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

Comparaison between old category and new category

Hello everyone, 

I have a table with the actual category and another column with new category and I would like to calculate the spend difference between the old and the new category.

Let me explain you with an example:

AxelKAp_0-1675083985474.png

I would like to have the spend in € for each categories for old and new, like that I can compare if we have less or more spend for each category by [New Spend]- [Old Spend].

Thanks for your support !



1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Create a category dimension table like 

Category =
DISTINCT (
    UNION (
        SELECTCOLUMNS ( DISTINCT ( 'Table'[Old] ), "Category", 'Table'[Old] ),
        SELECTCOLUMNS ( DISTINCT ( 'Table'[New] ), "Category", 'Table'[New] )
    )
)

and then link this table to the data table for both Old and New columns. Only 1 relationship can be active but thats OK.

You can then create a measure like

Diff old and new =
VAR OldValue =
    CALCULATE (
        SUM ( 'Table'[Spend] ),
        USERELATIONSHIP ( 'Table'[Old], 'Category'[Category] )
    )
VAR NewValue =
    CALCULATE (
        SUM ( 'Table'[Spend] ),
        USERELATIONSHIP ( 'Table'[New], 'Category'[Category] )
    )
RETURN
    NewValue - OldValue

and put this in a visual with the category column from the dimension table

View solution in original post

2 REPLIES 2
AxelKAp
Helper I
Helper I

@johnt75 It works ! Thank a lot for your support 🙂

 

johnt75
Super User
Super User

Create a category dimension table like 

Category =
DISTINCT (
    UNION (
        SELECTCOLUMNS ( DISTINCT ( 'Table'[Old] ), "Category", 'Table'[Old] ),
        SELECTCOLUMNS ( DISTINCT ( 'Table'[New] ), "Category", 'Table'[New] )
    )
)

and then link this table to the data table for both Old and New columns. Only 1 relationship can be active but thats OK.

You can then create a measure like

Diff old and new =
VAR OldValue =
    CALCULATE (
        SUM ( 'Table'[Spend] ),
        USERELATIONSHIP ( 'Table'[Old], 'Category'[Category] )
    )
VAR NewValue =
    CALCULATE (
        SUM ( 'Table'[Spend] ),
        USERELATIONSHIP ( 'Table'[New], 'Category'[Category] )
    )
RETURN
    NewValue - OldValue

and put this in a visual with the category column from the dimension table

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.