Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

What to do to insert a Total/SUM of a column in a variable?


Hi everybody.

I'd like to understand the way to work to apply to a variable a SUM/Total especially of a calculated column by IF command.

Thank you so much for your reply

Alberto

7 Replies
Gysbert_Wassenaar

Open the Variable Overview, click on Add, give the new variable a name and click on OK. Next select the new variable in the list of variables. Then enter the expression to calculate the sum in the Definition field. For example =sum(Amount) if you want to calculate the sum of the field Amount.


talk is cheap, supply exceeds demand
Roop
Specialist
Specialist

In your chart select the expression and then select the total box. This can either be No Total, Expression Total or Sum of the Rows - I think you want the "Sum of the Rows" checked.

Hope this helps

Not applicable
Author

Hi Rupert,

Consider that for normal Total Column I have no issue. The issue I get is

when I calculate a third column (for istance comparing the first two

columns) using IF command and writing row by row 1 or 0 depending of the

condition. Non problem in this case to get the SUM of the column, but I'd

like to know what to do to apply this "SUM" to a variable.

Thanks a lot indeed.

Alberto

Alberto Cuozzo | Senior Customer Development Information Technology

Coordinator |

' +39 06 54906249 | ' +39 335 8052066 | ? alberto_cuozzo@colpal.com | ü

VOIP 85366249

? Colgate Palmolive Commerciale Srl - Via Alexandre Gustave Eiffel, 15 ?

00148 ? Rome - Italy

P Think Before You Print This Email or Attachment

Roop
Specialist
Specialist

You can add the columns together very simply.

So if you have calculated expression A and calculated expression B, you can create a rule that says A + B in calculated expression Total and then this can in turn have the sum rows checked for the total.

Not applicable
Author

Could you please explain me better what you intend for "create a rule that says A + B...."

Thank you

Roop
Specialist
Specialist

Create a calculated expression as A + B if you have already created your other calculated expressions.

Not applicable
Author

Thank you very much Rupert.

Your suggestion is OK if I want to get a third column to be the result of column A + B (also them calculated using IF command). Fortunately to fix my problem I found, surfing, something that seems working very good. In this way I have the opportuniy to store the SUM/TOTAL of those calculated columns to some variables. Please see and test the code here below.

Sub Get_XTOTAL

Application.WaitForIdle

set cell=ActiveDocument.GetSheetObject("CH45").GetCell(1,7)

ActiveDocument.Variables("vXTOTAL").SetContent cell.text, True

set cell=nothing

End Sub