Forum Discussion

ChemEnger's avatar
ChemEnger
Advocate V
5 years ago

Dynamic column selection refresh fails

I am extracting data from Excel workbooks where I have one table (I call it a Shape table) that includes an option (Yes/No) as to whether to include a column (Parameter) from another table (Data table) in a Power BI report.

I have a function (fnSPCColumns) that creates a list of the selected columns:

  • ColumnHeading is the name of the column in the Shape table that has the Parameter names
  • SPCColumn is the name of the column in the Shape table that has the 'Yes/No' selection
  • The output from this is a list named #"SPC Columns"
let
    fnSPCColumns = (Source, ColumnHeading as text, SPCColumn as text) =>
    let
        //Filter only those Parameters required for SPC
        #"Filtered Rows" = Table.SelectRows(Source, each (Record.Field(_, SPCColumn) = "Yes")),
        //Make a list of the Parameter Column
        Parameters = #"Filtered Rows"[Parameter]
    in
       Parameters
in
    fnSPCColumns

Then, I simply keep only the columns on this list:

#"SPC Columns" = fnSPCColumns(#"Shape Table", "Column Heading", "SPC")
#"Removed Other Columns" = Table.SelectColumns(#"Data Table",#"SPC Columns")

Everything works fine in Desktop and I can update a Yes to a No or vice versa and the desired column will appear or disappear as designed when I refresh the Data table query.

My problem is that if I change a Yes to a No value and don't do a Desktop refresh & Publish, I get a refresh error on the Power BI Service:

The xx column does not exist in the rowset

If I change a No to a Yes then I do not get an error and the 'new' column appears in the filtered Data table.

I have a feeling that some sort of query folding might be going on but I don't know how to avoid this error and have properly dynamic column selection from outside of Power BI (i.e. only have to change a Workbook cell).

If it is relevant, I take the data from the Data table (after column selection) and unpivot it into Attribute (Parameter) - Value pairs so that I can plot the data by choosing the Attribute in a Slicer.

Nowhere in the queries do I make explicit reference to any column names.

1 Reply

  • It's not query folding - the Power BI service is caching the meta data (including the column definitions for your dataset tables). I am not aware of any workaround. Well, maybe import all columns and then use DAX dynamic matrix visual measures instead.