• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Understand "true" in PQ

MBS

Member
Hi All,
below is the just one query step. It takes care, if user do not select the product and product field is empty or null then the output will get filtered with all the products. This is achieved by "true" after "else".
But I don't fully understand how this "true" executes the code for this particular case. Or what other construction may work in place of "true".

#"Filter Product" = Table.SelectRows( #"Filter Date",
each
if Parameters[Product]{0} <> null
then
[Product] = Parameters[Product]{0} (Parameter table is transposed)
else
true )

Thanks & regards,
 

Attachments

  • PQ_Ex.png
    PQ_Ex.png
    198.2 KB · Views: 0
each true = no filter set.

See it as nothing get's evaluated. To filter you'd use something like each [ColumnName] > 100 (some value), or [ColumnName] <> "SomeText".

Try to set a filter on column. Then in the UI reset the filter to show all. The formula of the UI is updated to "each true".
 
To elaborate a little, Table.SelectRows uses a function as the second argument that needs to return true or false for each row. If true, the row is included in the results; if false, it isn't.
So in the formula you posted, the function basically performs these steps:
Is Parameters[Product]{0} null or not?
If it isn't, then check each row to see if the [Product] field equals the selected product in the parameters table and return true/false accordingly.
If the parameter is null, then just return true for every row, so all rows are included in the results. As G said earlier, that's the equivalent of not filtering at all. Another way of writing that would be to only use Table.SelectRows if the parameter is not null and just return the previous step if it is null - e.g.

Code:
#"Filter Product" = if Parameters[Product]{0} <> null then
    Table.SelectRows( #"Filter Date", each [Product] = Parameters[Product]{0})
else
#"Filter Date"
 
Back
Top