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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mh20221111
Helper II
Helper II

Apply rule table of multiple string conditions to Data table (issues with List.Contains)

Hi all,

I have two tables in Power Query:


Rules: columns Seq (unique number) and Condition (a string that contains a logical M expression).
Data: the dataset I want to classify.


There are multiple rows in Rules. I want to evaluate these conditions against each row in Data, and add the matching Seq value as a new column in Data. If multiple conditions match, picking one value (e.g., the first, minimum, or maximum Seq`) is fine.

I managed to make this work when the conditions only use AND, OR, =, <>, etc. But it breaks when a condition includes List.Contains.

What is the best way to evaluate these string conditions (including List.Contains) against each row of Data and return a single Seq per row?

Rules
Rules.png

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

cond.jpg

 

 

 

let
    seq_no = List.Buffer(conditions[Sequence No]),
    cond = List.Buffer(List.Transform(conditions[Condition], (x) => Expression.Evaluate("each " & x, #shared))),
    cond_column = Table.AddColumn(
        data, 
        "cond",
        (x) => List.Transform(
            List.PositionOf(
                List.Transform(
                    cond, 
                    (w) => w(x)
                ), 
                true,
                Occurrence.All
            ), 
            (i) => seq_no{i}
        )
    )
in
    cond_column

rres.jpg

View solution in original post

5 REPLIES 5
Rufyda
Impactful Individual
Impactful Individual

I'm glad you found a solution! We're here in the community to support each other.

Regards,
Rufyda Rahma | Microsoft MIE

AlienSx
Super User
Super User

cond.jpg

 

 

 

let
    seq_no = List.Buffer(conditions[Sequence No]),
    cond = List.Buffer(List.Transform(conditions[Condition], (x) => Expression.Evaluate("each " & x, #shared))),
    cond_column = Table.AddColumn(
        data, 
        "cond",
        (x) => List.Transform(
            List.PositionOf(
                List.Transform(
                    cond, 
                    (w) => w(x)
                ), 
                true,
                Occurrence.All
            ), 
            (i) => seq_no{i}
        )
    )
in
    cond_column

rres.jpg

Hi @AlienSx ,

I have an additional question. When I tried the described method on Desktop, it worked fine. Is it possible to perform the same process using Power BI Dataflows?
I understand that dynamic evaluation, such as using Expression.Evaluate or #shared, cannot be used in Dataflows.

Regards,
Miho

Hello, @mh20221111 I have no idea, sorry

Hi @AlienSx ,

It worked perfectly! Thank you so much for your help.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.