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
AndreLuiz
Frequent Visitor

Help in Query Editor with the second argument of Table.FirstN using error criteria.

Hello,
I would like to use the second argument of Table.FirstN with a condition in which the function stop evaluating when an error is found.
I've tried Table.FirstN(Table, each [Column1] ; [Column1] <> "Error") but it does't work..

Any help will be appreciated!
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

The 2nd parameter of Table.FirstN() needs to be an expression that evaluates to a whole number.

 

BUT, you can do something like this.

PreviousStep = //some M code here,  
Table_with_FirstN = Table.FirstN(PreviousStep, 20),
Conditional = //some M code here that says whether or not to apply the FirstN transformation.
FinalTable = if Conditional = true then Table_with_FirstN else PreviousStep 
in

FinalTable 

 

View solution in original post

Thank you for the answer Chris!

What I liked in your anwer is the simplicity and brevity in the M code.

 

In following the brevity approach to the problem I've found that the 2nd parameter of Table.FirstN() can be any condition which evaluates to True/False. So, by trying to catch the error condition, I've came to the following solution:

 

//Using the "try ... otherwise" clause in M
//A cell is equal to itself unless it contains an Error

SingleStep = Table.FirstN(Table, each try [Column1] = [Column1] otherwise null <> null)
// ( try..otherwise error test )

 

Greetings,

André

 

 

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

The 2nd parameter of Table.FirstN() needs to be an expression that evaluates to a whole number.

 

BUT, you can do something like this.

PreviousStep = //some M code here,  
Table_with_FirstN = Table.FirstN(PreviousStep, 20),
Conditional = //some M code here that says whether or not to apply the FirstN transformation.
FinalTable = if Conditional = true then Table_with_FirstN else PreviousStep 
in

FinalTable 

 

Thank you for the answer Chris!

What I liked in your anwer is the simplicity and brevity in the M code.

 

In following the brevity approach to the problem I've found that the 2nd parameter of Table.FirstN() can be any condition which evaluates to True/False. So, by trying to catch the error condition, I've came to the following solution:

 

//Using the "try ... otherwise" clause in M
//A cell is equal to itself unless it contains an Error

SingleStep = Table.FirstN(Table, each try [Column1] = [Column1] otherwise null <> null)
// ( try..otherwise error test )

 

Greetings,

André

 

 

 

 

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.