Hey up,
I have recently been trying to figure out crosstabs, found this, did the job pefectly in my example. When I took it into the real data we wanted to use I noticed that it wasn't returning the results I wanted.

I return up to 6 grouped values for my columns which are numeric values, and then return a NID for each of them, the rows show up fine, but it will only return one value (with the correct data), which is the highest value, so if I request a column for 1, 15 and 23, I will only get results for 23, and the other columns do not appear. When I made the 6 grouped values text and not integers, the rest of the columns showed up correctly and all is working fine.

When I swap the data round to use NID as columns, again, it will only show the column for the highest numbered NID.

If you need any more information just give me a shout.
Cheers
Dan

Comments

porridj’s picture

StatusFileSize
new3.06 KB

here is an example view that is broken

eft’s picture

Can you recreate the problem on a fresh install with dummy data or some other means? I don't have enough experience to figure it out from your exported view.

porridj’s picture

Hey, that view has been created for a fresh install, but you'll need the views_crosstab module installed and also I used the devel module to generate content. Once you have imported the view, you will see that it doesnt look odd (because i must have forgotten to turn on aggregation before I exported!) so if you turn on the aggregation and group content type you should see, a list of nodes accross the top, with a 1 or a 0 in the content type line, then the count at the end. Instead what you actually see is just the highest number node id accross the top and all the others are missing. If you then change the crosstab settings so that the columns are the content types and the rows are the node ids, you will see that it works properly.

The problem only seems to happen when trying to use numbers as the columns.

Let me know if you need more explanation.

Cheers
Dan

danchadwick’s picture

Title: When using row results that have numbers » When using column results that have numbers
Component: Miscellaneous » Code
Priority: Normal » Major
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new849 bytes

The fix is trivial. The regular expression used to create a column alias uses only letters A-Za-z. If the values in the column field are numeric, then the expression aliases are not unique. Also, the actual alias returned by add_field is ignored. The second change fixes the problem for all column field values, but I fixed it explicitly for numeric fields because the column value expressions have meaningful names.

Marking this as major because it prevents functioning for a major set of use cases. Renaming title to show correct failure mode (column field, rather than row field containing numeric values).

danchadwick’s picture

Looking at the code a bit more, the optional total column is susceptible to the same bug. Also, if the [2126443] is committed, then the awkward double-if can be cleaned up too:

      // If selected by user, add an additional column for aggregating
      // on entire row.
      if (isset($options['include_crosstab_operation_on_row'])) {
        if ($options['include_crosstab_operation_on_row'] == TRUE) {
          $alias = $crosstab_columns['alias'] . '_total';
          $this->view->query->add_field(
              NULL,
              $crosstab_data['table'] . '.' . $crosstab_data['field'],
              $alias,
              array(
                'function' => strtolower($options['crosstab_operation_on_row']),
              )
          );
          $this->view->query->fields[$alias]['aggregate'] = TRUE;
          $this->view->field[$alias] = clone($this->view->field[$crosstab_data['field']]);
          $this->view->field[$alias]->field_alias = $alias;
          $this->view->field[$alias]->options['id'] = $alias;
          $this->view->field[$alias]->options['label'] = t('Total');
          $this->view->style_plugin->options['info'][$alias] = $this->view->style_options['info'][$crosstab_data['field']];
          $this->view->style_plugin->options['columns'][$alias] = $alias;
        }
      }

Because this issue intersects with the can't-export issue, it might be best to tend to this after the export issue is committed.

danchadwick’s picture

#4 committed to 7.x-1.x. #5 still open.

danchadwick’s picture

Status: Needs review » Fixed
StatusFileSize
new3.55 KB

Commited to 7.x-1.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.