The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi all,
I'm trying to find a way to SUM a column if another "column A" in the same table has a specific value OR "column B" in the same table has a specific value.
My workaround was to CONCATENATE column A and column B and use the value in the concatenated column in my SUM measure. However, and correct me if I'm wrong, I don't think creating custom columns is optimal for performance when working with large data sets.
Hope the above describes the question well. Thanks for looking into this!
Kind regards,
Ivan
Solved! Go to Solution.
Hi, @Anonymous
If I understand you correctly. You are able to do that with CONTAINS function:
Measure =
CALCULATE (
SUM ( 'Table'[Column] ),
FILTER (
'Table',
CONTAINS ( 'Table', 'Table'[ColumnA], "Text1" )
|| CONTAINS ( 'Table', 'Table'[ColumnB], "Text2" )
)
)
Paul
Best
Hi again @Anonymous ,
Just found the solution. What worked for me is the below. I had to get rid of the "CONTAINS" which actually works better for me as I have exact values. Have to describe my requests better in future forum posts 🙂 .
Hi, @Anonymous
If I understand you correctly. You are able to do that with CONTAINS function:
Measure =
CALCULATE (
SUM ( 'Table'[Column] ),
FILTER (
'Table',
CONTAINS ( 'Table', 'Table'[ColumnA], "Text1" )
|| CONTAINS ( 'Table', 'Table'[ColumnB], "Text2" )
)
)
Paul
Best
Hi again @Anonymous ,
Just found the solution. What worked for me is the below. I had to get rid of the "CONTAINS" which actually works better for me as I have exact values. Have to describe my requests better in future forum posts 🙂 .
Hi @Anonymous ,
Thanks for sharing the solution, what if I want the same calculation to happen when two columns contain a specific value simultaneously? E.g. calculate only when column 1 has "x" AND column 2 has "y"? I tried replacing || with && but haven't achieved the desired result.
Appreciate your help.
Ivan