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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jack_Fan2309
Frequent Visitor

Calculate last 12 months data and MOM% in Power Bi

Hi, 

I wanna display Last 12 months sales data and those MOM% and using an other slicer for time selection. 
Here is what I'd like to show in Power BI: 

Jack_Fan2309_1-1679021940677.png

 

I am able to achieve Last 12 months sales by using "DATESINPERIOD" function but now I am struggling with those MOM%. The DAX I used as follows.


Any help is appreciated
Regards,

Jack

 

Last 12 month MOM% =
VAR _Currentdate =
DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[Month] ), 1 )
VAR _Last12month =
CALCULATE (
SUM ( 'Sales'[Actual] ),
DATESINPERIOD ( 'Date'[Date], _Currentdate, - 12, MONTH )
)
VAR _PREV_MONTH =
CALCULATE ( _Last12month, DATEADD ( 'Date'[Date], -1, MONTH ) )
RETURN
_PREV_MONTH

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please try something like below whether it works in your datamodel.

 

Last 12 month MOM% fix =
VAR _Currentdatemonthstart =
    DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[Month] ), 1 )
VAR _Currentdateprevmonthstart =
    IF (
        SELECTEDVALUE ( 'Date'[Month] ) <> 1,
        DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[Month] ) - 1, 1 ),
        DATE ( SELECTEDVALUE ( 'Date'[Year] ) - 1, 12, 1 )
    )
VAR _Last12month =
    CALCULATE (
        SUM ( 'Sales'[Actual] ),
        DATESINPERIOD ( 'Date'[Date], _Currentdatemonthstart, - 12, MONTH )
    )
VAR _PREV_MONTH_12month =
    CALCULATE (
        SUM ( 'Sales'[Actual] ),
        DATESINPERIOD ( 'Date'[Date], _Currentdateprevmonthstart, - 12, MONTH )
    )
RETURN
    DIVIDE ( _Last12month - _PREV_MONTH_12month, _PREV_MONTH_12month )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Dear Kim, 

 

Thanks so much for your reply. I have just tried with your suggestion but the results as the following photo.  Maybe I haven't solved my problem yet. 

 

I have used three Measures as follows: 

 1.  Monthly Sales =
VAR _Currentdatemonthstart = DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ('Date'[Month] ), 1 )
VAR _Last12month = CALCULATE (SUM ( 'Sales'[Actual] ),DATESINPERIOD ( 'Date'[Date], _Currentdatemonthstart, - 12, MONTH ))
RETURN
_Last12month 

 

2.  Previous Month Sales =
VAR _Currentdateprevmonthstart = IF (SELECTEDVALUE ( 'Date'[Month] ) <> 1,
DATE ( SELECTEDVALUE ( 'Date'[Year] ), SELECTEDVALUE ( 'Date'[Month] ) - 1, 1 ),
DATE ( SELECTEDVALUE ( 'Date'[Year] ) - 1, 12, 1 ) )
VAR _PREV_MONTH_12month = CALCULATE (SUM ( 'Sales'[Actual] ), DATESINPERIOD ( 'Date'[Date], _Currentdateprevmonthstart, - 12, MONTH ))
RETURN
_PREV_MONTH_12month

 

 3. MOM% : The DAX is as same as you suggested. 

 

Thanks again. 

 

Best Regards,

Jack

 

Jack_Fan2309_1-1679028524779.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.