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
alsm
Helper III
Helper III

Sum column A, B if column C has specific value else return sum column A

Hello,

My data looks like

IdCategorySensi1Sensi2
1A100-50
2B200-60
3A300-70
4B400-80
5B500

-90

 

I want to implement that is Category = A then return Sensi1 + Sensi2 else return Sensi1. How would I do that?

1 ACCEPTED SOLUTION
Martin_D
Super User
Super User

Hi @alsm ,

try

 

Conditional Sum = 
SUMX (
    VALUES ( 'Table'[Category] ),
    CALCULATE (
        SUM ( 'Table'[Sensi1] )
    ) +
    IF (
        'Table'[Category] = "A",
        CALCULATE (
            SUM ( 'Table'[Sensi2] )
        )
    )
)

 

 

github.pnglinkedin.png

View solution in original post

4 REPLIES 4
alsm
Helper III
Helper III

@Martin_D , thank you. It works.. though the first part

 VALUES ( 'Table'[Category] )

is non-intuitive . Its basically saying evaluate every line on the dashboard. Is it correct?

 

I tried and created another variant

total_sensi =
VAR sensi1 =
CALCULATE ( SUM ( Table[Sensi1] ) )
VAR sensi2 =
CALCULATE ( SUM ( Table[Sens2] ), FILTER ( Table, Table[Sensi2] = "A" ) )
VAR total_sensi = sensi1 + sensi2
RETURN
total_sensi

 

Answers are same in both cases, is there a way to say one solution is more optimal than other?

I was not 100% sure whether you want to use it as a measure or calculated column, so I wrote code that works for both. Actually, the same should be true for your solution. In a visual that shows values by Category both solution should perform about the same. With a large number of categories yours might be even faster in the grand total.

Thank you for your reply and showing me another way to do it....

 

FYI: I created a measure (not a column)

Martin_D
Super User
Super User

Hi @alsm ,

try

 

Conditional Sum = 
SUMX (
    VALUES ( 'Table'[Category] ),
    CALCULATE (
        SUM ( 'Table'[Sensi1] )
    ) +
    IF (
        'Table'[Category] = "A",
        CALCULATE (
            SUM ( 'Table'[Sensi2] )
        )
    )
)

 

 

github.pnglinkedin.png

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.