If a 'Taxonomy: Terms for' field is added to a Views Calc view that is a free tagging multiple term vocabulary, the Count is incorrect.

For example, if a submit a node with 2 terms from the same vocabulary called 'apple' and 'banana', the node is counted as 2 instead of 1. With only 'apple' assigned, the count is correctly 1.

Further more, if a node type has more than 1 vocabulary and has terms from each assigned, the count goes haywire.

For example, I've got 6 nodes that are counted as 15. 3 of these nodes have 1 term each from 2 vocabularies while the other 3 are not tagged at all.

I realize I haven't provided much support, but has anyone else been successful when adding 'Taxonomy: Terms for' fields? My current workaround is using the 'Taxonomy Field' fields, but this only works for me because I am using Content Taxonomy. I also did this on a new local install without Content Taxonomy (to make sure no conflicts were happening) and the issue still occurs.

Files: 
CommentFileSizeAuthor
#12 error.txt2.69 KBkeithmorr
#10 views_calc-340334.patch958 bytesinfojunkie
#6 view.txt11.49 KBAren Cambre

Comments

Can you fix it?

Title:Count is incorrect when multiple taxonomy terms present>=2 taxonomies screws up module's math
Version:5.x-1.x-dev» 6.x-1.3
Priority:Normal» Critical

This is still the case in 6.x-1.3. The module multiplies each node's calculation by the number of taxonomies used in the node. These are not free-tagging taxonomies.

I have a view with 75 nodes, all the same type. I used Views Calc to count one field (the title field--to get a count of nodes) and sum an integer field.

All nodes have one term selected from 2 taxonomies. The total count and sum are both doubled what they should be. I confirmed this by exporting the data to Excel.

I added a third taxonomy and added a 76th node. Now I get 153 in the count: 75 * 2 for the first 75 nodes and 1 * 3 for the last node that has 1 term from 3 taxonomies selected, and the sum's math works out the same.

#492364: All mathematical operations are doubled marked as duplicate of this issue.

Status:Active» Postponed (maintainer needs more info)

This module just adds whatever the view returns. If a field shows up in the table more than once, it will get added more than once.

This is a well known issue when joining taxonomy terms into Views, duplicate rows are created. I don't know of any way Views Calc can do something Views cannot do. Views Calc is just adding groupby totals to whatever rows the view creates.

If you think you see a way to prevent this, you're welcome to provide a patch.

Status:Postponed (maintainer needs more info)» Active

Are you saying that Views internally creates one row for each of a node's used taxonomies, even if the final rendered result only shows the row once?

Is it even meaningful to operate on each node more than once? If not, should Views Calc add the current node's NID to an array and check that array on each row operation to eliminate the chance of a node being operated on multiple times?

Status:Active» Postponed (maintainer needs more info)

I'm saying that Views calc is not creating the table rows, Views is. If the same node shows up more than once in the table it will get added multiple times. If that's what's happening, it's the way Views works. If the view shows each node only once in the table but the total adds them in more than once, that would be a Views Calc issue. If you have a multiple-page view, you need to be sure the node is not duplicated on some other page that you can't see. The best way to be sure would be to sort the view by nid so all instances of the same nid show up together.

Status:Postponed (maintainer needs more info)» Active
StatusFileSize
new11.49 KB

By that, it's a problem with Views Calc. The view shows each node only once, and it's a one-page view. The calc appears to be done once per taxonomy vocabulary used in each node.

E.g., suppose I have nodes with integer fields A and B. Further suppose the nodes each have one term selected from two taxonomy vocabularies. Here's what I get on a Views Calc with COUNT on field A and SUM on field B:

Title  A  B
X      1  2
Y      2  4
Z      4  6
Count  6
Sum       24

An export of the actual view with which I am having problems is attached.

I just set up the simplest live test of that quickie example I gave in #6. The numbers got doubled only if I added taxonomy terms to the view. If the view has no taxonomy terms, the calculations are correct.

@KarenS, it's serious problem. Could you please help us to solve this issue? Maybe you know how we can make autocopy of terms to textfield without loading to views? We can expose text instead of terms...

subscribe

When I examined the Calc query using the Devel module's query log, it appeared that there's an extra clause in the SQL that's not present in the original Views query:

LEFT JOIN term_node term_node ON node.vid = term_node.vid

If I execute the Calc query as is in a MySQL editor, it gives the wrong result. If I remove the term_node clause, it gives the right result.

I'll be investigating why this clause gets added to the Calc query.

Status:Active» Needs review
StatusFileSize
new958 bytes

Attached is a patch that seems to resolve the problem. What it does is to let the original Views query builder decide which tables should be added, instead of doing that work again in Views Calc. Technically, that means removing the calls to views_query::add_table() in views_calc_table::query_total() and views_calc_table::query_sub_total(). The rationale is that call is unneeded anyway since Views Calc only iterates on existing fields in the original view.

Confirm
Patch solves the problem

Thanks kratib

StatusFileSize
new2.69 KB

Patch causes massive error:

Error list attached

Status:Needs review» Needs work

subscribe, same problem (patch dont work)

Question, I'm having similar issues with CCK fields rather than taxonomy terms. My view displays results of CCK field check boxes in one column. If more than one item is checked in a given node (and therefore several items are displayed in that column), then views calc counts that node once for each term displayed.

Is this the same issue, or should it be its own issue?

FYI, the patch worked beautifully on a table using multiple Taxonomies. The math is now perfect and I'm thrilled. Thanks infojunkie.

However, the patch generated an error on a table that uses multiple CCK fields (this is the table I mentioned in #15). I get the same basic error as keithMorr. That's an error discussed in another issue with this module. According to that other issue thread, the error occurs when you designate a table to be a views_calc table but then don't do any calculations. The solution was if you aren't doing calculations, just make it a regular views table.

In my case, I'm doing calculations but still get that error. Pre-patch, I didn't get the error but views_calc was counting rows with multiple terms once for each term.

Any thoughts?

Confirming this issue. views_calc multiplies each node's calculation by the number of taxonomy level used in the node.

Steps to reproduce this issue
1. Add a taxonomy to your node. Saved taxonomy term must be 2 level deep.
2. Setup a standard Views Calc table with a SUM. Using above node.
3. Log-in Drupal with a user that does not have admin access to Views Calc. But viewing access to content. Display the Views Calc table. views_calc will multiply the SUM by two. Expected result is the SUM should not be multiply by the number of taxonomy level.

Note: If you redo all above steps but use a three level taxonomy, views_calc multiplies the SUM by three

Using
* Drupal 6.22
* Views Calc 6.x-1.3
* Views 6.x-2.12

We found a temporary workaround

1. Go to /admin/user/permissions
2. Give the user access to "administer nodes"
3. Test. The SUM result is correct.

This is not ideal because "administer nodes" gives to much permissions to some user types

Thanks to solemanus http://drupal.org/node/1163078

Looks like this post although looking like different problem is also caused by the same problem located here:
http://drupal.org/node/1163078

Seems like there was a core problem with Node Module.

I applied the patch at comment #127
(http://drupal.org/node/681760#comment-4371188)

Here is link to patch:
http://drupal.org/files/issues/681760_node_access-127-D6.patch

Solved my problem

"If the view shows each node only once in the table but the total adds them in more than once, that would be a Views Calc issue"

This is what I'm seeing. I have a table with 3 distinct rows, each row contains 3 taxonomy term references, and the sum is double what it should be. Applying the patch linked above does not seem to change anything.

Just curious - has anyone patched this for Drupal 7? http://drupal.org/node/340334#comment-1908280

More issues here :-(
I gent my "SUM" and "COUNT" multiplied for 6!
I can "reduce" it to x3 deleting all taxonomies fields, sort critery and filters... :-)
And how I get the right numbers? Deleting the non-calc columns to 1 (from the original 3... I've deleted telephone and email colums and then only node title remains, besides numeric columns).
If you need further / more detailed info, I could send you ;-)

Issue summary:View changes
Status:Needs work» Closed (won't fix)

The D6 version is no longer supported.