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.

#12 error.txt2.69 KBkeithmorr
#10 views_calc-340334.patch958 bytesinfojunkie
#6 view.txt11.49 KBAren Cambre
Members fund testing for the Drupal project. Drupal Association Learn more


Daniel A. Beilinson’s picture

Can you fix it?

Aren Cambre’s picture

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.

KarenS’s picture

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.

Aren Cambre’s picture

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?

KarenS’s picture

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.

Aren Cambre’s picture

Status: Postponed (maintainer needs more info) » Active
11.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.

Aren Cambre’s picture

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.

Daniel A. Beilinson’s picture

@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...

infojunkie’s picture


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.

infojunkie’s picture

Status: Active » Needs review
958 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.

bluehead’s picture

Patch solves the problem

Thanks kratib

keithmorr’s picture

2.69 KB

Patch causes massive error:

Error list attached

Aren Cambre’s picture

Status: Needs review » Needs work
bsztreha’s picture

subscribe, same problem (patch dont work)

amyadams’s picture

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?

amyadams’s picture

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?

Francewhoa’s picture

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

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

Francewhoa’s picture

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

JCB’s picture

Looks like this post although looking like different problem is also caused by the same problem located here:

Seems like there was a core problem with Node Module.

I applied the patch at comment #127

Here is link to patch:

Solved my problem

eclauset’s picture

"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.

solution33r’s picture

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

calbasi’s picture

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 ;-)

KarenS’s picture

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

The D6 version is no longer supported.