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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

List.Generate doesn't handle errors correctly

List.Generate(()=> 1, each not _[HasError], each try "1" - 1)

generates error, but as far as I understand it shouldn't, because I handle error in "next" function.

 

Is such a behavior of List.Generate a bug?

Status: New
Comments
v-yulgu-msft
Microsoft Employee

Hi @aminakov ,

 

When using "each not _[HasError]" as condition function in List.Generate, it violates the syntax, casuing error "cannot apply field access to the type Number". 

 

To handle the syntax error with List.Generate, you should use "Try" outside this function, rather than using "Try" inside it.

try List.Generate(()=> 1, each not _[HasError], each _ - 1)

Best regards,

Yuliana Gu

aminakov
Frequent Visitor

It was my mistake while I created the expression above - sorry for that. Actually it should be

List.Generate(()=> try 1, each not [HasError], each try "1" - 1). And it turned out that it works (so handles the try clause correctly).

But my problem is that I have much more complex situation, which uses List.Generate with try clause inside.

In the initial post I just tried to reproduce the List.Generate + try error of my complex code with simpe example. But unfortunately in such simple example the error is not reproductable. At the same time posting here the whole code is unreasonable (it's 53 interdependent queries).

 

BUT I  still would like to get some clue to understand my porblem, so the question is - what is your logic behind your recommendation not use "try" inside List.Generate? Could you please explain it a little bit, why we should not use try inside List.Generate?