Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Highlighted
newqlik2017
Contributor

How to sum values based on selections at different levels

Hello,

Below is my raw table and final output table with bands (range). However, my expressions (Total Account & Amount) aren't working.

Attached is a sample qvw.

Based on what selection (State, County, City or Zip) is made, the Amount should fall in the corresponding range.
Selection can be one state or multiple states and so forth. I tried using set analysis but didn't quite get the correct result.

Any ideas how this can be handled? Thanks!

LP Test1.JPG

1 Solution

Accepted Solutions

Re: How to sum values based on selections at different levels

Try this

Sum({<ZIP = {"=If(GetSelectedCount(ZIP) > 0, Len(Trim(ZIP)) > 0, Len(Trim(ZIP)) = 0)"},

  COUNTY = {"=If(GetSelectedCount(COUNTY) > 0 or GetSelectedCount(CITY) > 0 or GetSelectedCount(ZIP) > 0, Len(Trim(COUNTY)) > 0, Len(Trim(COUNTY)) = 0)"},

  CITY = {"=If(GetSelectedCount(CITY) > 0 or GetSelectedCount(ZIP) > 0, Len(Trim(CITY)) > 0, Len(Trim(CITY)) = 0)"}>}AMOUNT) + Sum({1} 0)

View solution in original post

6 Replies

Re: How to sum values based on selections at different levels

What is the expected output for the data provided?

newqlik2017
Contributor

Re: How to sum values based on selections at different levels

Hi Sunny, please find the attached excel file for the expected output.

Re: How to sum values based on selections at different levels

This expression almost works... see if you have missed some data rows and it works for your original app

Sum({<ZIP = {"=If(GetSelectedCount(ZIP) > 0, Len(Trim(ZIP)) > 0, Len(Trim(ZIP)) = 0)"}, COUNTY = {"=If(GetSelectedCount(COUNTY) > 0, Len(Trim(COUNTY)) > 0, Len(Trim(COUNTY)) = 0)"}, CITY = {"=If(GetSelectedCount(CITY) > 0, Len(Trim(CITY)) > 0, Len(Trim(CITY)) = 0)"}>}AMOUNT) + Sum({1} 0)


Count(DISTINCT {<ZIP = {"=If(GetSelectedCount(ZIP) > 0, Len(Trim(ZIP)) > 0, Len(Trim(ZIP)) = 0)"}, COUNTY = {"=If(GetSelectedCount(COUNTY) > 0, Len(Trim(COUNTY)) > 0, Len(Trim(COUNTY)) = 0)"}, CITY = {"=If(GetSelectedCount(CITY) > 0, Len(Trim(CITY)) > 0, Len(Trim(CITY)) = 0)"}>}ACCOUNT_NUM) + Sum({1} 0)

newqlik2017
Contributor

Re: How to sum values based on selections at different levels

Test_S1.JPG

Test_S2.JPG

Hi Sunny, yes you are right - I think I missed some data rows. However, during my testing I found this expression didn't work in the above examples. Screen shots attached.

1) First image, when NJ state and Lehigh2 city is selected, the final table displays 0. Correct total account is 1 and amount is 21617
2) Second image, when NJ state and Lehigh1+Lehigh2 city is selected, the final table still displays 0. Correct total account is 2 and amount is 21617 + 1125 = 22742

Any ideas, please?

newqlik2017
Contributor

Re: How to sum values based on selections at different levels

I meant state = PA (not NJ) in my prior response. Correction.

Re: How to sum values based on selections at different levels

Try this

Sum({<ZIP = {"=If(GetSelectedCount(ZIP) > 0, Len(Trim(ZIP)) > 0, Len(Trim(ZIP)) = 0)"},

  COUNTY = {"=If(GetSelectedCount(COUNTY) > 0 or GetSelectedCount(CITY) > 0 or GetSelectedCount(ZIP) > 0, Len(Trim(COUNTY)) > 0, Len(Trim(COUNTY)) = 0)"},

  CITY = {"=If(GetSelectedCount(CITY) > 0 or GetSelectedCount(ZIP) > 0, Len(Trim(CITY)) > 0, Len(Trim(CITY)) = 0)"}>}AMOUNT) + Sum({1} 0)

View solution in original post