Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

sum based on dimension value in table

hello there,

in qlik sense i want sum of amount based on the dimension value.

here's my query -

if(Reference=1 or Reference=2  or Reference=3,
sum(Amount) / sum({<Reference={'1','2','3'}>}Amount),0)

in this i want sum of amount in table where reference value is either 1,2 or 3 and that sum to be divided by the amount where reference number is 1,2 and 3

required output:

ref       sum(amount)    above expression

1               10                    10/60 = 0.16

2               20                    20/60 = 0.33

3               30                    30/60 = 0.5

rather the output is showing 1's and zero in that field

please help with this..

12 Replies
Anonymous
Not applicable
Author

i did exactly what he suggested but its not showing those figures and even i tried your expression too

this is what i wrote in that measure:

if(Reference=1 OR Reference=2 OR Reference=3,

   sum(Amount) / sum({<Reference={'1','2','3'}>} TOTAL Amount),

if(Reference=5 OR Reference=6 OR Reference=7,

    sum(Amount) / sum({<Reference={'5','6','7'}>} TOTAL Amount)

  )

)

sunny_talwar

Not that it should make any difference, but I recommend making your expression a little simpler...

Sum(Amount)/

If(Match(Reference, 1, 2, 3), Sum({<Reference = {'1', '2', '3'}>} TOTAL Amount),

If(Match(Reference, 4, 5, 6), Sum({<Reference = {'4', '5', '6'}>} TOTAL Amount)))

If this still doesn't work, would you be able to share a qvf sample to show what you are doing?

Anil_Babu_Samineni

Your question make sense now? Will you provide sample

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful