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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Jay20024
Helper I
Helper I

Custom horizontal barchart

Hi,

For esthetic purpose, I like to create a horizontal stack barchart with values, that looks like a 100% stacked barchart.

So i need to calculate the most expensive category, substracting the result to other categories to fill the gap in the barchart.

Starting with this kind of dataset.

DateCategoryCost
2025-01-01Compute

100

2025-01-01Storage50
2025-01-01Network10
2025-02-01Compute150
2025-02-01Storage60
2025-02-01Network20
2025-03-01Compute200
2025-03-01Storage70
2025-03-01Network30

 

Got a pivot table like this, I'd like to calculate the gap column through a dax measure.

Category[TotalCost]GAP to be calculated
Compute450450-450 = 0
Storage180450-180 = 270
Network60450 - 60 = 390

So I can built a horizontal barchart that looks like a 100%

Gap.PNG

 

 

 

 

 

 

 

 

 

 

I'm struggling to calculate this gap column, any clue ?

I thank you in advance folks.

 

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@Jay20024 Create a new measure to calculate the total cost for each category.
Create another measure to calculate the GAP.

 

TotalCost = SUM('YourTable'[Cost])

MaxCost = CALCULATE(MAXX(ALL('YourTable'[Category]), [TotalCost]))

GAP = [MaxCost] - [TotalCost]

 

Add a stacked bar chart to your report.
Drag the Category field to the Axis.
Drag the TotalCost measure to the Values.
Drag the GAP measure to the Values.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

5 REPLIES 5
bhanu_gautam
Super User
Super User

@Jay20024 Create a new measure to calculate the total cost for each category.
Create another measure to calculate the GAP.

 

TotalCost = SUM('YourTable'[Cost])

MaxCost = CALCULATE(MAXX(ALL('YourTable'[Category]), [TotalCost]))

GAP = [MaxCost] - [TotalCost]

 

Add a stacked bar chart to your report.
Drag the Category field to the Axis.
Drag the TotalCost measure to the Values.
Drag the GAP measure to the Values.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Works like a charm ! Many thanks @bhanu_gautam  ! You rock, and you allowed me to improve my understanding of Dax !

Also a nice trick to improve UI

Cookistador
Super User
Super User

Hello @Jay20024 

 

This measure should return what you need

 

GAP =
VAR MaxCost = CALCULATE(MAX('Table'[TotalCost]), ALL('Table'))
RETURN
MaxCost - SUM('Table'[TotalCost])
 
Cookistador_0-1743508638420.png

 

If it is not what you are trying to achieve, let me know 🙂

Another way to do it, Many thanks for this feedback

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.