Forum Discussion
Table.FirstN function doesn't seem to work properly for my case...
Welcome to the wonderful world of contexts. Yes, they exist in Power Query too. You are nesting one "each" inside another "each" and Power Query gets confused as to which context to use.
Mitigate by using inline functions or variables ("let ... in ..." ) much like you would do in DAX.
But I have as many "each" involved/nested in my original code mixing Last/FirstN that I have in the Last/SelectRows version, so why is the context "clearer" in the second case ? Do parenthesis would help regarding this context issue ? Is this a known issue that Microsoft is going to address soon ? This seems crazy.. I mean my code is not yet very complicated and I can't already be sure that it is behaving as expected ? How can I check/debug what context is being use ?
- lbendlin3 years agoSuper User
Break your query into smaller steps, and use inline function to check/debug. You can also use the Query diagnostics to validate the results of each step.
If you like to learn M I can highly recommend the primer here
Power Query M Primer (Part 21): Identifier Scope & Sections | Ben Gribaudo