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

"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
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.