Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AKARSEVGI
Helper I
Helper I

Last 12 Months Sales

How can I calculate the sales as sliding? I mean for example; we are in May 2022 . If I want to sum of sales by sales origin and sales department and country group but as last 12 months which doesn't include May 2022. How can I ?

1 ACCEPTED SOLUTION
Whitewater100
Solution Sage
Solution Sage

Hi:

You can have month slicer and choose April 2022:

Sales (last n months) =

VAR MaxFactDate =

    CALCULATE ( MAX ( Sales[Posting Date] ), ALL ( Dates ) ) // ignore the selected date filter, and find the max of date in Sales table

VAR FDate =

    ENDOFMONTH ( Dates[Date] ) // get the last day of the month selected in the date filter

VAR Edate =

    EDATE ( FDate,- [N Value] ) //  get the last day of -N months

RETURN

    IF (

MaxFactDate <= MAX ( Dates[Date] )

&& MaxFactDate > Edate,

        CALCULATE ( [Sales] ), ALL ( Dates ) )

 

You can also add Calc col to your date table and set filter to TRUE. This insures only completed months.

Completed Month =
VAR ThisMonthID =
LOOKUPVALUE('Dates'[Running Month Index], 'Dates'[Date Key], TODAY())
RETURN 'Dates'[Running Month Index] < ThisMonthID
//returns TRUE() if the month is in the past and complete
 
Some like using the folowing measure for past year:
CALCULATE([Total Sales],PARALLELPERIOD('Dates'[Date],-12,MONTH))
 
You can have filter for completed month here too:
Whitewater100_0-1654009892183.png

 

I hope this solves for you. 

View solution in original post

5 REPLIES 5
AKARSEVGI
Helper I
Helper I

This very complicated. not just April. I want for all months.  

Hello:

 

Are you able to check the solution for you? If you have any questions, i'll try to answer. Thanks

Hello, Could you send it to me (sevgi.akar@haus.com.tr) if you have any example power bi work? I can study with it easly.  Thanks 

Hi:

DAX can look complicated - I agree! But these measures aren't too bad after you use them a bit. I will attach a file which shows how the date table has relationship with the data table. If you look at the calc cols in Date Table you will see about insuring month is complete. It's critical to have this date table for time intel calculations. These figures are not April only. I hope this solves your question. Thanks

 

Whitewater100_0-1654011983230.png

 

https://drive.google.com/file/d/11TnA0izWB65WgnsuJeDiGeuYrUN60gOG/view?usp=sharing 

Whitewater100
Solution Sage
Solution Sage

Hi:

You can have month slicer and choose April 2022:

Sales (last n months) =

VAR MaxFactDate =

    CALCULATE ( MAX ( Sales[Posting Date] ), ALL ( Dates ) ) // ignore the selected date filter, and find the max of date in Sales table

VAR FDate =

    ENDOFMONTH ( Dates[Date] ) // get the last day of the month selected in the date filter

VAR Edate =

    EDATE ( FDate,- [N Value] ) //  get the last day of -N months

RETURN

    IF (

MaxFactDate <= MAX ( Dates[Date] )

&& MaxFactDate > Edate,

        CALCULATE ( [Sales] ), ALL ( Dates ) )

 

You can also add Calc col to your date table and set filter to TRUE. This insures only completed months.

Completed Month =
VAR ThisMonthID =
LOOKUPVALUE('Dates'[Running Month Index], 'Dates'[Date Key], TODAY())
RETURN 'Dates'[Running Month Index] < ThisMonthID
//returns TRUE() if the month is in the past and complete
 
Some like using the folowing measure for past year:
CALCULATE([Total Sales],PARALLELPERIOD('Dates'[Date],-12,MONTH))
 
You can have filter for completed month here too:
Whitewater100_0-1654009892183.png

 

I hope this solves for you. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors