Forum Discussion

Stuquan's avatar
Stuquan
Frequent Visitor
3 years ago
Solved

Dynamic column changes handler

Hi all,

 

I have a specific problem around columns appearing/disppearing as my data refreshes daily. The source is from an API that pulls through all data for that day (I am unable to see what it will pull for that day until it has done so), somedays I might have 67 columns, the next 88 and vice versa. The error I get when I try to refresh in Power BI Service is that 'column 'X' does not exist in the rowset' and therefore it cannot refresh.

 

I am wondering if anyone knows a way of dynamically handling column changes e.g. being added/removed say in the advanced editor? I have tried to create a null table with known columns that are creating errors, but each day I get a new one so this is a very static approach and extremely manual. 

 

Many thanks.

4 Replies

  • Stuquan,

     

    You can use the following M expression to refer to columns by position (0 is the first column):

     

    Table.ColumnNames(PreviousStep){0}

     

    One approach would be to get a column count and loop through each column, incrementing the number in curly braces. Example: iteration 1: {0}, iteration 2: {1}, until you reach the end.