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: 
ananyaghosh
Creator III
Creator III

How to use MTD, YTD, WTD calculation in a As-Of table script?

Hi,

I am using the below script: and I need to implement MTD, YTD and WTD calculations. So how to do in the as of table script?

tmpAsOfCalendar:
Load distinct [Order Date]
Resident [Order Data];

Join (tmpAsOfCalendar)
Load [Order Date] as AsOfDate
  Resident tmpAsOfCalendar; 

[As-Of Calendar]:
Load *,
  If(DayDiff=0,'Current Day',If(DayDiff=1,'Previous Day')) as FlagDate,
  If(WeekDiff=0,'Current Week',If(WeekDiff=1,'Previous Week')) as FlagWeek,
  IF(MonthDiff=1 and Day([Order Date]) <= Day(AsOfDate), 'Previous Month',
  IF(MonthDiff=0 and Day([Order Date]) <= Day(AsOfDate), 'Current Month')
  ) as FlagMonth,
  If(YearDiff=0,'Current Year',If(YearDiff=1,'Previous Year')) as FlagYear;
Load
  [Order Date],
  floor([AsOfDate]) as DateKey,
  [AsOfDate],
  [AsOfDate] - [Order Date] as DayDiff,
  Round((WeekStart(AsOfDate)-WeekStart([Order Date]))/7) as WeekDiff,
 
  (Year(AsOfDate)*12 + Month(AsOfDate)) -  (Year([Order Date])*12 + Month([Order Date])) as MonthDiff,
  Year(AsOfDate)-Year([Order Date]) as YearDiff

Resident
  tmpAsOfCalendar
Where
  AsOfDate >= [Order Date];
 
drop table tmpAsOfCalendar;

2 Replies
ananyaghosh
Creator III
Creator III
Author

Please help me for the above post.

ananyaghosh
Creator III
Creator III
Author

Hi,

Please can anybody help me?