Forum Discussion

xChillout's avatar
xChillout
Frequent Visitor
6 years ago
Solved

Dynamic filtering of multiple columns and different conditions with List.Generate()

I need to filter a table. The challenge for me is that the filter information (column names, number of columns, as well as filter values) can change. After doing some research I think List.Generate...
  • Jimmy801's avatar
    6 years ago

    Hello

    you can try my developed function "fxFilter" for comparing and give it some testing 😄

    please pay attention to the table structure needed by this function (Columns "Name" and "Value")

    (rRecord as record, filtertable as table) as logical =>
    //filtertable has to have two columns [Name] and [Value]
    //always an equal comparison is executed
    //Developed by Jimmy
    let
        
        RecordToTable = #table({"Name", "Value"}, List.Zip({Record.FieldNames(rRecord), Record.FieldValues(rRecord)})),
        AddColumnToFilterTable = Table.AddColumn
            (
                filtertable, 
                "Compare",
                try (add)=> Table.SelectRows
                    (
                        RecordToTable,
                        (select)=> select[Name]= add[Name]
                    )[Value]{0} = add[Value]
                    otherwise false
            ),
        CheckIfAllCompareIsTrue = try List.AllTrue(AddColumnToFilterTable[Compare]) otherwise false
    in
        CheckIfAllCompareIsTrue

     

    you can then applying like this

     

     Table.SelectRows(#"Changed Type", each fxFilter(_, FILTER))

     

    Have fun

     

    Jimmy