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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Adding values once conditions have been met from 2 different fields

I have the following data and need some help.

DATE_DATA (dates)

DAYS (numbers from 1 to 31. Some months the max is 30)

ACCOUNT (#)

BALANCE ($)

I need to be able to create an expression either in the script or in the front end that will let me add all the Balances for the accounts for the DATE_DATA where the DAYS in the max. If you see the table below, I would need to be able to add the Balances for the accounts for the highlighted days.

In Jan 2014 - it would be for day 01/17/14 since the DAYS is the max for that month (31)

In Feb 2014 - it would be for 02/19/14 since the DAYS is the max for that month (31)

In Mar 2014 - it would be for 03/19/14 since the DAYS is the max for that month (28)

I have attached data to use as an example. It is important to note that within each DATE_DATA, there are many different DAYS. First I need to calculate the Max Day for the month to be able to identify which date it is that I need to use to add all the balances for my accounts.

DATE_DATAMax (DAYS)
31
2014010214
2014010317
2014010618
2014010719
2014010820
2014010921
2014011024
2014011325
2014011426
2014011527
2014011628
2014011731
201401212
201401223
201401234
201401247
201401278
201401289
2014012910
2014013011
2014013114
2014020315
2014020416
2014020517
2014020618
2014020721
2014021022
2014021123
2014021224
2014021325
2014021429
2014021830
2014021931
201402201
201402214
201402245
201402256
201402267
201402278
2014022811
2014030312
2014030413
2014030514
2014030615
2014030718
2014031019
2014031120
2014031221
2014031322
2014031425
2014031726
2014031827
2014031928
201403201
201403214
201403245
201403256
201403267
201403278
2014032811
2014033112
3 Replies
MK_QSL
MVP
MVP

use below script

LOAD Date#(DATE_DATA,'YYYYMMDD') as DATE_DATA,

  Date(MonthStart(Date#(DATE_DATA,'YYYYMMDD')),'YYYYMM') as MonthYear,

     ACCOUNT,

     DAYS,

     BALANCE

FROM

Example.xlsx

(ooxml, embedded labels, table is Sheet1);

Now

create a straight table

Dimension

MonthYear

Expression

SUM(Aggr(IF(DAYS = Max(TOTAL <MonthYear> DAYS),SUM(BALANCE)),MonthYear,DAYS))

Not applicable
Author

Good afternoon Manish,

Thank you for the response. I was able to get the formula to work, but it isn't giving me the correct sum.

Using the expression you provided me with, I am getting the following discrepancies:

Jan - Date 01/17/2014

     -Correct Sum: $24,140

     -Sum from expression: $23,516

Feb - Date 02/19/2014

     -Correct Sum: $26,624

     -Sum from expression: $25,490

Mar- Date 03/19/14

     -Correct Sum: $25,529

     -Sum from expression: $24,821

I also then need to be able to have that data filter to my account numbers. Meaning that once I select MonthYear "Jan 2014" I need to be able to have the correct account numbers and balances filtered out for date 01/17/14 because I need to go into the detail of account and segment that data into smaller pieces by later linking my segmentation excel table. Currenly if I select MonthYear, Its licking to the entire month and not providing me with the account numbers that are relevant to just to the day 01/17/14.

Not applicable
Author

Good afternoon Manish,

I figured out the error of why the differences in the sum. It is only counting the records that have the max number of Days identified under its DAYS. For instance, we were able to identify that for Jan 2014, the DATE_DATA with the max DAYS was 01/17/14. Now with the expression you provided me, it is only adding the accounts on that day that have a 31 as the DAYS. The problem is that I need to have the sum of all the accounts under that DATE_DATA for all the DAYS, not just the ones that have 31. Do you think this can be fixed?

Thank you for the help!