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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

How does Power Query evaluate expressions?

PSB piece of PQ code 

let
MyList = { 5, 10, 15, 20 },
Index = -1,
Found = (Index = List.PositionOf(MyList, 15)) <> -1
in
[Found in Array = Found, Array Location = Index]

 

This results in the following output

[TRUE, -1]

I am trying to wrap my head around how Found can be TRUE and still Index is -1. 

4 REPLIES 4
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

This might be useful as well.

https://docs.microsoft.com/en-us/powerquery-m/evaluation-model

 

Best Regards,
Mariusz

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

 

Anonymous
Not applicable

Actually I want the ability to be able to get the index of an element in a list (say list A) in 1 condition and use the returned index to access a diferent list (list B) all within an each statement. Without repeating the List.PositionOf in the second condition again, it does not seem possible. 

Just use List.Transform e.g.

 

= each List.Transform([MyListColumn], (elm) => [MyOtherListColumn]{elm})

 

The thing to note is that "each" is just shorthand for "(_) =>" and "_" is the default variable, so that where "[Column]" is, it just is shorthand for "_[Column]"

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

The original index was not overridden because it's been changed only within Found, so technically you referred to the original state within your output.

 

The below will make more sense

 

let
    MyList = { 5, 10, 15, 20 },
    Index = List.PositionOf( MyList, 15 ),
    Found = Index <> -1
in
    [Found in Array = Found, Array Location = Index]

 

 

Best Regards,
Mariusz

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

 

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.