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
jiglow3501
Frequent Visitor

difference between two values in same column

Year    T otal Sales       Difference in Sales from Last Year (should be result)
2014    0
2015   2.5                          2.5
2016   4.5                           2
2017   9                             4.5
2018   0                             -9
2019   2                               2

 

How do you write dax for it? 

 

 

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @jiglow3501

 

Please create the calculated column with the formula below.

 

Column =
VAR temp =
    CALCULATE (
        MAX ( 'table'[Total Sales] ),
        FILTER ( 'table', 'table'[Year] = EARLIER ( 'table'[Year] ) - 1 )
    )
RETURN
    IF ( 'Table'[Total sales] - temp = 0, BLANK (), 'Table'[Total sales] - temp )

Then you will get the output below.

 

 Capture.PNG

 

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
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-piga-msft
Resident Rockstar
Resident Rockstar

Hi @jiglow3501

 

Please create the calculated column with the formula below.

 

Column =
VAR temp =
    CALCULATE (
        MAX ( 'table'[Total Sales] ),
        FILTER ( 'table', 'table'[Year] = EARLIER ( 'table'[Year] ) - 1 )
    )
RETURN
    IF ( 'Table'[Total sales] - temp = 0, BLANK (), 'Table'[Total sales] - temp )

Then you will get the output below.

 

 Capture.PNG

 

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-piga-msft

 

I am working with a table with daily quantities.

 

What would be the formula for a calculated column with the daily difference of the quantities?

 

e.g.

 

Date           Qty     Diff

6/1/2020    1

6/2/2020    2          1

 

Thank you!

 

Daniel

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.