Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
YRMTH | YR | MTH | Sales (YTD) | |
201507 | 2015 | Jul | 20 | |
201507 | 2015 | Jul | 30 | |
201506 | 2015 | Jun | 40 | |
201505 | 2015 | May | 55 | |
201506 | 2015 | Jun | 65 | |
201501 | 2015 | Jan | 75 | |
201501 | 2015 | Jan | 80 | |
201504 | 2015 | Apr | 90 | |
201507 | 2015 | Jul | 95 | |
Sales Data is Cumulative |
I am trying to calculate Month to Date from this Year to Date data
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
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;
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??????
yes
or create a new field
dim1 & '|' & dim2 & '|' & dim3 ...... as new field
and check this field
if(newfield<>peek(newfield)........