Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
kevbrown
Creator II
Creator II

Max month, less 1 month, Rolling 3 and 12 Months

I'm looking to use the following expression but only pull out the max of my reporting_period (text field), last months results, as well as rolling 3 and 12 month sums

count(distinct(if(IsNull(MIN_Ledger_Entry)=0 AND CBP_Blink_Flag='Blink',Risk_No)))

Easy?

Kev

4 Replies
arvind_patil
Partner - Specialist III
Partner - Specialist III

Hi kevin,

You will get idea from below code:

QuartersMap: 

MAPPING LOAD  

rowno() as Month, 

'Q' & Ceil (rowno()/3) as Quarter 

AUTOGENERATE (12); 

 

Temp: 

Load 

               min(TransactionDate) as minDate, 

               max(TransactionDate) as maxDate 

Resident LinKTable; 

 

Let varMinDate = Num(Peek('minDate', 0, 'Temp')); 

Let varMaxDate = Num(Peek('maxDate', 0, 'Temp')); 

Let CurrentDate=Num(Peek('maxDate', 0, 'Temp'));

Let CurrentYear=Year(Num(Peek('maxDate', 0, 'Temp')));

DROP Table Temp; 

 

TempCalendar: 

LOAD 

               $(varMinDate) + Iterno()-1 As Num, 

               Date($(varMinDate) + IterNo() - 1) as TempDate 

               AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate); 

 

MasterCalendar: 

Load 

               TempDate AS TransactionDate, 

               week(TempDate) As Week, 

               Year(TempDate) As Year, 

               Month(TempDate) As Month, 

               Day(TempDate) As Day, 

               YeartoDate(TempDate)*-1 as CurYTDFlag, 

               YeartoDate(TempDate,-1)*-1 as LastYTDFlag, 

               inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12, 

               date(monthstart(TempDate), 'MMM-YYYY') as MonthYear, 

               ApplyMap('QuartersMap', month(TempDate), Null()) as Quarter, 

               Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear, 

               WeekDay(TempDate) as WeekDay  ,

               //Rolling

              

     If( TempDate > addmonths($(CurrentDate),-11) and TempDate <= Today(),1) as _R12, // Rolling 12

    If( TempDate > addmonths($(CurrentDate),-2) and TempDate <= Today(),1) as _R2, // Rolling 2

    If( TempDate > addmonths($(CurrentDate),-3) and TempDate <= Today(),1) as _R3, // Rolling 3

    If( TempDate > addmonths($(CurrentDate),-6) and TempDate <= Today(),1) as _R6, // Rolling 6

    If( TempDate > addmonths($(CurrentDate),-24) and TempDate <= addmonths($(CurrentDate),-12),1) as _R13_24// Rolling 13 -24

Resident TempCalendar 

Order By TempDate ASC; 

Drop Table TempCalendar; 

Thanks,

Arvind Patil

Kushal_Chawda

kevbrown
Creator II
Creator II
Author

I have the rolling month flag, that isn't the problem, its more of how to get the Max Month added into the expressions

count(distinct(if(IsNull(MIN_Ledger_Entry)=0 AND CBP_Blink_Flag='Blink',Risk_No)))

and then max month -1

Kushal_Chawda

Create the if condition flag in script

LOAD *,

if(IsNull(MIN_Ledger_Entry)=0 AND CBP_Blink_Flag='Blink',1) as RiskFlag


Now you can use expression like below


=count({<RiskFlag={1}, MonthYear={"$(=date(max(MonthYear),'MMM YYYY'))"}>}Risk_No)


Note: Assuming you have created MonthYear field in script with format MMM YYYY