Fix subtotal calculations.
[pspp] / src / language / stats / ctables.c
index 6b6b46a035239564d3a54c43d353a9bcf06c84f1..b57f33f5d7ef4a35203433e231d49057820fffb9 100644 (file)
@@ -2567,12 +2567,16 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
     pivot_table_set_caption (
       pt, pivot_value_new_user_text (t->corner, SIZE_MAX));
 
-  bool summary_dimension = t->summary_axis != t->slabels_axis;
+  bool summary_dimension = (t->summary_axis != t->slabels_axis
+                            || (!t->slabels_visible
+                                && t->summary_specs.n > 1));
   if (summary_dimension)
     {
       struct pivot_dimension *d = pivot_dimension_create (
-        pt, t->slabels_axis, N_("Summaries"));
+        pt, t->slabels_axis, N_("Statistics"));
       const struct ctables_summary_spec_set *specs = &t->summary_specs;
+      if (!t->slabels_visible)
+        d->hide_all_labels = true;
       for (size_t i = 0; i < specs->n; i++)
         pivot_category_create_leaf (
           d->root, pivot_value_new_text (specs->specs[i].label));
@@ -2700,7 +2704,7 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
                     }
                 }
 
-              if (a == t->slabels_axis && a == t->summary_axis)
+              if (!summary_dimension && a == t->slabels_axis)
                 {
                   levels[n_levels++] = (struct ctables_level) {
                     .type = CTL_SUMMARY,
@@ -2718,17 +2722,16 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
                   if (level->type == CTL_CATEGORY)
                     {
                       size_t var_idx = level->var_idx;
-                      if (prev->axes[a].cvs[var_idx].category
-                          != cell->axes[a].cvs[var_idx].category)
-                        {
-                          break;
-                        }
-                      else if (!value_equal (&prev->axes[a].cvs[var_idx].value,
-                                           &cell->axes[a].cvs[var_idx].value,
-                                             var_get_type (nest->vars[var_idx])))
-                        {
-                          break;
-                        }
+                      const struct ctables_category *c = cell->axes[a].cvs[var_idx].category;
+                      if (prev->axes[a].cvs[var_idx].category != c)
+                        break;
+                      else if (c->type != CCT_SUBTOTAL
+                               && c->type != CCT_HSUBTOTAL
+                               && c->type != CCT_TOTAL
+                               && !value_equal (&prev->axes[a].cvs[var_idx].value,
+                                                &cell->axes[a].cvs[var_idx].value,
+                                                var_get_type (nest->vars[var_idx])))
+                        break;
                     }
                 }
             }