Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

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

  1. #1
    New Member
    Join Date
    Feb 2017
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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


    Power Query - Mcode to sort only if cell is not blank
    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,

  2. #2
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    73,711
    Post Thanks / Like
    Mentioned
    24 Post(s)
    Tagged
    0 Thread(s)

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

    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 by Norie; Jun 14th, 2018 at 10:43 AM.
    If posting code please use code tags.

  3. #3
    Board Regular
    Join Date
    Dec 2013
    Posts
    198
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •