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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MichaelaMul
Helper I
Helper I

Difference between two different filter values in same column

Hi,

I am trying to make a dax measure that finds the difference between a product and its overall category (group), filtering by entire category and specific product. Below, is sample data, with the yellow column showing what I would like. I have made the following measures but they are not working. Any suggestions are welcome!

Entire Category % Vol Sales = 
CALCULATE(
	SUM('Table'[Volume Sales % Change vs YA]),
	ALL('Table'[Entire Category])
)

Brand % Vol Sales = 
CALCULATE(
	SUM('Table'[Volume Sales % Change vs YA]),
	ALL('Table'[Product])
)

Brand % Vol Sales minus Entire Category % Vol Sales = 
[Brand % Vol Sales] - [Entire Category % Vol Sales]

 

Difference bw category and product.png

 

Thanks!

Michaela

1 ACCEPTED SOLUTION

Hi @MichaelaMul 

You can try thw following measure

% Difference =
VAR _volbyentirecate =
    CALCULATE (
        SUM ( 'Table'[% Vol Sales Change] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Entire Category] = MAX ( 'Table'[Category] ),
        'Table'[Manager] IN VALUES ( 'Table'[Manager] ),
        'Table'[Time] IN VALUES ( 'Table'[Time] )
    )
VAR _volbyproduct =
    CALCULATE (
        SUM ( 'Table'[% Vol Sales Change] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Category] <> BLANK (),
        'Table'[Product] IN VALUES ( 'Table'[Product] ),
        'Table'[Manager] IN VALUES ( 'Table'[Manager] ),
        'Table'[Time] IN VALUES ( 'Table'[Time] )
    )
RETURN
    IF (
        MAX ( 'Table'[Category] ) <> BLANK (),
        _volbyproduct - _volbyentirecate,
        0
    )

Output

vxinruzhumsft_1-1711422159923.png

Best Regards!

Yolo Zhu

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

5 REPLIES 5
AUDISU
Resolver III
Resolver III

Hi @MichaelaMul ,

Can you share some sample data file.


Thanks

 

here's the sample data - 

MichaelaMul_0-1711399113854.png

 

Hi @MichaelaMul 

You can try thw following measure

% Difference =
VAR _volbyentirecate =
    CALCULATE (
        SUM ( 'Table'[% Vol Sales Change] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Entire Category] = MAX ( 'Table'[Category] ),
        'Table'[Manager] IN VALUES ( 'Table'[Manager] ),
        'Table'[Time] IN VALUES ( 'Table'[Time] )
    )
VAR _volbyproduct =
    CALCULATE (
        SUM ( 'Table'[% Vol Sales Change] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Category] <> BLANK (),
        'Table'[Product] IN VALUES ( 'Table'[Product] ),
        'Table'[Manager] IN VALUES ( 'Table'[Manager] ),
        'Table'[Time] IN VALUES ( 'Table'[Time] )
    )
RETURN
    IF (
        MAX ( 'Table'[Category] ) <> BLANK (),
        _volbyproduct - _volbyentirecate,
        0
    )

Output

vxinruzhumsft_1-1711422159923.png

Best Regards!

Yolo Zhu

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

 

 

HI @MichaelaMul ,
Create two new columns in power query.
First column is Entire %

 If [Entire Category <> null then [%Vol Sales Change] else null

Then fill down this new column.
Second Column Difference Between Product Group

 

If [Entire Category <> null then null else [Entire %] -  [%Vol Sales Change]

Thanks

Hi @MichaelaMul ,
Could you please copy and paste data rather than image.
Thanks.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.