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
z29n
Regular Visitor

help needed - difference btw columns

Hello there, 

 

I am trying to create a new measure to calculate difference btw two columns in absolute and % for each year. 

LYOP and OP are Types. 

Could you please help me on this? I do not how to code DAX. 

Capture2.JPGCapture.JPG

 

thanks in advance.. 

 

2 ACCEPTED SOLUTIONS

Try using the following DAX formula.

Negative vari = 
var _lyop = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "LYOP")
var _op = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "OP")
RETURN
IF(SELECTEDVALUE('Table 2'[Type]) = "OP", _lyop - _op, BLANK())

 

Best Regards,

Wisdom Wu

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

no, what I mean is I would like to see the difference OP minus LYOP in a format that either negative or positive based on figures- not only negative ones or not in absolute form. Is it clear? 

View solution in original post

10 REPLIES 10
v-jiewu-msft
Community Support
Community Support

Hi @z29n ,

Based on my testing, please try the following methods:

1.Create the sample table.

vjiewumsft_0-1724981673473.png

2.Create the new measure to calculate absolute.

Absolute = 
var _lyop = SUM('Table'[LYOP])
var _op = SUM('Table'[OP])
RETURN
ABS(_lyop - _op)

3.Create the new measure to calculate percentage.

Percentage = 
var _lyop = SUM('Table'[LYOP])
var _op = SUM('Table'[OP])
RETURN
IF(
    ISBLANK(_lyop),
    BLANK(),
    (_op - _lyop) / _lyop * 100
)

4.Drag the measures into the matrix visual. The result is shown below.

vjiewumsft_1-1724981685176.png

You can also view the following documents to learn more information about DAX function.

ABS function (DAX) - DAX | Microsoft Learn

SUM function (DAX) - DAX | Microsoft Learn

ISBLANK function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Wisdom Wu

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

thanks for the reply but it did not work out 😞 

here is the below result.. 

aaaCapture.JPG

Capturdde.JPG

 

Can you please help me to solve? 

 

thanks in advance.. 

Hi @z29n ,

Based on the desctiption, please try the following formula again.

Absolut = 
var _lyop = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "LYOP")
var _op = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "OP")
RETURN
ABS(_lyop - _op)
Percent = 
var _lyop = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "LYOP")
var _op = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "OP")
RETURN
IF(
    ISBLANK(_lyop),
    BLANK(),
    (_op - _lyop) / _lyop * 100
)

vjiewumsft_0-1725269958750.png

Best Regards,

Wisdom Wu

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

thanks a lot.. 

Is it possible to make "absolute" to appear only in one column on right hand-side instead of repeating itself? 

 

thanks in advance, appreciated.. 

Hi @z29n ,

Try using the following DAX formula.

Absolut = 
var _lyop = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "LYOP")
var _op = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "OP")
RETURN
IF(SELECTEDVALUE('Table 2'[Type]) = "OP", ABS(_lyop - _op), BLANK())

vjiewumsft_0-1725325440839.png

You can also set the column wrap in format visual. Drag the

vjiewumsft_1-1725325473298.png

vjiewumsft_2-1725325479626.png

vjiewumsft_3-1725325492068.png

Best Regards,

Wisdom Wu

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

thanks once more.. 

 

Unfortunately wrapping didn't work for me somehow. I don't know why but the column is still there 😞

 

also, I would like to see the negatives as well, not only absolute figures so minus can work for me. 

 

Thanks again.. 

Hi @z29n ,

After setting the wrap, you need to drag the LYOP right border to hide the absolute data columns.

vjiewumsft_0-1725355603617.png

If you want to get negative numbers, you don’t use abs function.

Absolut = 
var _lyop = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "LYOP")
var _op = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "OP")
RETURN
IF(SELECTEDVALUE('Table 2'[Type]) = "OP", _lyop - _op, BLANK())
//IF(SELECTEDVALUE('Table 2'[Type]) = "OP", ABS(_lyop - _op), BLANK())

vjiewumsft_1-1725355680433.png

 

Best Regards,

Wisdom Wu

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

thanks a lot, now one more thing: I would like to have negative variances as well instead of absolute figures. Can you help me  on that as well? 

 

thanks in advance.. 

Try using the following DAX formula.

Negative vari = 
var _lyop = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "LYOP")
var _op = CALCULATE(SUM('Table 2'[Rev]), 'Table 2'[Type] = "OP")
RETURN
IF(SELECTEDVALUE('Table 2'[Type]) = "OP", _lyop - _op, BLANK())

 

Best Regards,

Wisdom Wu

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

no, what I mean is I would like to see the difference OP minus LYOP in a format that either negative or positive based on figures- not only negative ones or not in absolute form. Is it clear? 

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.