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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
TKray23
Regular Visitor

Need help to calculate the sum from different columns depending on the filter value

I Need help to calculate the sum from different columns depending on the filter value
I have two tables 
Table1 has a column Col V with different values: a,b,c,
Table 2 has many columns and rows. Some of the columns are used as flags and have values 1 and 0. Lets say Col1, Col2, Col3
 
Table1 ColV is used as a filter on the page
I need to be able to calculate the sum  of one of the Table2 Columns( Col1, Col2, Col3) depending on the value of the Table1 ColV
 
Lets say
 
Table1 ColV= a
Than SUM of Flags= Sum of Col1
 
If 
 
Table1 ColV= b
Than SUM of Flags=Sum of Col2
 
if
 
Table1 ColV= c
Than SUM of Flags=Sum of Col3
1 ACCEPTED SOLUTION
CoreyP
Solution Sage
Solution Sage

I think I understand now. Maybe a SWITCH function? Like..

Sum Of Flags = 
VAR A_flags = SUM( 'Table2'[Col1] )
VAR B_flags = SUM( 'Table2'[Col2] )
VAR C_flags = SUM( 'Table2'[Col3] )
VAR ColV_filter = MAX( 'Table1'[ColV] )

RETURN
SWITCH(
TRUE() , 
ColV_filter = "A" , A_flags ,
ColV_filter = "B" , B_flags ,
ColV_filter = "C" , C_flags ,
BLANK()
)

View solution in original post

4 REPLIES 4
CoreyP
Solution Sage
Solution Sage

I think I understand now. Maybe a SWITCH function? Like..

Sum Of Flags = 
VAR A_flags = SUM( 'Table2'[Col1] )
VAR B_flags = SUM( 'Table2'[Col2] )
VAR C_flags = SUM( 'Table2'[Col3] )
VAR ColV_filter = MAX( 'Table1'[ColV] )

RETURN
SWITCH(
TRUE() , 
ColV_filter = "A" , A_flags ,
ColV_filter = "B" , B_flags ,
ColV_filter = "C" , C_flags ,
BLANK()
)

Hi, Thank you for your assistance!

CoreyP
Solution Sage
Solution Sage

Is there a relationship between the two tables?

yes, many to many

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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