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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
dpeterson99
New Member

Help Calculating the Difference Between Two Normalized Columns

I have a raw data table that holds information about the inventory of two different retail stores. It includes 4 columns:

 

Column 1: the unique ID of the inventory item

Column 2: the category of the inventory item (clothing, electronics, toys or food)

Column 3: the relative size (%) of the item in Store A's inventory

Column 4: the relative size (%) of the item in Store B's inventory

 

The two stores have some overlapping inventory, but not every item in Store A's inventory is in Store B's inventory (and vice versa). Therefore, there can be values of zero in Columns 3 and 4.

 

In the Power BI Desktop app, I imported this raw data table and then created a Table widget that shows the relative size of each inventory category for each store, as well as the difference in size between the two stores. To do this, I simply dragged Columns 2, 3 and 4 into my table and then created a Custom Measure to calculate the difference (see DAX expression below):

 

Difference = SUM([Column 3]) - SUM([Column 4])

 

The final table came out as expected and looks something like this (recreated in Excel for privacy reasons):

 

dpeterson99_5-1674158323173.png

 

I then decided I wanted the ability to filter by inventory category. That way I could filter to Food and Toys, for example, before renormalizing the sizes and viewing the difference in inventory makeup between the two stores. I added a Filter widget to my Power BI, set the "Store A Inventory %" and "Store B Inventory %" columns to display as a % of the Column Total, and then tested it out. To my dismay, this was the result (again reproduced in Excel):

 

dpeterson99_7-1674158812602.png

 

Although the first two columns were renormalized to 100% as expected, the Difference column is still referencing the underlying data and isn't aware that I have renormalized the columns it is supposed to be showing the difference of. The expected output would have been:

 

dpeterson99_8-1674158957119.png

 

Displaying the difference column as a % of the Grand or Column Total is not a solution because this would simply show the proportion between the two rows. What I need is a way to simply and directly calculate the difference between the two columns in the Table, as opposed to referencing the raw data which obviously doesn't change when filters are applied. It seems like something that should be very easy to do, but I have yet to find a solution. Any tips/suggestions/questions are welcome.

 

Thanks!

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @dpeterson99 ,

 

According to your statement, I think your table should look like as below.

RicoZhou_0-1674198035122.png

M_Store A of inventory % = 
VAR _CURRENTVALUE =
    CALCULATE ( SUM ( 'Table'[Store A of inventory %] ) )
VAR _TOTAL =
    CALCULATE ( SUM ( 'Table'[Store A of inventory %] ), ALLSELECTED ( 'Table' ) )
RETURN
    DIVIDE ( _CURRENTVALUE, _TOTAL )
M_Store B of inventory % = 
VAR _CURRENTVALUE =
    CALCULATE ( SUM ( 'Table'[Store B of inventory %] ) )
VAR _TOTAL =
    CALCULATE ( SUM ( 'Table'[Store B of inventory %] ), ALLSELECTED ( 'Table' ) )
RETURN
    DIVIDE ( _CURRENTVALUE, _TOTAL )
Difference = [M_Store A of inventory %] - [M_Store B of inventory %]

Result is as below.

RicoZhou_1-1674198084946.png

RicoZhou_2-1674198092927.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @dpeterson99 ,

 

According to your statement, I think your table should look like as below.

RicoZhou_0-1674198035122.png

M_Store A of inventory % = 
VAR _CURRENTVALUE =
    CALCULATE ( SUM ( 'Table'[Store A of inventory %] ) )
VAR _TOTAL =
    CALCULATE ( SUM ( 'Table'[Store A of inventory %] ), ALLSELECTED ( 'Table' ) )
RETURN
    DIVIDE ( _CURRENTVALUE, _TOTAL )
M_Store B of inventory % = 
VAR _CURRENTVALUE =
    CALCULATE ( SUM ( 'Table'[Store B of inventory %] ) )
VAR _TOTAL =
    CALCULATE ( SUM ( 'Table'[Store B of inventory %] ), ALLSELECTED ( 'Table' ) )
RETURN
    DIVIDE ( _CURRENTVALUE, _TOTAL )
Difference = [M_Store A of inventory %] - [M_Store B of inventory %]

Result is as below.

RicoZhou_1-1674198084946.png

RicoZhou_2-1674198092927.png

 

Best Regards,
Rico Zhou

 

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

This is exactly what I was looking for! Thanks so much!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors