Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
felipe_oliveira
Contributor III
Contributor III

sum if ever exists in list box (on selected year)

Hi Qlik masters

I need to come out with a expression that sum up if a field ever existed (active) in a list box during the selected year.

Please find further details below:

DWH Table

Key%AccountVendor_loc_CodeDWH.ProgramDWH.DateYearMonthBalance$
10001111A01-Jan-20172017Jan100
10002111E01-Jan-20172017Jan50
20003222B01-Jan-20172017Jan10
3004333F01-Jan-20172017Jan30
40001111A01-Feb-20172017Feb120
40002111E01-Feb-20172017Feb90
50004333F01-Feb-20172017Feb30
60002222B01-Feb-20172017Feb110
70001111A01-Mar-20172017Mar160
70002111E01-Mar-20172017Mar90
80004333F01-Mar-20172017Mar85

%Key = AutoNumber(vendor_loc_Code & Date(DWH.Date, 'MMYY'))


Dealer Table

Key%ApplicationDealer NameVendor_CodeDealer.ProgramSubmitted.DateDWH.YearDWH.MonthSubmitted Amount$
211111YY222B01-Jan-20172017Jan100
122222XX111A01-Jan-20172017Jan20
133333XX111E01-Jan-20172017Jan40
644444WW222B01-Feb-20172017Feb40
455555XX111A01-Feb-20172017Feb40
58888XX333A01-Feb-20172017Feb55
766666XX111A01-Mar-20172017Mar30
777777XX111E01-Mar-20172017Mar15

%Key = AutoNumber(Vendor_Code & Date(Submitted.Date,'MMYY'))

The link between the 2 tables is %Key2


I have the following list tables

Year (from Dealer Table)

Month (from Dealer Table)

Dealer Name (from Dealer Table)

Dealer Program (from Dealer Table)

I select Year = 2017, Month = Feb and Dealer Name = XX

The current expression to calculate the Sum Balance$ is:

Sum({1}{<Year={$(=($(vFieldYear)))}, Month={$(=($(vFieldMonthName)))},DWH.Program = p({1}Dealer.Program)>} NET_BAL)

Straight table actual:

Dealer.NameDWH.ProgramCount AccountSum Balance$
XXA1120
XXE190
XXF130

Straight table expected:

Dealer.NameDWH.ProgramCount AccountSum Balance$
XXA1120
XXE190

Expected logic:

1) I would like to disclose the sum balance of the maximum date selected (Year and month). It cannot sum over different months as the balance field is a cumulative field.

2) I would like to show in the DWH.Program column, only programs available in the Dealer table (regardless of the period of the year). For example, in Feb 2017, Program E was not submitted but I would like to have it included as it has balance in the same month on table DWH. Program F should not be disclosed as it does not on Dealer table (even though they share the same Dealer Name).

Thanks

Message was edited by: Felipe Oliveira

1 Solution

Accepted Solutions
sunny_talwar

May be this

Sum({1<Year={$(=($(vFieldYear)))}, Month={$(=($(vFieldMonthName)))}, DWH.Program= p({1<Dealer.Name = p(Dealer.Name)>} Dealer.Program)>} NET_BAL)

View solution in original post

3 Replies
sunny_talwar

Why would you not see Key% 6 here... it is also in Feb 2017 and DWH.Program = B....

sunny_talwar

May be this

Sum({1<Year={$(=($(vFieldYear)))}, Month={$(=($(vFieldMonthName)))}, DWH.Program= p({1<Dealer.Name = p(Dealer.Name)>} Dealer.Program)>} NET_BAL)

felipe_oliveira
Contributor III
Contributor III
Author

Thanks Sunny!

It worked! I just needed to make a small change as below. I didn't know we could use p() inside another p().

sum({1<DWH.Program=p({1<Dealer.Name=p(Dealer.Name)>}Dealer_Program),Dealer.Name=p(Dealer.Name),Year={$(=($(vFieldYear)))}, Month={$(=($(vFieldMonthName)))}>} NET_BAL)