Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

paulacalvalis
New Contributor III

YTD this year, comparing THE SAME PERIOD previous YTD

Hi Qlikers!

I have 2 fields: OrderDate -> 01/01/2016 and Sales.

To calculate Current YTD im using this measure: =SUM({$<OrderDate = {'>=$(=YearStart(Today()))<=$(=MonthEnd(Today()))'}>}Sales) and it works well.

To calculate Previous YTD im using: SUM({$<OrderDate = {'>=$(=AddMonths( YearStart (Today()),-12))<=$(=AddMonths( MonthEnd (Today()),-12))'}>}Sales) and it works well too!

But now i want to calculate the same period of the previous year. Example:

Im calculating YTD: Sales from 01/01/2016 to 27/07/2016

I want to calculate from previous YTD: Sales from 01/01/2015 to 27/07/2015..

Anyone have any idea?

Thanks a lot!!

7 Replies
danansell42
Contributor III

Re: YTD this year, comparing THE SAME PERIOD previous YTD

Hi Paula

I always find it easiest to use flags in the calendar script using yeartodate function

Example:

YearToDate(OrderDate,0 ,1,today()) as CurYTDFlag, 

     YearToDate(OrderDate,-1,1,today()) as LastYTDFlag,

It also makes the set analysis easier in the user interface

set analysis example:

sum({<$(CurYTDFlag)={'-1'}>} Sales)

Thanks

Dan

paulacalvalis
New Contributor III

Re: YTD this year, comparing THE SAME PERIOD previous YTD

Thank you!

I will try with flags!

It looks some easy but...

How can i compare this Current YTD with THE SAME PERIOD from Previous YTD??

Regards,

Paula

MVP
MVP

Re: YTD this year, comparing THE SAME PERIOD previous YTD

maybe removing monthend

To calculate Previous YTD im using: SUM({$<OrderDate = {'>=$(=AddMonths( YearStart (Today()),-12))<=$(=AddMonths( MonthEnd (Today()),-12))'}>}Sales) and it works well too!

SUM({$<OrderDate = {'>=$(=AddMonths( YearStart (Today()),-12))<=$(=AddMonths(  (Today()),-12))'}>}Sales)

danansell42
Contributor III

Re: YTD this year, comparing THE SAME PERIOD previous YTD

if you wanted a growth figure then use something like the below:

num(sum({<$(CurYTDFlag)={'-1'}>} Sales)/sum({<$(LastYTDFlag)={'-1'}>} Sales)-1,'#,##0.00%')

paulacalvalis
New Contributor III

Re: YTD this year, comparing THE SAME PERIOD previous YTD

Thanks for you reply Maxgro,

but it doesn't runs well.

Regards,Paula.

MVP
MVP

Re: YTD this year, comparing THE SAME PERIOD previous YTD

How about this:

Sum({$<OrderDate = {"$(='>=' & YearStart(AddMonths(Today(), -12)) & '<=' & AddMonths(Today(), -12))"}>}Sales)

If you put this -> ='>=' & YearStart(AddMonths(Today(), -12)) & '<=' & AddMonths(Today(), -12) in the text box, it should show you the range (01/01/2015 to 27/07/2015) in the format of your OrderDate field.

danansell42
Contributor III

Re: YTD this year, comparing THE SAME PERIOD previous YTD

Hi Paula


Did any of the responses solve your query?

Please mark one as correct to help other community users.

Thanks

Dan