Forum Discussion

TLGemp's avatar
TLGemp
New Member
2 years ago
Solved

Use List entry in Table.SelectRows function

Hello everybody.

 

I have a problem in using a List as argument for a column/record in the function Table.SelectRows.

 

From my source I got TABLE where one COLUMN, eg. Column3, contains all necessary information. The challenge is that the column I am looking for is not always Column3. It can be also Column4 or Column5. I managed to find a way that I got back the correct column name in a LIST. Now I want to use this LIST entry in the Table.SelectRows function to get rid of all other unwanted stuff.  But this do not want to work.

 

 

= Table.SelectRows(Source, each ([Referenz by using the LIST] = "Value for Filtering"))

 

 

So, what will be the step to go from e.g. {Column3} to the Source[Column3] referenz.

Thanks.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi TLGemp,

    Here is query table code that I used to transform table structure based on 'transpose table' and 'remove blank row' functions to output expected table structure without specific column names as conditions, you can try it if helps:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtKBoVgdLLyU1GJDiEhZYo4hkqgRXNQISdQYLmqsFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
        #"Removed Blank Rows" = Table.SelectRows(Source, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
        #"Transposed Table" = Table.Transpose(#"Removed Blank Rows"),
        #"Removed Blank Rows1" = Table.SelectRows(#"Transposed Table", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
        #"Promoted Headers" = Table.PromoteHeaders(#"Removed Blank Rows1", [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"des1", type text}, {"des2", type text}, {"des3", type text}})
    in
        #"Changed Type"

    Regards,

    Xiaoxin Sheng

3 Replies

  •  

    Source value - the column of des1,des2,des3 can vary and is not always the same

    nullnullnullnull
    nullnullnullnull
    nulldes1nullval1
    nulldes2nullval2
    nulldes3nullval3

     

    Result

    des1des2des3
    val1val2val3

     

     

    let
        Quelle = Excel.CurrentWorkbook(){[Name="Tabelle4"]}[Content],
        #"Geänderter Typ" = Table.TransformColumnTypes(Quelle,{{"Column1", type any}, {"Column2", type text}, {"Column3", type any}, {"Column4", type text}}),
        #"Tiefer gestufte Header" = Table.DemoteHeaders(#"Geänderter Typ"),
        #"Transponierte Tabelle" = Table.Transpose(#"Tiefer gestufte Header"),
        #"Gefilterte Zeilen" = Table.SelectRows(#"Transponierte Tabelle", each ([Column4] = "Des1")),
        Column1 = #"Gefilterte Zeilen"[Column1],
        Benutzerdefiniert1 = Table.SelectRows(Quelle, each ([Column2] <> null))
    in
        Benutzerdefiniert1

     

     

     

    In the line Benutzerdefiniert1 I would like to use the list Column1 from the line above instead of the static [colum2]. This should make the code more dynamic.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi TLGemp,

      Here is query table code that I used to transform table structure based on 'transpose table' and 'remove blank row' functions to output expected table structure without specific column names as conditions, you can try it if helps:

      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtKBoVgdLLyU1GJDiEhZYo4hkqgRXNQISdQYLmqsFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
          #"Removed Blank Rows" = Table.SelectRows(Source, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
          #"Transposed Table" = Table.Transpose(#"Removed Blank Rows"),
          #"Removed Blank Rows1" = Table.SelectRows(#"Transposed Table", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
          #"Promoted Headers" = Table.PromoteHeaders(#"Removed Blank Rows1", [PromoteAllScalars=true]),
          #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"des1", type text}, {"des2", type text}, {"des3", type text}})
      in
          #"Changed Type"

      Regards,

      Xiaoxin Sheng