Forum Discussion

vfx661's avatar
vfx661
Advocate I
1 year ago
Solved

Building WHERE X IN (1, 2, 3) clause with native query using dynamic parameters in power bi

I'm using a dyamically created list, e.g. {1, 2, 3} to build a query with a WHERE...IN clause so it only brings in data with column X = 1, 2, or 3 from snowflake SELECT * FROM my_table WHERE X IN...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Buffering a table brings a whole table into memory, which is a huge waste of resources, especially if all you need are the unique values in a column to use in your WHERE clause. Buffering a list allows your query to use the list in a WHERE [SQLColumn] IN clause.  So in your case, use List.Buffer by wrapping it around your Text.Replace function. This should be its own query so that the result is just the unique valued, buffered list. 

    In fact, if you make a uniqe list as its own query, and use it in

     

    Table.SelectRows(PriorStepOrTableName, each List.Contains(List.Buffer(ListName), [ColumnNameToFilter]))

     

    then you don't have to bother with writing the native query, because a buffered list in List.Contains for Table.SelectRows folds to the SQL source.

     

    --Nate