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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Measure to SUM if column contains specific text or another column contains specific text

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

2 ACCEPTED SOLUTIONS
V-pazhen-msft
Community Support
Community Support

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

View solution in original post

Anonymous
Not applicable

Hi again @V-pazhen-msft ,

 

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 🙂

 

GR1_FB_CompliantSpendTEST = CALCULATE (

SUM ( 'FBGRReportData'[Amount Spent (DKK)] ),

FILTER (

'FBGRReportData',

('FBGRReportData'[Publisher platform]) = "Automatic placement"

&& ('FBGRReportData'[GR1]) = "CBO"
))

View solution in original post

4 REPLIES 4
V-pazhen-msft
Community Support
Community Support

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

Anonymous
Not applicable

Hi again @V-pazhen-msft ,

 

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 🙂

 

GR1_FB_CompliantSpendTEST = CALCULATE (

SUM ( 'FBGRReportData'[Amount Spent (DKK)] ),

FILTER (

'FBGRReportData',

('FBGRReportData'[Publisher platform]) = "Automatic placement"

&& ('FBGRReportData'[GR1]) = "CBO"
))
Anonymous
Not applicable

Hi @V-pazhen-msft , 

 

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

amitchandak
Super User
Super User

Share the formula you are using as of now.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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