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

DAX measure: string search/find/contains with conditions

Hi pros,

I have a visual matrix like this:

C_DAYC_Type
13-Mar-20Actual
13-Mar-20No data
14-Mar-20Forecasted
14-Mar-20No data
14-Mar-20No data

I am trying to prepare a measure that can: If a C_DAY contains "Actual", then returns "true" to all rows of this C_DAY.

My failed trial: 

 

 

 

CAT = contains(filter(table,table[C_DAY]=table[C_DAY]),table[C_TYPE],"Actual")

 

 

 

 

C_DAYC_TypeCATExpected
13-Mar-20Actual

true

true

13-Mar-20No datafalsetrue
14-Mar-20Forecastedfalsefalse
14-Mar-20No datafalsefalse
14-Mar-20No datafalsefalse

Anyone, please help. Thank you.

7 REPLIES 7
amitchandak
Super User
Super User

@navafolk , Try a new measure like

if ( countx(Summarize(Table, Table[C_DAY], "_1",countx(filter(Table,Table[C_Type]="Actual"),C_DAY)),[C_DAY])>=1, "True","False")

AlB
Super User
Super User

Hi @navafolk 

 

Measure =
"Actual" IN CALCULATETABLE ( DISTINCT ( Table1[C_Type] ), ALL ( Table1[C_Type] ) )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs

Cheers 

SU18_powerbi_badge

Hi @AlB ,

It works perfectly, but it is quite hard for me to understand how it works. May you explain please?

Thank you again.

Hi @navafolk 

In every row of you table visual (except the Total) both C_Day and C_Type are being filtered. That's your filter context. You want to see all the C_Types for that specific date, so you need to clear the filter on C_Type but keep the one for C_day. That is what we do with

  CALCULATETABLE ( DISTINCT ( Table1[C_Type] ), ALL ( Table1[C_Type] ) )

which yields a one-column table with all the values of C_Type for the date in the current row.

Once we have that, we just need to check if "Actual" is one of those values. That can be done with the IN operator

"Actual" IN CALCULATETABLE ( DISTINCT ( Table1[C_Type] ), ALL ( Table1[C_Type] ) )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs

Cheers 

SU18_powerbi_badge

It is clear.

Big thanks @AlB 

Mariusz
Community Champion
Community Champion

Hi @navafolk 

 

Try this

Measure = 
CALCULATE(
    CONTAINS( 'Table', 'Table'[C_Type], "Actual" ),
    ALL( 'Table' ),
    VALUES( 'Table'[C_DAY] )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn


 

Thank you @Mariusz@AlB 

They all work like a charm. Big thanks.

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.