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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
EddP
Frequent Visitor

IF with multiple Contains

Similar to the below, I'm trying to make an IF statement with Contains but I am trying to count the times 2 (or more) affiliates appear in a customers click path together.

 

IF CONTAINS WITH MULTIPLE VALUES 

 

E.g.

Selection1= HUKD

Selection2= TCB

 

OrderIDPath_Taken
Order1Step1 -> Step2 -> HUKD -> TCB
Order2 Step1 -> Step2 -> HUKD -> TCB
Order3Step1 -> Step2 -> HUKD -> TCB
Order4HUKD-> Step2 -> HUKD -> Step4
Order5Step1 -> Step2 -> Step3 -> TCB

 

The count would equal 3 as they appear in the paths together 3 times.

 

Stringer Code:

StringerT4 =
CONVERT(SELECTEDVALUE(Steps_AffiliateOnly[taxonomy_4]),STRING)

 

Mutual counter Code:

Mutual = 

IF(
AND(
CONTAINS(Steps_AffiliateOnly, Steps_AffiliateOnly[path_taken],Steps_AffiliateOnly[StringerT4]),(
CONTAINS('Steps_AffiliateOnly_2','Steps_AffiliateOnly_2'[path_taken],'Steps_AffiliateOnly_2'[StringerT4_Second])))
,           COUNT(Steps_AffiliateOnly[order_id]))
 
 
Logically it makes sense to me, but the output is not what i'm expecting.
 
Thanks in advance for any help
1 ACCEPTED SOLUTION

@EddP 
Are you looking for something like this?

1.png2.png

FilterMeasure = 
COUNTROWS ( 
    FILTER ( 
        Orders,
        VAR String = Orders[Path_Taken]
        VAR Items = SUBSTITUTE ( String, " -> ", "|" )
        VAR Length = COALESCE ( PATHLENGTH ( Items ), 1 )
        VAR T = GENERATESERIES ( 1, Length, 1 )
        RETURN
            ISEMPTY ( 
                EXCEPT ( 
                    VALUES ( Stations[Station] ) ,
                    SELECTCOLUMNS ( T, "@Station", PATHITEM ( Items, [Value] ) )
                )
            )
    )
)

View solution in original post

6 REPLIES 6
tamerj1
Super User
Super User

Hi @EddP 

is the selection from a slicer? From which table/column?

EddP
Frequent Visitor

Hi @tamerj1

yes it's from a slicer, i use the stringer code to turn the selection into a string adn then use that string for the search.

Steps_affiliate_only and the affiliate_only_2 (duplicate or the original table) are the tables used. Path_taken is the column the contains is looking through 

@EddP 

I'm havinf a difficulty picturing the situation. Would you please share a screenshot of the source table?

EddP
Frequent Visitor

@tamerj1 

 

No problem, the below looks more readable than my original example.

 

EddP_0-1674725354980.png

So there are two tables that contain these columns and rows, they're copies of eachother, the original has more columns and the duplicate just has the necessary columns.. The taxonomy4 coloumn is the affiliate list. The path taken column is the start to finish journey taken by the user.

The tables aren't linked at all, the duplicate is only for the splicer list as it wouldn't work when they were selected from the same table. But that selection just gets converted into a string so not sure if that'll be an issue.

 

Then the contains goes over the path_taken columns in the original table. 

@EddP 
Are you looking for something like this?

1.png2.png

FilterMeasure = 
COUNTROWS ( 
    FILTER ( 
        Orders,
        VAR String = Orders[Path_Taken]
        VAR Items = SUBSTITUTE ( String, " -> ", "|" )
        VAR Length = COALESCE ( PATHLENGTH ( Items ), 1 )
        VAR T = GENERATESERIES ( 1, Length, 1 )
        RETURN
            ISEMPTY ( 
                EXCEPT ( 
                    VALUES ( Stations[Station] ) ,
                    SELECTCOLUMNS ( T, "@Station", PATHITEM ( Items, [Value] ) )
                )
            )
    )
)
EddP
Frequent Visitor

@tamerj1 

Works perfectly, thank you so much for your help!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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