Power Query - Mcode to sort only if cell is not blank

HarveyH123

New Member
Joined
Feb 18, 2017
Messages
8
Hello,

I want to create a query that uses a paramater taken from my excel worksheet.

i have managed to do this with this code;

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Filtered Rows" = Table.SelectRows(Source, each ([StepTag] = GetValue("Filter")))
in
#"Filtered Rows"

However, i want the code to only filter if the cell (named *filter*) is not blank.

i.e. I dont want to filter at all if the cell in blank.

Hope this makes sense.

Thank you,
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
What is GetValue?

Is the StepTag field text?

If it is try this.

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Filtered Rows" = Table.SelectRows(Source, each (Text.Contains([Step_Tag],if GetValue("Filter")=null then "" else GetValue("Filter"))))
in
#"Filtered Rows"
 
Last edited:
Upvote 0
Hey Norie! 'sup fella?

you could also do like...

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each 
    let
        filterTarget = GetValue("Filter")
    in
        filterTarget = null or (Text.Contains([Step_Tag], filterTarget)))
in
    #"Filtered Rows"
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,672
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top