Dax function R12M

Axelle

New Member
Joined
Apr 16, 2018
Messages
19
Hi,
I have written a measure in DAX to calculate the turnover of the past 12 months (Rolling 12 months) per customer:

CALCULATE([Turnover];
FILTER(ALL(T_Calendar);
T_Calendar[MonthNumber]=MONTH(TODAY())-1&&T_Calendar[Year]=YEAR(TODAY())
||T_Calendar[MonthNumber]=MONTH(TODAY())-2&&T_Calendar[Year]=Year(TODAY())
||T_Calendar[MonthNumber]=MONTH(TODAY())-3&&T_Calendar[Year]=Year(TODAY())
||T_Calendar[MonthNumber]=MONTH(TODAY())-4&&T_Calendar[Year]=Year(TODAY())
||T_Calendar[MonthNumber]=MONTH(TODAY())&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+1&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+2&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+3&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+4&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+5&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+6&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+7&&T_Calendar[Year]=Year(TODAY())-1
||T_Calendar[MonthNumber]=MONTH(TODAY())+8&&T_Calendar[Year]=Year(TODAY())-1))

Is there a way to write this more efficiently? I have to adjust this monthly.
Thanks in advance!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Have a look at this article:

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

The key code is:

Code:
<code class="dax plain">Sales12M := </code><code class="dax color2">CALCULATE</code> <code class="dax parenthesis">(</code>
<code class="dax spaces">    </code><code class="dax plain">[Sales],</code>
<code class="dax spaces">    </code><code class="dax color2">DATESBETWEEN</code> <code class="dax parenthesis">(</code>
<code class="dax spaces">        </code><code class="dax color2">Calendar</code><code class="dax plain">[FullDate],</code>
<code class="dax spaces">        </code><code class="dax color2">NEXTDAY</code> <code class="dax parenthesis">(</code> <code class="dax color2">SAMEPERIODLASTYEAR</code> <code class="dax parenthesis">(</code> <code class="dax color2">LASTDATE</code> <code class="dax parenthesis">(</code> <code class="dax color2">Calendar</code><code class="dax plain">[FullDate] </code><code class="dax parenthesis">)</code> <code class="dax parenthesis">)</code> <code class="dax parenthesis">)</code><code class="dax plain">,</code>
<code class="dax spaces">        </code><code class="dax color2">LASTDATE</code> <code class="dax parenthesis">(</code> <code class="dax color2">Calendar</code><code class="dax plain">[FullDate] </code><code class="dax parenthesis">)</code>
<code class="dax spaces">    </code><code class="dax parenthesis">)</code>
<code class="dax parenthesis">)</code>

You could replace the LASTDATE ( Calendar[FullDate] ) with TODAY ( ).

In order to use time intelligence you need a contiguous daily list of dates. If you don't have one already then you could create one and connect it to your existing calendar table.
 
Upvote 0
Hi,

thank you for your answer.
The article was also very interesting.

For this I need a measure that does not change depending on which dates in the filters, because I want to use this measure to create a calculated column in order to categorize customers.

now I have written it like this:

=CALCULATE([Turnover];
DATESBETWEEN(T_Calendar[Date];
DATE(YEAR(TODAY())-1;MONTH(TODAY());1);
DATE(YEAR(TODAY());MONTH(TODAY())-1;30)))

is there a way to make the last day of the month dynamic? I have written 30 because this is about April data. But for May this must be 31 ..

Thanks in advance!
 
Upvote 0
Adopt quite understand what you are doin, but look up EOMONTH () , or just add 1 month and subtract 1.
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top