cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
malha Frequent Visitor
Frequent Visitor

Evaluate parameter text as M code

I can filter my data using the following code in the advanced editor:

 

#"Filtered Rows" = Table.SelectRows(#"Previous step", each true)

 

Of course, nothing will happen there. What I would like to do now is to create a parameter (let's call it ParamFilter) where I could store the actual filter definition:

 

"([Column1] > 5 and [Column2] < 2)" meta [IsParameterQuery=true, Type="Any", IsParameterQueryRequired=false]

 

Now I want use that parameter content to do the actual filtering. This here will throw an error:

 

#"Filtered Rows" = Table.SelectRows(#"Previous step", each ParamFilter)

 

Which was obvious because it would be interpreted like this, mind the quotation marks:

 

#"Filtered Rows" = Table.SelectRows(#"Previous step", each "([Column1] > 5 and [Column2] < 2)")


I actually wanted to achieve this:

 

#"Filtered Rows" = Table.SelectRows(#"Previous step", each ([Column1] > 5 and [Column2] < 2))

 

So, how can I manage that? Any ideas?

 

1 ACCEPTED SOLUTION

Accepted Solutions
malha Frequent Visitor
Frequent Visitor

Re: Evaluate parameter text as M code

Solved it myself after browsing the M reference again for anything related. There is the Expression.Evaluate() function. This will work:

 

#"Filtered Rows" = Table.SelectRows(#"Previous step", Expression.Evaluate(ParamFilter))

 

The each statement needs to go to the parameter value:

 

"each ([Column1] > 5 and [Column2] < 2)" meta [IsParameterQuery=true, Type="Any", IsParameterQueryRequired=false]

 

View solution in original post

1 REPLY 1
malha Frequent Visitor
Frequent Visitor

Re: Evaluate parameter text as M code

Solved it myself after browsing the M reference again for anything related. There is the Expression.Evaluate() function. This will work:

 

#"Filtered Rows" = Table.SelectRows(#"Previous step", Expression.Evaluate(ParamFilter))

 

The each statement needs to go to the parameter value:

 

"each ([Column1] > 5 and [Column2] < 2)" meta [IsParameterQuery=true, Type="Any", IsParameterQueryRequired=false]

 

View solution in original post

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors