Forum Discussion

JimJaggers's avatar
JimJaggers
Frequent Visitor
4 years ago
Solved

Conditionally creating queries

Is it possible to create a set of queries from a universe of possible queries based on what is available in a data source?   That is, say I have a spreadsheet that might contain tabs labled A, B, C...
  • BA_Pete's avatar
    4 years ago

    Hi JimJaggers ,

     

    You can't control the actual creation of queries per se, but you can have all the queries already in place and conditionally populate them using error handling i.e. you would set up the query with the source as 'Tab C', but then put an evaluation into the query that says "if the Tab C source returns an error (i.e. tab not present) then just run as blank" or similar.

     

    Generally accepted technique on Chris Webb's blog here, but make sure to read the comments as Ken Puls adds some crucial adjustments to the method:

    https://blog.crossjoin.co.uk/2014/09/18/handling-data-source-errors-in-power-query/ 

     

    Pete