Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

set analysis for formula like sum(a-b)

Hi,

I'm trying to create an expression with SET.

It is easy to do this...

sum ( {$<....>} a) - sum ( {$<....>}  b)

BUT... how do i do it when i want it to be SUM (a - b), applying the same set analyis for both a and b?

Thanks,

10 Replies
whiteline
Master II
Master II

sum ( {$<....>} a-b)

or

sum ( {$<....>} RangeSum(a, -b))

Not applicable
Author

i can't do that. because the SET criteria for a and b are different....

whiteline
Master II
Master II

I thought you said its the same.

Ok, use Only({$...} a) - Only({$...} b)

Not applicable
Author

yes.. my bad.. typed too quick..

so, perfect, it works...

now, as i'm doing this in pivot table...

the subtotal wont work anymore.. it disappear...

any tips?

Not applicable
Author

and also.. how does ONLY() works?

i tried to look up in the document, it's not very helpful...

the reason why the total is not working.. because...

instead of doin sum (only(a) - only(b)),

i remove the sum, otherwise the figures wont show...

thats why i asked how does only() works...

it's weird...

whiteline
Master II
Master II

All answers depends on your data structure. You can reduce your file and post it or try to give more info.

About Only():

Originally this function checks if your field values are all the same and return this value or null.

But when you know that there is only one value (for your case it was my suggesstion 'cause  you use and without aggregation) you can use it to modify the set (of dimension values) of such fields.

upd:

Oh, I've just realised.

I think when you do sum (only(a) - only(b)),  you forget about sum() sets. You have to wrtite a set expression so that the totals can be calculated.

Not applicable
Author

Thanks.. after looking at the pivot.. it make sense now.

the only() works when i'm at the lowest value of my pivot, which means i have to expand all the rows.

once i collapse the roll, there's no data to it. that's why there's no value to the total line.

Is there a workaround? so that when it's collapsed, the overall total will work?

Thanks again.

whiteline
Master II
Master II

Actually two workarounds:

1) use aggregation function if possible (like sum and so on)

2) use dimensionality() function to determine the level of expression being calculated.

    If(dimensionality()=1,  expression for subtotals, expression for other cells).

Not applicable
Author

Hi,

I still can't make my expression work.

I have made a similator in attached.

Bascially the percentage by row for zone and month and the selected product is good.

Just that the total percentage is not wanted.

I made a small table below, in the last column, if we can get the expression working, it will be great.

somebody ?

Thanks,