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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tarrantmark
Regular Visitor

Adding a calculated variance - check my data!! Help!!

Hi I have seen a few people posting with issues and most have been resolved with a fairly simple formula. Unfortunately that doesnt seem to work with mine. Ok so I have simplified my data table for this message which is essentially a list of customer orders

OrderCustomerproductFinancial YearValue
1atrouser2021500
2btrouser2022250
3cshirt202120
4djacket202150
5ashirt2022100
6bjacket2022150

 

Using power BI I have been able to do a Matrix table visualisation and that would give me: -

 

Product20212022
Trouser500250
Shirt20100
Jacket50150

 

What I cant seem to workout is how to then do a variance column to show the difference between 2022 and 2021. I assume its because the original table is just a list and not a summarised version (like the Matrix table). I cant seem to insert a column based soley on the Matrix table as it keeps referring to the original data table. 

 

Any clues please!!  I have loads of other things I want to do on Power BI but they probably ALL need a variance of some kind in there!! 

 

Cheers

 

Mark

 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @tarrantmark 

 

You can try the following methods.

Maesure:

Difference =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        ALL ( 'Table' ),
        [Financial Year] = 2022
            && [product] = SELECTEDVALUE ( 'Table'[product] )
    )
)
    - CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            [Financial Year] = 2021
                && [product] = SELECTEDVALUE ( 'Table'[product] )
        )
    )

vzhangti_0-1649647458945.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

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @tarrantmark 

 

You can try the following methods.

Maesure:

Difference =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        ALL ( 'Table' ),
        [Financial Year] = 2022
            && [product] = SELECTEDVALUE ( 'Table'[product] )
    )
)
    - CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            [Financial Year] = 2021
                && [product] = SELECTEDVALUE ( 'Table'[product] )
        )
    )

vzhangti_0-1649647458945.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.

Hi - I tried to apply that to my main data and I am still getting errors - see screenshot. I obviously had to change a few bits to apply it to the different names/fields on my actual data but it just doesnt like it. I have also copied the error code : - 

 

Error Message:
MdxScript(Model) (5, 102) Calculation error in measure 'Data2'[Difference]: DAX comparison operations do not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

 

tarrantmark_0-1650443368416.png

 

If you have any further advice that would be gratefully recieved!! 

Just to make it easier this is what I changed the formula to : - 

Difference = CALCULATE ( SUM ( 'Data2'[Actual Line Value] ), FILTER ( ALL ( 'Data2' ), [Financial Year] = 2022 && [Product Group] = SELECTEDVALUE ( 'Data2'[Product group] ) ) ) - CALCULATE ( SUM ( 'Data2'[Actual Line Value] ), FILTER ( ALL ( 'Data2' ), [Financial Year] = 2021 && [Product group] = SELECTEDVALUE ( 'Data2'[Product group] ) ) )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors