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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
JustDavid
Helper III
Helper III

How to have measure variance to flip the sign

As the subject says, I'm trying to create a measure that shows the variance between 2 measures - [measure_PrevAmount] and [measure_CurrAmount].

 

After googling, although was told that I could use SWITCH, my question now is that, given that my table could collapse or expand depending on user's view, I want to show the correct variance calculation.

 

As shown in the print screen, I have 6 cost codes, that made up of 'Revenue' category. But it's sub categories are 'Items Sold' (Obj_Code 1500, 1501 and 1502) and 'Promotions' (Obj_Code 1520, 1530 and 1540).

 

How can I flip the sign when it's Obj_Code 1500, 1501 and 1502 even though it's not showing in the table? In other words, those highlighted variance in yellow need to show positive amount, and that the Revenue subtotal will show 185 instead of -215

 

Sign Flip on Measure.png

9 REPLIES 9
danextian
Super User
Super User

Hi @JustDavid 

Please try  this:

CALCULATE ( - [Variance], KEEPFILTERS ( 'table'[Sub Category] = "Items Sold" ) )
    + CALCULATE ( [Variance], KEEPFILTERS ( 'table'[Sub Category] <> "Items Sold" ) )

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Ritaf1983
Super User
Super User

Hi @JustDavid 
You can use the measure :

Variance =
VAR itemsSoldVariance =
SUMX(
FILTER( 'Table', 'Table'[Sub category] = "items sold" ),
('Table'[prev amount] - 'Table'[curr amount]) * -1
)

VAR otherVariance =
SUMX(
FILTER( 'Table', 'Table'[Sub category] <> "items sold" ),
'Table'[prev amount] - 'Table'[curr amount]
)

VAR totalVariance =
SUMX(
'Table',
IF( 'Table'[Sub category] = "items sold",
('Table'[prev amount] - 'Table'[curr amount]) * -1,
('Table'[prev amount] - 'Table'[curr amount])
)
)

RETURN
IF( HASONEVALUE('Table'[Category]), itemsSoldVariance + otherVariance, totalVariance )

Result:

Ritaf1983_0-1740289247549.png

Pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

@Ritaf1983 Instead of using Table[Sub category], if I want to incorporate your formula with [Obj_code], how do I take into consideration of 1500, 1501 and 1502?

Hi @JustDavid 
This is the same logic, different condition :

Variance =
VAR itemsSoldVariance =
    SUMX(
        FILTER( 'Table', 'Table'[obj code] IN {1500,1501,1502} ),
        ('Table'[prev amount] - 'Table'[curr amount]) * -1
    )

VAR otherVariance =
    SUMX(
        FILTER( 'Table', NOT 'Table'[obj code]  IN {1500,1501,1502}),
        'Table'[prev amount] - 'Table'[curr amount]
    )

VAR totalVariance =
    SUMX(
        'Table',
        IF( 'Table'[obj code] IN {1500,1501,1502},
            ('Table'[prev amount] - 'Table'[curr amount]) * -1,
            ('Table'[prev amount] - 'Table'[curr amount])
        )
    )

RETURN
IF( HASONEVALUE('Table'[Category ]), itemsSoldVariance + otherVariance, totalVariance )
The updated pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi @JustDavid ,

Based on the sample data you provided, could you clarify what your expected result is? To help us investigate further, would you kindly share additional details, specific examples, and a supporting screenshot illustrating the issue? Thank you for your assistance.

@Ritaf1983 Instead of using Table[Sub category], if I want to incorporate your formula with [Obj_code], how do I take into consideration of 1500, 1501 and 1502?


vyiruanmsft_0-1740451400777.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

Try these measures

Measure = if(Data[Obj_code]="1500"||Data[Obj_code]="1501"||Data[Obj_code]="1502",[measure_curramount]-[measure_prevamount],[measure_prevamount]-[measure_curramount])

Measure2 = SUMX(VALUES(Data[Cost code]),[Measure])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur Quick question.

 

What's the purpose of Measure2 here?

To get the correct Grand Total.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

Try these measures

Measure = if(Data[Obj_code]="1500"||Data[Obj_code]="1501"||Data[Obj_code]="1502",[measure_curramount]-[measure_prevamount],[measure_prevamount]-[measure_curramount])

Measure2 = SUMX(VALUES(Data[Cost code]),[Measure])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.