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: 
Rama1
Contributor II
Contributor II

YTD calculation based on selection of week

HI,

 I have my dashboard with different tables and charts with last 4 weeks data and few graphs with last 6 months data and YTD calculations as KPI's.

In my script i created 2 flags for this year and previous year YTD

, if (year(Datefeild) = year(Today()) , 'CY') as YTD_Flag
, if (year(Datefield) = year(Today()) -1 , 'LY') as LYTD_Flag

In my KPI i am using 

SUM({<YTD_Flag={'CY'}  >} [my field] * [my field]) to calculate the calendar YTD for the present year.

If am selecting any week from Previous year from any of the tables then the calendar YTD is showing 0 as this is present year YTD calculation.

Now my requirement is if i select any weeks from previous year then it should display that year YTD and if i select week1 of 2020 then it should display this year YTD and if i select Week53 and Week1 together then it should get those weeks based on the year YTD.

Can anyone help me how to do this.

Note: I want to achieve this in single KPI. Not in two separate KPI's , one for this year and two for Last year

My YTD year is YTD calendar year 1.e week 1...week 53 Previous year

Thanks in advance.

 

2 Replies
Lauri
Specialist
Specialist

Hi Rama1,

When you use the term "YTD" do you mean it as I understand it: Year To Date -- from January 1 until today?

When you say, "if i select any weeks from previous year then it should display that year YTD" do you want the KPI to calculate for the time from January 1 in that year until today's date in that year?

H_Julian
Contributor III
Contributor III

Build a Mastercalendar to connect your date,Week and year for example:

Date,Week,Year

01.01.2019,1,2020

08.01.2019,2,2020

etc...

Than your Date Variable(YTD) can connect to your weekfilter(in Menubar for example)

Greetings