Tags:
create new tag
view all tags

SID-01342: How to... sum formfield values

Status: Answered Answered TWiki version: 4.0.1 Perl version: Not sure
Category: SpreadSheetPlugin Server OS: Windows Last update: 14 years ago

Hi,

Looking for help to see how I can sum the values for a particular formfield across a number of topics containing that formfield. If possible I would like to first filter the topics to those that have a particular value for a different formfield. In terms of display I only want to output the summed value. Is this possible?

Thanks Colin

-- ColinStapleton - 2011-11-30

Discussion and Answer

Use a CALC in a SEARCH format, something like this (untested) :

%CALC{$SET(total, 0)}%
%SEARCH{
 "whatever..."
 format="$percntCALC{$IF($formfield(FieldA) > 10, $SETM(total, +$formfield(FieldB)))}$percnt"
}%
Total: %CALC{$GET(total)}%

Details in SpreadSheetPlugin (see example), FormattedSearch, VarSEARCH.

-- PeterThoeny - 2011-11-30

This is a great help thanks. However, try as I might I can't get the formfield evaluation to work. Here's my script:

%SEARCH{ "[F]y" scope="text" type="regex" nosearch="on" nototal="on" format="$percntCALC{$IF($formfield(Fy) = \"2011\", $IF(defined $formfield(Amount), $SETM(total, +$formfield(Amount))))}$percnt"}%

I think I am not escaping properly but I can't pinpoint the error. Any help with this would be greatly appreciated.

-- ColinStapleton - 2011-12-01

The IF formula is wrong. Read SpreadSheetPlugin. Compare an integer using ==, or compare a string using $EXACT().

-- PeterThoeny - 2011-12-01

Ok makes sense. Is there a way to include formfields in an $EXACT() comparison? I tried this:

%CALC{"$EXACT($formfield(Fy), 2012)"}%

But always returns 0.

Using %FORMFIELD% I am able to verify that Fy value is 2012.

Thanks Colin

-- ColinStapleton - 2011-12-01

Should work. Is there maybe some whitespace around 2012?

-- PeterThoeny - 2011-12-01

Your suggestion about whitespace gave me an idea. I tried

%CALC{"$LENGTH($formfield(Fy))"}%

And returns 14 which is the number of characters in the string "$formfield(Fy)". Hence I think what is happening is that the $EXACT() and also the $LENGTH() functions are not resolving the formfield values as you would expect. Could this be a fault in version of twiki I am using (4.05 personal for windows). Perhaps it is time I stepped up to the proper webserver version?!

-- ColinStapleton - 2011-12-02

$formfield(Fy) only gets resolved in a SEARCH format="".

-- PeterThoeny - 2011-12-02

Eureka. Thanks a million smile

-- ColinStapleton - 2011-12-03

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title How to... sum formfield values
SupportCategory SpreadSheetPlugin
TWiki version 4.0.1
Server OS Windows
Web server Tiny
Perl version Not sure
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2011-12-03 - ColinStapleton
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.