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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
cn4422
Helper IV
Helper IV

"Contains" in Dax measure - workaround wanted

Hi guys,

 

I'm using the following DAX measure:

Sum Spend =
CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
'FB_GA_GA4_This Year'[account_name]="AC01" && 'FB_GA_GA4_This Year'[campaign]="[AT]-Lead-Ads-2024")
 
So I'm filtering by Account Name and Campaign Name.
The thing is, I have more campaigns, all starting with [AT]... and I would like to put something like "Contains [AT]", which doesn't work. Also, in the future there might be more campaigns added, so it needs to be automatic.
 
Do you know of any good workaround for this problem?
 
Thx in advance! 😊
 
 
2 ACCEPTED SOLUTIONS

Sum Spend FB AT Test Filter =
CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
'FB_GA_GA4_This Year'[account_name] && SEARCH("[AT]"'FB_GA_GA4_This Year'[campaign]10)>0)

View solution in original post

What is 'FB_GA_GA4_This Year'[account_name]  supposed to achieve in that formula?

 

CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
SEARCH("[AT]"'FB_GA_GA4_This Year'[campaign]10)>0) ||
SEARCH("[DE]", 'FB_GA_GA4_This Year'[campaign], 1, 0)>0)
)

View solution in original post

12 REPLIES 12
lbendlin
Super User
Super User

You can use FIND/SEARCH or LEFT  for that

 

Text functions (DAX) - DAX | Microsoft Learn

Thanks for your reply.

 

I tried LEFT, but couldn't mange to get it working.

 

Then I tried the following with SEARCH:

Sum Spend FB AT Test Filter =
CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
'FB_GA_GA4_This Year'[account_name] && SEARCH("[AT]", 'FB_GA_GA4_This Year'[campaign], 1, 0))

However, I get the following error message:
Cannot convert value '02 GA4' of type Text to type True/False.
 
Any idea about that?
 
 

Sum Spend FB AT Test Filter =
CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
'FB_GA_GA4_This Year'[account_name] && SEARCH("[AT]"'FB_GA_GA4_This Year'[campaign]10)>0)

Hi,

one more question regarding this issue.

Is it possible to include an "or"-condition for the SEARCH("[AT"]... - something like:
SEARCH("[AT]" || "[DE]",

Yes, run two searches and OR the results.

Like this?
 
CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
'FB_GA_GA4_This Year'[account_name] && SEARCH("[AT]"'FB_GA_GA4_This Year'[campaign]10)>0) ||
'FB_GA_GA4_This Year'[account_name] && SEARCH("[DE]", 'FB_GA_GA4_This Year'[campaign], 1, 0)>0)
 
 

@lbendlin Could you perhaps have one more look at this issue?

 

Is it possible to include an "or"-condition for the SEARCH("[AT"]

 

You suggested:

Yes, run two searches and OR the results.

 

I tried this but it didn't work:

 

CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
'FB_GA_GA4_This Year'[account_name] && SEARCH("[AT]"'FB_GA_GA4_This Year'[campaign]10)>0) ||
'FB_GA_GA4_This Year'[account_name] && SEARCH("[DE]", 'FB_GA_GA4_This Year'[campaign], 1, 0)>0)

 

Thank you!

 

 

What is 'FB_GA_GA4_This Year'[account_name]  supposed to achieve in that formula?

 

CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
SEARCH("[AT]"'FB_GA_GA4_This Year'[campaign]10)>0) ||
SEARCH("[DE]", 'FB_GA_GA4_This Year'[campaign], 1, 0)>0)
)

@lbendlin Ah thank you very much.

 


@lbendlin wrote:

What is 'FB_GA_GA4_This Year'[account_name]  supposed to achieve in that formula?

 
 

Actually, the "Test" is missing...

 

Sum Spend FB AT Test Contains OR =
CALCULATE(SUM('FB_GA_GA4_This Year'[spend]),
'FB_GA_GA4_This Year'[account_name]="Test" && SEARCH("[AT]", 'FB_GA_GA4_This Year'[campaign],1,0) ||
SEARCH("[DE]", 'FB_GA_GA4_This Year'[campaign],1,0))

 

 

 

Hm, unfortunately the same error message keeps appearing... 🤔

Do you have any other suggestions? 

What's 'FB_GA_GA4_This Year'[account_name]  supposed to do?

Ahh, my bad, it worked, I just had a typo in it.

Thank you so much, made my day! 🤗

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.