Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Polution
New Member

Conditional Source in Power Query advanced editor / OR / Conditional Appended queries

Hi,

 

Introduction: I have 10 dynamic web queries that depend on the value of a cell. Once I quered the 10 queries, I append them them. Until here no problem, everything works. In theory those 10 web queries habe the same structure

https://finance.yahoo.com/quote/AAPL/history?period1=1608768000&period2=1664928000&interval=1wk&filt... ) , the dynamic part is the ticker symbol (i write it in an excel cell) and the variable part is the unix timestamps that vary according to cell values (preset by me) to download different intervals of prices.

 

The 10 queries together can scrape a maximum of 19 years of data (arbitrary decision), so, if a company has less than 19 years of data some of these queries will present the error (for example aapl doesn't present errors because has more than 20 years of price data, but visa presents errors because if less than 19 years of data

 

😞 Expression.Error: The column 'Date' of the table wasn't found.
Details:
Date

 

For me its fine because if there's no data in these periods its logical that it doesnt retreive any data. But the problem appears when the new appended query that i create is coded including all the queries (including those that rbing errrors), so it doesnt work anymore.

The potential solutions that i thought about it are 2:

 

-OPTION 1: Create all the possible sources and through an if statement, retreive and combine the ones that doesnt bring errors and has the largest number of rows using some kind of if when error...

 

let
Source = Table.Combine({#"Table 0", #"Table 0 (2)", #"Table 0 (3)", #"Table 0 (4)", #"Table 0 (5)", #"Table 0 (6)", #"Table 0 (7)", #"Table 0 (8)", #"Table 0 (9)", #"Table 0 (10)"})

Source2 = Table.Combine({#"Table 0", #"Table 0 (2)", #"Table 0 (3)", #"Table 0 (4)", #"Table 0 (5)", #"Table 0 (6)", #"Table 0 (7)", #"Table 0 (8)", #"Table 0 (9)"})

Source3 = Table.Combine({#"Table 0", #"Table 0 (2)", #"Table 0 (3)", #"Table 0 (4)", #"Table 0 (5)", #"Table 0 (6)", #"Table 0 (7)", #"Table 0 (8)"})

Source4 = Table.Combine({#"Table 0", #"Table 0 (2)", #"Table 0 (3)", #"Table 0 (4)", #"Table 0 (5)", #"Table 0 (6)", #"Table 0 (7)"})

Source5 = Table.Combine({#"Table 0", #"Table 0 (2)", #"Table 0 (3)", #"Table 0 (4)", #"Table 0 (5)", #"Table 0 (6)"})

 

... up until it only combines the first 2 tables...
in
Source  (Here is where the code with if statement is needed)

 

-OPTION 2: use some code to conditionally combine (append) those queries that don't bring error.

 

-OPTION 3: maybe someone has better alternative open to suggestions.

 

TY, I would upload the excel file but i haven't seen the option for uploading it... 

 

 

 

 

Appended code.pngExcel file.pngNot working query.pngWorking Query.png

1 REPLY 1
artemus
Microsoft Employee
Microsoft Employee

Looks like you will need to add a bunch of conditional checks. Example:

let
   Source = ...,
   HasDateColumn = Source[Date]? <> null,
   ...,
   SomeLaterStep = if HasDateColumn then <<Code for Date column existing>> else <<Code for no Date Column>>,
   ...
in
   LastStep

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.