Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

CALC MONTH TO DATE (MTD) FROM YEAR TO DATE (YTD)

I have the data  cumulative as Year to date and the Date format is ('YYYYMM'). I am trying to calculate the Month To Date (MTD) for each month .  It sounds easy to just subtract the selected month from the previous month. But how can I accomplish this in QV  Set Analysis dynamically.

Any help is appreciated

14 Replies
teiswamsler
Partner - Creator III
Partner - Creator III

Hi Rehan

This set analysis works for me.

MTD

= Sum( {<
CalenderYear,
CalenderMonth,
CalenderQuater,
%OrderDate = {">=$(=num(MonthStart(Max(%OrderDate))))<=$(=Max(%OrderDate))"}
>}
Sales )

YTD

Sum( {<
CalenderYear,
CalenderMonth,
CalenderQuater,
%OrderDate = {">=$(=Floor( Yearstart(Max(%OrderDate)) ))<=$(=Floor( Max(%OrderDate) ))"}
>}
Sales )

This will dynamically change by the selection in calender.

/Teis

sasiparupudi1
Master III
Master III

try like this

Sum( {<DATE1 = {">=$(=date(MonthStart(Max(DATE1)),'YYYYMM'))<=$(=Max(DATE1))"}>} Sales)

hth

Sasi

sasiparupudi1
Master III
Master III

or

Sum( {<DATE1 = {"=$(=Max(DATE1))"}>} COUNTER1 )

Not applicable
Author

My data is already cumulative YTD, I need to back into it to get the MTD.

Not applicable
Author

My data is already cumulative YTD, I need to back into it to get the MTD.

maxgro
MVP
MVP

If you have a chart with a year month field, maybe with sum(field) - above(sum(field))

Or you can do it in the laod script.

Not applicable
Author

How can I do it in Load Script?. I would rather do that

maxgro
MVP
MVP

maybe this?

SET DateFormat='DD/MM/YYYY';

// start test data

x:

load

  addmonths(MakeDate(2014),rowno()-1) as ym,          // year month

  2*rowno()*rowno()+rowno() as ytd                                   // ytd value

AutoGenerate 24;

left join                                                                               // just to test, add another dimension

load * inline [

dim4

a

b

];

// end test data


// load ordered by .... and when one dimension or year chenge reset

// calc diff between row and previuos row ytd value

y:

NoConcatenate load

  dim4,

  ym,

  ytd,

if(dim4<>Peek(dim4) or year(ym)<>year(peek(ym)), ytd, ytd-Peek(ytd)) as mtd

Resident x

order by dim4, ym;

DROP Table x;

Not applicable
Author

YRMTH        YRMTH                          Sales (YTD)
2015072015Jul20
2015072015Jul30
2015062015Jun40
2015052015May55
2015062015Jun65
2015012015Jan75
2015012015Jan80
2015042015Apr90
2015072015Jul95
Sales Data is Cumulative  

I am trying to calculate Month to Date from this Year to Date data