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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bob57
Helper IV
Helper IV

Eliminate "hard coding".

Example table:

Example.png

I am producing a pie chart to show the relationship of total payments for each category. I have four measures (one for each category).

Cat A = CALCULATE( SUM(  'Table'[Payment]  ),' Table'[Category] = "Cat A" )

Cat B = CALCULATE( SUM(  'Table'[Payment]  ),' Table'[Category] = "Cat B" )

Cat C = CALCULATE( SUM(  'Table'[Payment]  ),' Table'[Category] = "Cat C" )

Cat D = CALCULATE( SUM(  'Table'[Payment]  ),' Table'[Category] = "Cat D" )

Question 1: Is there a DAX formula that would eliminate the need to hard code the category name into the formula?

Question 2: I would like the formula to allow for dynamic addition of new categories.

Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Can you share a sample file?

 

The basic solution would be to just have a simple sum formula:

Payment Amounts = 
CALCULATE(
    SUM(Table[Payment])
)

Then use the category column in the legend section of the pie chart. That should give you the pie chat that you're looking for.  

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Can you share a sample file?

 

The basic solution would be to just have a simple sum formula:

Payment Amounts = 
CALCULATE(
    SUM(Table[Payment])
)

Then use the category column in the legend section of the pie chart. That should give you the pie chat that you're looking for.  

Thank you! That does solve my problem. I now understand that there is no need to worry about the addition of new categories. I'm new to DAX and Power BI so sometimes the simple things are not so simple.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.