Forum Discussion

AlexHeinze's avatar
AlexHeinze
Frequent Visitor
2 years ago
Solved

Switch datasource using IF statement in Power Query

I have a report with 2 datasources. One datasource gets the XML from a file (Source = Xml.Tables(File.Contents(.......): The second datasource gets a similar XML from an API (Source = Xml.Tab...
  • AlexHeinze's avatar
    AlexHeinze
    2 years ago

    I finally solved it by not referencing the existing sources, instead I put it all in the same place:

    let
        // Get data from API
        SourceAPI = Xml.Tables(Web.Contents(GatewayURL)),
        
        // Get data from file
        SourceFile = Xml.Tables(File.Contents(SavedScheduleXML)),
        
        // Select the sources based on the parameter value
        Source = if DataSource="API Broadcast" then SourceAPI else SourceFile,
    .......