Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

sum multiple columns in straight table

Hi, how do I sum multiple columns in straight table? I want to create column D:

ABCD
26512
43714
17816
59216

Thanks.

9 Replies

Re: sum multiple columns in straight table

RangeSum(A,B,C)

dirk_konings
Contributor III

Re: sum multiple columns in straight table

=++

Expression labels are reused

MVP
MVP

Re: sum multiple columns in straight table

Hi,

Try like this

=[Expression Name1] + [Expression Name2] + [Expression Name3]

OR

=Column(1) + Column(2) + Column(3)

OR

= RangeSum(A, B, C)

Hope this helps you.

Regards,

Jagan.

dgreenberg
Contributor III

Re: sum multiple columns in straight table

Jagan that's right but you run into trouble if you have an unknown number of columns.

For example I take a rolling 24 months but hide the column if there is no data so it's not Column(1)+...Column(24)

If you go to far and take a column that doesn't exist it shows a -

Example

showing Nov-2016 - Jan 2016 if I take Column(1) + Column(2) it's good but if I take Column(1)+Column(2) + column(16) it returns a -.

Same goes for if using column names which are expressions vDateSubmitted24 through vDateSubmitted1.

So what I need to do is figure out the column # in a straight table for this expression and use that to determine the max column # to sum.

I don't think you can get the column # from a straight table - I haven't been able to figure it out

Rangesum works/fails in same manner.

dgreenberg
Contributor III

Re: sum multiple columns in straight table

Ha answered my own question.

wrap the column with an alt and if it's a non existent column or the sum column it will still work.

alt(column(1),0) + alt(column(2),0) + alt(column(3),0) + alt(column(4),0) + alt(column(5),0) + alt(column(6),0) + alt(column(7),0) + alt(column(8),0) + alt(column(9),0)  +alt(column(10),0) + alt(column(11),0) + alt(column(12),0) + alt(column(13),0) + alt(column(14),0) + alt(column(15),0) + alt(column(16),0) + alt(column(17),0) + alt(column(18),0)

dgreenberg
Contributor III

Re: sum multiple columns in straight table

Ok but something odd is happening with the above.

My result is 2x what it should be because it's somehow including that column itself (the total column).

Yet if I wrap it in ( )/2 I get a different result that is not correct.

However if I add another expression as =TOTAL  //the name of the total column it works.

I can hide the TOTAL column on the presentation tab so I have a work around so far.

Just not sure how I am going to get the average.

When looking at my table below keep in mind this is just what our data set contains the months could be This month (Feb 2017) going back 24 months.  Notice how the first Total column is 2x what it should be.  That's the one that says =alt(column(1),0) + alt(column(2),0) ....  The second Total column says =Total  which matches the name of the previous column.  Very odd.

table.png

dgreenberg
Contributor III

Re: sum multiple columns in straight table

Figured out average.

Not elegant but here goes:

=Total/(Year(max([Date Submitted]))*12 + Month(max([Date Submitted]))

-(Year(min([Date Submitted]))*12 +month(min([Date Submitted])))

)+1)

Not applicable

Re: sum multiple columns in straight table

Hi

I need to calculate the final balance based on Min Year start and Max Year start . the  date format is in the MMM-YYYY form. I'm writing the below syntax. I know somewhere is wrong. can you please guide me in writing the new syntax.

= sum({<new_date={">=$(vYearStart))<=$(vYearMax)"},(sum(DBAL)-sum(WRITE_OFF)-sum(SECURED_RECOVERY)))



Thanks in advance.

Sowjanya

futureminds
New Contributor

Re: sum multiple columns in straight table

Hey there, 

You could do it in the script by using the following way:

Data: LOAD A,
B,
C,
Num#(A ,'##.###') + Num#(B ,'##.###') + Num#(C ,'##.###') as D FROM [YOUR PATH] (ooxml, embedded labels, table is sheet1);
This will sum the elements in each row of A, B, and C and will put it into D for you! Then you could use from "New object Sheet" --> "Table Box" to show your A, B, C, and D columns.

 

Community Browser