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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
DryMouse555
Frequent Visitor

Add two or more columns with a condiotion

Hi,

 

I have the below data,

 

Column AColumn BColumn C
ABCMap$56
EFGCamera$89
IJKElectricity$789
   


I want to do Sum (Column C, where Column A =ABC and Column B =Map) + Sum (Column C, where Column A =EFG and Column B =Camera) + Sum (Column C, where Column A =IJK and Column B =Electricity)

Can you tell me how to do in Power BI dax?

 

Thanks

2 ACCEPTED SOLUTIONS
manvishah17
Responsive Resident
Responsive Resident

Hi @DryMouse555 ,
You can try out this DAX Measure,

 

TotalSum = 
SUMX(
    'YourTable',
    SWITCH (
        TRUE (),
        'YourTable'[Column A] = "ABC" && 'YourTable'[Column B] = "Map", 'YourTable'[Column C],
        'YourTable'[Column A] = "EFG" && 'YourTable'[Column B] = "Camera", 'YourTable'[Column C],
        'YourTable'[Column A] = "IJK" && 'YourTable'[Column B] = "Electricity", 'YourTable'[Column C],
        0  -- Default case, if none of the conditions match
    )
)

 

 or this one..

TotalSum = 
SUMX(
    FILTER(
        'YourTable',
        ('YourTable'[Column A] = "ABC" && 'YourTable'[Column B] = "Map") ||
        ('YourTable'[Column A] = "EFG" && 'YourTable'[Column B] = "Camera") ||
        ('YourTable'[Column A] = "IJK" && 'YourTable'[Column B] = "Electricity")
    ),
    'YourTable'[Column C]
)

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

ThxAlot
Super User
Super User

A straightforward way if you have no much knowledge of DAX,

Sum1 = 
CALCULATE(
    SUM( DATA[Column C] ),
    DATA[Column A] = "ABC" && DATA[Column B] = "Map"
        || DATA[Column A] = "EFG" && DATA[Column B] = "Camera"
        || DATA[Column A] = "IJK" && DATA[Column B] = "Electricity"
)

 

Another way in a more "DAX manner",

Sum2 = 
CALCULATE(
    SUM( DATA[Column C] ),
    TREATAS(
        { ( "ABC", "Map" ), ( "EFG", "Camera" ), ( "IJK", "Electricity" ) },
        DATA[Column A],
        DATA[Column B]
    )
)

ThxAlot_0-1718956621085.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

3 REPLIES 3
DryMouse555
Frequent Visitor

Thank you @ThxAlot && @manvishah17 

ThxAlot
Super User
Super User

A straightforward way if you have no much knowledge of DAX,

Sum1 = 
CALCULATE(
    SUM( DATA[Column C] ),
    DATA[Column A] = "ABC" && DATA[Column B] = "Map"
        || DATA[Column A] = "EFG" && DATA[Column B] = "Camera"
        || DATA[Column A] = "IJK" && DATA[Column B] = "Electricity"
)

 

Another way in a more "DAX manner",

Sum2 = 
CALCULATE(
    SUM( DATA[Column C] ),
    TREATAS(
        { ( "ABC", "Map" ), ( "EFG", "Camera" ), ( "IJK", "Electricity" ) },
        DATA[Column A],
        DATA[Column B]
    )
)

ThxAlot_0-1718956621085.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



manvishah17
Responsive Resident
Responsive Resident

Hi @DryMouse555 ,
You can try out this DAX Measure,

 

TotalSum = 
SUMX(
    'YourTable',
    SWITCH (
        TRUE (),
        'YourTable'[Column A] = "ABC" && 'YourTable'[Column B] = "Map", 'YourTable'[Column C],
        'YourTable'[Column A] = "EFG" && 'YourTable'[Column B] = "Camera", 'YourTable'[Column C],
        'YourTable'[Column A] = "IJK" && 'YourTable'[Column B] = "Electricity", 'YourTable'[Column C],
        0  -- Default case, if none of the conditions match
    )
)

 

 or this one..

TotalSum = 
SUMX(
    FILTER(
        'YourTable',
        ('YourTable'[Column A] = "ABC" && 'YourTable'[Column B] = "Map") ||
        ('YourTable'[Column A] = "EFG" && 'YourTable'[Column B] = "Camera") ||
        ('YourTable'[Column A] = "IJK" && 'YourTable'[Column B] = "Electricity")
    ),
    'YourTable'[Column C]
)

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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