Quantcast
Channel: Desktop topics
Viewing all articles
Browse latest Browse all 213819

YTD measure that works with years in rows as well

$
0
0

Hello,

 

There are many ways to create a YTD measure in DAX. They all work fine. However, what they all seem to lack (at least as far as I am aware) is the possibility to compare YTD Sales when you have only years in the filter context. Imagine it's June 2016 and I would like to compare my Sales to the previous years. I would like to compare similar time periods (Jan - June) for all years. Below an example for illustration:

               

               Sales YTD (undesired)   Sales YTD (desired)

2016          10.000                            10.000

2015          19.000                             9.500

2014          18.000                             9.000

 

My current YTD measure is a as follows:

 

Sales YTD = 
CALCULATE (
    [Sales];
    FILTER (
        ALL ( Date );
        Date[Year] = MAX (  Date[Year] )&& Date[Index] <= MAX ( Date[Index] )
    )
)

I thought all I have to to is to replace MAX ( Date[Index] ) with the Max DayNoOfYear of the current year. I am sure they are way more efficient ways to achieve that, but this is what I have done:

 

I wrote a measure to get the max year in my calender table (which is always the current year in my case)

 

MaxYear =
CALCULATE ( MAX ( Date[Year] ); ALL ( Date ) )

Then I wrote a measure to get the Max DayNoOfYear of the current year

 

MaxDayNoOfYear =
CALCULATE (
MAX ( Date[DayNoOfYear] );
FILTER ( ALL ( Date ); Date[Year] = [MaxYear] )
)

Finally I changed my YTD measure:

 

Sales YTD New = 
CALCULATE (
    [Sales];
    FILTER (
        ALL ( Date );
        Date[Year] = MAX (  Date[Year] )&& Date[Index] <= MAX ( Date[Index] )
    )
)

It works fine if I have only years in rows. However, when I add months too I get the Total YTD value of the year in every row which makes sense since it alway refers to my MaxDayNoOfYear in every row.

 

A possible solution would be to use the "Sales YTD" measure for years and the "Sales YTD New" for all other time periods but I have no idea how to achieve that.

 

Sorry for this long post Smiley Happy Looking forward to some ideas.

 

Sammy


Viewing all articles
Browse latest Browse all 213819

Trending Articles