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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
cjcj
Helper I
Helper I

Previous month sales

Hi I have read a few posts on this issue, but I could not get anything to work properly.

 

I have the following table and want to create a measure to find the difference from the current Selected month to the previous month.  The following works, but the problem is that I am having problems making the date "MAY" dynamic to refer to the previous month when the user changes the date filter on the table below.

 

Sales difference from previous month =

VAR __BASELINE_VALUE =

    CALCULATE(

        SUM('Tbl_sales’[Sales]),

        'DIM_Date'[Date].[Month] IN { "May" },

        ALL('DIM_Date'[Date].[MonthNo])

    )

VAR __MEASURE_VALUE = SUM('Tbl_sales’[Sales]),

RETURN

    IF(NOT ISBLANK(__MEASURE_VALUE), __MEASURE_VALUE - __BASELINE_VALUE)

 

cjcj_0-1661754390869.png

 

Thank you!

2 ACCEPTED SOLUTIONS
MahyarTF
Memorable Member
Memorable Member

Hi

Use the below code instead of the "MAY" :

Format( month(EOMONTH( SELECTEDVALUE( 'DIM_Date'[Date]), -1 ) ), "MMM")
Appreciate your Kudos
Mahyartf

View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below, and I suggest having a calendar table like below.

I hope the below sample can provide some ideas on how to create a solution for your dataset.

 

Picture1.png

 

Sales measure: = 
SUM( Sales[Sales] )

 

Sales Previous month: = 
    CALCULATE( [Sales measure:], 
        DATEADD( 'Calendar'[Date], -1, MONTH ) 
    )

 

Sales diff: = 
IF( not ISBLANK( [Sales measure:] ), [Sales measure:] - [Sales Previous month:] )

 

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.


Go to My LinkedIn Page


View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below, and I suggest having a calendar table like below.

I hope the below sample can provide some ideas on how to create a solution for your dataset.

 

Picture1.png

 

Sales measure: = 
SUM( Sales[Sales] )

 

Sales Previous month: = 
    CALCULATE( [Sales measure:], 
        DATEADD( 'Calendar'[Date], -1, MONTH ) 
    )

 

Sales diff: = 
IF( not ISBLANK( [Sales measure:] ), [Sales measure:] - [Sales Previous month:] )

 

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.


Go to My LinkedIn Page


Tried this as well and it worked great!  thank you!

MahyarTF
Memorable Member
Memorable Member

Hi

Use the below code instead of the "MAY" :

Format( month(EOMONTH( SELECTEDVALUE( 'DIM_Date'[Date]), -1 ) ), "MMM")
Appreciate your Kudos
Mahyartf

that worked GREAT!  thank you and others on the community!

TomMartens
Super User
Super User

Hey @cjcj ,

 

this article contains almost everything you need to know about time/date calculations: Time patterns – DAX Patterns
Check the time intelligence function PREVIOUSMONTH: PREVIOUSMONTH – DAX Guide

 

Hopefully, this will provide some information on how to tackle your challenge.

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.