I have:
- latest released (not dev) versions on Drupal 6 as of 3/28/09
- cck field with an integer value on node type A
- a nid argument to limit the nodes to related nodes of type A
- view with style Views Calc Table that properly shows a table with the nodes,
but
- on the view edit page, adding an argument and clicking preview does not show the sum line
- visiting a node with the view shows the sum line, but no sums.

I have fiddled around trying every different combination. Further, I have looked through all the issues, but am stuck.

Any help is appreciated.

Comments

KarenS’s picture

You are using values from a relationship? That is not currently working. It's going to be tricky because I have to find the right table name to swap into the query. I'm spending some time on this today. Not sure if I'll find a fix right away.

KarenS’s picture

Title: Blank Result » Blank Result when using relationship

Renaming for clarity.

johnthomas00’s picture

Karen,

Does this same issue also apply to calculation fields? I am trying to calculate a price per X on content type A. The price is a CCK field on content type A, but the number of X's is on content type B, which is a node reference in A.

I wish I knew enough to help these "referenced" problems along. If there is something I can do to help, please let me know.

johnthomas00’s picture

Disregard #3
In case others end up here from a search, my solution was:
http://drupal.org/project/computed_field
That module allows field calculations across content types.

hlykos’s picture

subsribing

jmary’s picture

Any progress regarding that in the dev version ?

aleagi’s picture

+1 here!

It would be nice to have relationship calc working... Is there any chance to get this?

AaronBauman’s picture

Version: 6.x-1.0 » 6.x-1.x-dev

bump

gthing’s picture

Subscribing.

gthing’s picture

@johnthomas00 Could you explain your solution? Were you able to calculate fields in a view using that module?

gthing’s picture

Okay I have a workaround.

Using the views_customfield module, you can add a customfield to your view that can contain PHP. I first put the following code into the customfield and viewed it to find the string name I needed:
<?php print_r($data);?>

One you have the string, just replace the above code with this in the customfield:
<?php echo $data->string_name; ?>

I should note also that this didn't work unless I already had the relationship field pulled in above the customfield in the fields section of my view. Since I don't want it to display twice I just set the first instance to not display. I hope that makes sense. Here is a screenshot of the relevant section:

https://img.skitch.com/20110406-rp4peran187cnacqwsgg2b2799.jpg

Also, you need to be using views_customfield dev and install the patch from here: http://drupal.org/node/576264

I imagine a similar approach could be used to build in support for relationship fields out of the box. I think if you need more flexibility the views_customfield module could also entirely replace the functionality of views_calc.

Mokey’s picture

Can #11 be copied to the front page of this module? I find myself referring back to it regularly, both for the fix to the relationship issue, but also to remember how to use print_r($data) to find the field names (I am not a php programmer, so this is not obvious to me).

cgv’s picture

Hi: I change line 207 (query_total) in views_calc_table.inc
from: $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table .'.'. $field->field;

to: $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table_alias .'.'. $field->field;

then sum works fine. I change in a view with two relationship nested and works fine, but it needs more tests to check if this is the right solution.

I didn't test for query_sub_total yet.

Regards

raghugs’s picture

Status: Active » Reviewed & tested by the community

Thank you so much for your findings.
I did the changes you suggested and now the results are coming perfectly in both total and sub-total.

Sinan Erdem’s picture

Can we somehow apply this to D7 version?

fb-multimedia’s picture

+1 for a Drupal 7 solution, thanks...

senzaesclusiva’s picture

#13
View Calc 6.1 dev
Applied #13 patch but Doesn't works on D 6.28 and Views 6.x-3.0

senzaesclusiva’s picture

#13
Now applied patch to View Calc 6.x-1.3 on D 6.28 and Views 6.x-3.0.
Works fine now, thanks

doublejosh’s picture

Still broken for field handlers.

brylie’s picture

Title: Blank Result when using relationship » Support relationships with calculated fields
Version: 6.x-1.x-dev » 7.x-1.0
Category: bug » feature

I set this to be a feature request, as it is not really a bug per se. It would be a valuable feature.

As a project manager
I would like to calculate time spent on activities for projects
given that there is a project content type
and that there is an activity content type
and the activity content type has a decimal field called 'hours'
and that the activity content type has a relation field called 'related project'

Scenario: Creating a view with total hours
A new view is created showing a table activities related to a project
The activities table has a column for the decimal field 'hours'
The views calc style is able to perform various calculations on the hours results for the view query

Note: the view query should contain sufficient details regarding the database fields involved in the relationship
Here is an example page:
http://growhost.org/project/akgillespie

skorzh’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review

Test please my patch, perhaps it will fix the problem.
https://drupal.org/comment/8342915#comment-8342915

KarenS’s picture

Latest dev version should be working. The zip file does not seem to be getting updated but the git checkout should work right.

KarenS’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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