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

Announcements
Q&A with Qlik - Qlik Cloud Migration: Questions about migrating to Qlik Cloud? Catch the latest replay!
cancel
Showing results for 
Search instead for 
Did you mean: 
suryaa30
Creator II
Creator II

YTD calculations

Hi All I am expecting a chart like below.

Movements.PNG

Dimension: Year

Expression: Count(GrossSales_Policy)

Now I want to create a YTD chart. Here YTD means the maximumum date in the maximum year.

so max year is 2017

max date is 27

max month is sep

in the chart i should see data for

1-jan-2016 to 27-Sep-2016

1-jan-2015 to 27-Sep-2015

Individually I have calculated them using below expressions. I want to have a expression to accomodate any number of year's data. so I need not add expression for each year.

if 2016 is selected then for CY=2016

PY=2015

PY_1=2014

eYTDMovementsCY

Count({<Year={'$(=Max(Year))'},Date3={"<=$(=$(vSelectYrDate))"},Month=>}GrossSales_Policy)

eYTDMovementsPY

Count({<Year={'$(=Max(Year)-1)'},Date3={"<=$(=$(vPrevYrDate))"},Month=>}GrossSales_Policy)

vMaxYear Year(Max(Date3))

vMaxPrYear Year(Max(Date3))-1

vAllMaxMonth Num(Month(Max( ALL Date3)))

vAllMaxDate Date(Max(ALL Date3), 'DD-MMM-YY')

vAllMaxDay Day(Max(ALL Date3))

vSelectYrDate Date(MakeDate($(vMaxYear),$(vAllMaxMonth),$(vAllMaxDay)), 'DD-MMM-YY')

vPrevYrDate Date(MakeDate($(vMaxPrYear),$(vAllMaxMonth),$(vAllMaxDay)), 'DD-MMM-YY')

master calendar used;

Master Calender.PNG

Labels (1)
22 Replies
suryaa30
Creator II
Creator II
Author

Forgot to mention that In YTD the valyues for each month should be accumulative.

Actual:

2011

Jan-10

Feb-20

Mar-30

YTD:

2011

Jan-10

Feb-30(10+20)

Mar-40((10+20+30)

sunny_talwar
MVP
MVP

This?

Aggr(RangeSum(Above(Sum({<[Trade Date] = {"=SetDateYear([Trade Date], Max(TOTAL Year)) <= Max(TOTAL [Trade Date])"}>} [Trade Revenue]), 0, RowNo())), Year, Month)

suryaa30
Creator II
Creator II
Author

The values dont add up properly,

for convenience I have used  sum([Trade Revenue])/100000000

ValuesAggr.PNG

sunny_talwar
MVP
MVP

Use this if you have QV12 or above

Aggr(RangeSum(Above(Sum({<[Trade Date] = {"=SetDateYear([Trade Date], Max(TOTAL Year)) <= Max(TOTAL [Trade Date])"}>} [Trade Revenue])/100000000, 0, RowNo())), Year, (Month,(NUMERIC)))

suryaa30
Creator II
Creator II
Author

My Bad it is 11.20.... So any work around? should I settle for Individual values?

thank You very Much

sunny_talwar
MVP
MVP

The problem is the your Month field is not sorted in the correct order... Seems like you have a master calendar setup in your app but it is getting loaded from a qvw... if you can sort the data in your qvw... it will work...

sunny_talwar
MVP
MVP

Alternatively, if you can keep Year as your first dimension and Month as second dimension... this can work (without aggr)

RangeSum(Above(Sum({<[Trade Date] = {"=SetDateYear([Trade Date], Max(TOTAL Year)) <= Max(TOTAL [Trade Date])"}>} [Trade Revenue])/100000000, 0, RowNo()))

Capture.PNG

suryaa30
Creator II
Creator II
Author

So I should be sorting my entire Fact Table  on Trade Date in the script?  Although this is just a sample data let me give it a try.

Thank you so much

sunny_talwar
MVP
MVP

Not the trade date.... but if you can sort your master calendar, then that will do it....

suryaa30
Creator II
Creator II
Author

Appreciate your  Time Thanks Much