# Why does the following Expression.Evaluate scenario work?

• ### Question

• Here's an expression:

List.First(List.Select({{"<=10000", "Up To \$10,000"}}, each Expression.Evaluate(Number.ToText(10000) & _{0}))){1}

The expression returns "Up to \$10,000"

I'm wondering why Expression.Evaluate works, even though I have not specified an environment record.

Wednesday, November 29, 2017 9:53 PM

• The only part that is actually evaluated, is "10000<=10000", which contains no function, so no environment record required.

• Marked as answer by Thursday, November 30, 2017 2:50 PM
Thursday, November 30, 2017 8:08 AM

### All replies

• The only part that is actually evaluated, is "10000<=10000", which contains no function, so no environment record required.

• Marked as answer by Thursday, November 30, 2017 2:50 PM
Thursday, November 30, 2017 8:08 AM
• Hey Marcel,

have you hacked the M-engine? :-)

Seriously: Where do you get this knowledge?

Imke Feldmann - MVP Data Platform (PowerBI) - http://www.TheBIccountant.com

Thursday, November 30, 2017 9:52 AM
• Hi Imke,

No, just applied my personal logic.

Actually I meant, the only part that is evaluated by Expression.Evaluate.

So the part Number.ToText(10000) & _{0} is first evaluated (by the M-engine) to "10000<=10000", next this expression is evaluated by Expression.Evaluate.

Thursday, November 30, 2017 10:11 AM
• So true! It would have become obvious, if one would have piped the expression ;-)

Function.Pipe(	10000,
{
{Number.ToText},
{(number)=> List.Select({{"<= 10000", "Up To 10,000"}}, (list) => Expression.Evaluate(number & list{0}))},
{List.First},
{each _{1}}
)

With Function.Pipe as:

(x as any, operations) =>
List.Accumulate(operations,
x,
(state, current) => Function.Invoke(current{0}, {state}&List.Skip(current))
)

Imke Feldmann - MVP Data Platform (PowerBI) - http://www.TheBIccountant.com

Thursday, November 30, 2017 10:59 AM
• The only part that is actually evaluated, is "10000<=10000", which contains no function, so no environment record required.

Thanks, Marcel. I was quite tired when I posted the question, and couldn't think through the logic. I was so fixated on the function being in the Expression.Evaluate expression that I completely overlooked the fact that Number.ToText was not in quotes, hence would be evaluated normally.

Imke, I think that you have over-analyzed the issue. :)

Thursday, November 30, 2017 2:58 PM