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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Dynamic Sum for different column based on each category

Hello everyone,

i have a table that has the following columns:
category,
amount 1,
amount 2,
amount 3

in the category column, i have 4 categories lets say from A to D

i added a slicer for categories and i need to show the sum of amount

for Category A and B, I need to use amount 1
for Category C, I need to use amount 2
For Category D, I need to use amount 3

i tried using switch but if i select all categories, the value will be blank, if i select any 2 or more , i get blank , 

how can i make it sum based on each selection? so lets say i selected A and C, i need the sumx of Total amount for A + Total Amount for C

Best Regards

1 ACCEPTED SOLUTION
vicky_
Super User
Super User

So I created a measure for each sum amount (i.e Sum Amt 1 = SUM(Table[Amt 1])... etc) for each of the columns. 
Then i created this measure: 

Sum Amount = 
var _a = SUMMARIZECOLUMNS('Table'[Category])
return SUMX( _a, 
    SWITCH([Category], 
    "A", [Sum Amt 1],
    "B", [Sum Amt 1],
    "C", [Sum Amt 2],
    "D", [Sum Amt 3],
    0
    )
)

which gives the following result:

vicky__0-1719874270912.png

Hope this helps

View solution in original post

1 REPLY 1
vicky_
Super User
Super User

So I created a measure for each sum amount (i.e Sum Amt 1 = SUM(Table[Amt 1])... etc) for each of the columns. 
Then i created this measure: 

Sum Amount = 
var _a = SUMMARIZECOLUMNS('Table'[Category])
return SUMX( _a, 
    SWITCH([Category], 
    "A", [Sum Amt 1],
    "B", [Sum Amt 1],
    "C", [Sum Amt 2],
    "D", [Sum Amt 3],
    0
    )
)

which gives the following result:

vicky__0-1719874270912.png

Hope this helps

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.