Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
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
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

Not applicable
Author

But I have a lot of Dimensions, its a BIg Table, how does this logic works with mine, how AM I gonna  check this  if(dim4<>Peek(dim4) or year(ym)<>year(peek(ym)), ytd, ytd-Peek(ytd)) as mtd

maxgro
MVP
MVP

i think the logic is always the same also with n dimensions

- you must have all the months for all the dims

- when some dim or the year chenge restart

I add a dimension to my test data, now the dims are country and product

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;

// just to test, add 2 dimensions

left join load * inline [

product

a

b

c

];

left join load * inline [

country

italy

germany

france

];

// end test data

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

// calc diff between row and previuos row ytd value

y:

NoConcatenate load

  product, country,

  ym,

  ytd,

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

Resident x

order by product, country, ym;

DROP Table x;

Not applicable
Author

Thanx for the quick response, but am I gonna check  this

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


for each dimension??????

maxgro
MVP
MVP

yes

or create a new field

dim1 & '|' & dim2 & '|' & dim3 ...... as new field

and check this field

if(newfield<>peek(newfield)........