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
corpsikumar
Helper I
Helper I

Calculate Monthly Difference DAX

Hello Power Users,

 

I'm trying to create a measure or calculation for Monthly difference. but not getting exactly what i need. Basically what i'm trying to do get the difference for Amount for each Milestone number & Date. 

corpsikumar_0-1661212106637.png

 

I have create a previous month measure like calculate (Sum(Amount), Prevousmonth(Date) that gives me the previous month amount and i'm just subtracting amount-previousmonth amount to the difference. If you observe in the data there is no data for march for 123 in that i would like get the difference Feb to Apr. it should be like 200-400 but in my logic there is no data  for march then it considers as 0 then its give me 200-0. 

 

Please help. 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @corpsikumar 

 

You can try the following methods.

Preamount =
VAR PreDate =
    MAXX (
        FILTER (
            ALL ( 'Table'[Entry_Date], 'Table'[Milestonenumber] ),
            [Entry_Date] < SELECTEDVALUE ( 'Table'[Entry_Date] )
                && [Milestonenumber] = SELECTEDVALUE ( 'Table'[Milestonenumber] )
        ),
        'Table'[Entry_Date]
    )
VAR Preamount =
    CALCULATE (
        SUM ( 'Table'[amount] ),
        FILTER (
            ALL ( 'Table' ),
            [Entry_Date] = PreDate
                && [Milestonenumber] = SELECTEDVALUE ( 'Table'[Milestonenumber] )
        )
    )
RETURN
    Preamount
Difference = IF([Preamount]<>BLANK(),[Preamount]-SUM('Table'[amount]))

vzhangti_0-1661396458907.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @corpsikumar 

 

You can try the following methods.

Preamount =
VAR PreDate =
    MAXX (
        FILTER (
            ALL ( 'Table'[Entry_Date], 'Table'[Milestonenumber] ),
            [Entry_Date] < SELECTEDVALUE ( 'Table'[Entry_Date] )
                && [Milestonenumber] = SELECTEDVALUE ( 'Table'[Milestonenumber] )
        ),
        'Table'[Entry_Date]
    )
VAR Preamount =
    CALCULATE (
        SUM ( 'Table'[amount] ),
        FILTER (
            ALL ( 'Table' ),
            [Entry_Date] = PreDate
                && [Milestonenumber] = SELECTEDVALUE ( 'Table'[Milestonenumber] )
        )
    )
RETURN
    Preamount
Difference = IF([Preamount]<>BLANK(),[Preamount]-SUM('Table'[amount]))

vzhangti_0-1661396458907.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much

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.