7 Replies Latest reply: Dec 9, 2013 3:24 AM by Thomas Jensen

# Contribution % - MAT, YTD, MTD for PreviousYear

Hye folks,

I am trying to figure out how to script the contribution % for previous years.

Any ideas?

Best Regards,

Ram

• ###### Re: Contribution % - MAT, YTD, MTD for PreviousYear

YTD & PrevYTD

=sum({<CommonDateField={'>=\$(VPrevYear)<=\$(vMaxDate)'}>}Sales)

VPrevYear=Date(Yearstart(vMaxDate,-1),'DD/MM/YYYY')

For MTD Prv MTD

=sum({<CommonDateField={'>=\$(VPrevMonth)<=\$(vMaxDate)'}>}Sales)

Variables:

VPrevMonth=Date(MonthStart(vMaxDate,-1),'DD/MM/YYYY')

vMaxDate=Date(max(CommonDateField),'DD/MM/YYYY')

• ###### Re: Contribution % - MAT, YTD, MTD for PreviousYear

Hi Nirmal,

Sorry - your explanation is kinda vague. A more descriptive clarification would be appreciated.

My main concern is how do I create a <\$Year={(MAX)Year - 1> variable?

This would definitely help me out, put me on the right path.

Much appreciated.

• ###### Re: Contribution % - MAT, YTD, MTD for PreviousYear

Try Like this

=max(Year(date(CommonDate,'DD/MM/YYYY'))-1)

• ###### Re: Contribution % - MAT, YTD, MTD for PreviousYear

try this  {"=\$(=Max(Year)-1)"}

• ###### Re: Contribution % - MAT, YTD, MTD for PreviousYear

Hi Thomas,

Doesn't work. Syntax error.

• ###### Re: Contribution % - MAT, YTD, MTD for PreviousYear

try this:

=sum({<Year={\$(=only(Year)-1)}>} measure )

• ###### Re: Contribution % - MAT, YTD, MTD for PreviousYear

if you use many YTD and comparison vs previous year, you can

1) use complex set analysis  (take care, you must have only ONE year in your graph)

2) modify your model  (you can have several months & years in your graph)

see a doc I have written on that subject : http://community.qlik.com/docs/DOC-4821

Fabrice