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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
greend21
Creator III
Creator III

Max Date per Month

I have data like the below example and want my pivot table to only show the values for the max date per month. I have a variable to toggle the view so I tried =If($(vValuationDate) = 0, MonthName(Aggr(Max(ValuationDate), ValuationDate.autoCalendar.YearMonth)), ValuationDate) but it shows the values for 2015-01-22 and 2015-02-12. The other odd thing is if I remove the IF statement and only have =MonthName(Aggr(Max(ValuationDate), ValuationDate.autoCalendar.YearMonth)) I get the sum total for each month instead of a specific week's total. I would think the results would at least be consistent. Does anyone know how to get the desired format?

 Current format:

ValuationDateNumber
2015-01-02131
2015-01-08148
2015-01-15234
2015-01-22233
2015-01-29165
2015-02-05181
2015-02-1272
2015-02-19194
2015-02-2774

 

Needed format:

ValuationDateNumber
2015-01-29165
2015-02-2774
Labels (1)
13 Replies
greend21
Creator III
Creator III
Author

Actually, do you know how to flag the last date per month in the load script? I was going to try another method using flags and set analysis but AGGR doesn't work in the load script.

sunny_talwar
MVP
MVP

If(Date = Floor(MonthEnd(Date)), 1, 0) as MonthEndDateFlag
greend21
Creator III
Creator III
Author

Thanks. I should have worded my question better because I meant out of the dates I have in the data, for example if I do not actually have the last day of the month.

In case anyone else has a similar issue, I was able to solve my problem in the load script. Here is what I did as a reference:

[Can_UnallocCashSummary]:
LOAD
[LOB],
[ValuationDate],
[CANCashAge],
[CANBusinessType],
[ClosedAmt],
[ClosedCt],
MonthName([ValuationDate]) AS [CANMonth]
FROM [lib://Ad_Hoc_ QVD_Folder/Can_UnallocCashSummary.qvd]
(qvd);

LEFT JOIN(Can_UnallocCashSummary)

Load Date(Max(ValuationDate)) as CANMaxWk,
CANMonth
Resident Can_UnallocCashSummary
Group By CANMonth
;

LEFT JOIN(Can_UnallocCashSummary)

Load IF(ValuationDate = CANMaxWk, ClosedCt) as CANMaxWkCt,
IF(ValuationDate = CANMaxWk, ClosedAmt) as CANMaxWkAmt,
IF(ValuationDate = CANMaxWk, ValuationDate) as ValuationDate,
CANMaxWk,
CANMonth,
LOB,
CANBusinessType,
CANCashAge
Resident Can_UnallocCashSummary
;
nitrog3n
Partner - Contributor
Partner - Contributor

Hi Sunny, 

The expression you have shared is working perfect with me but the only issue is when I select any month I get data of that particular month.

My requirement is to get data for 6 months i.e if I select any month I should get data of that month + 5 previous months.

Expression used:

num(Sum({<Date={">=$(=Date(Num(MonthStart(AddMonths(Max(Date),-6))),'YYYY/MM/DD'))<=$(=Date(Num(Max(Date),-1),'YYYY/MM/DD'))"},MonthYear=>}
Aggr(If(Date = Max(TOTAL <MonthYear> Date),
count({<Date={">=$(=Date(Num(MonthStart(AddMonths(Max(Date),-6))),'YYYY/MM/DD'))<=$(=Date(Num(Max(Date),-1),'YYYY/MM/DD'))"},MonthYear=,
[Difference Category]={'7Days'}>}Distinct [DEVICE NO])),Date, MonthYear))

/

Sum({<Date={">=$(=Date(Num(MonthStart(AddMonths(Max(Date),-6))),'YYYY/MM/DD'))<=$(=Date(Num(Max(Date),-1),'YYYY/MM/DD'))"},MonthYear=>}
Aggr(If(Date = Max(TOTAL <MonthYear> Date),
count({<Date={">=$(=Date(Num(MonthStart(AddMonths(Max(Date),-6))),'YYYY/MM/DD'))<=$(=Date(Num(Max(Date),-1),'YYYY/MM/DD'))"},
MonthYear=>}Distinct [DEVICE NO])),Date, MonthYear)),'0.0%')