IF statement in power query web contents import

97hills

New member
Joined
Aug 24, 2017
Messages
2
Reaction score
0
Points
0
Hi everyone

I'm really new to power query and have created some basic code to scrape a table from a website (mainly through the UI with a couple of tweaks in advanced editor). It's a really great tool, especially for people like me who don't really know how to code. However, because of the way that websites loads the table it sometimes returns blank. It's not a huge amount of data so refreshing until it is non-blank should be fine.

Code:
let

    Source = Function.InvokeAfter(
()=> Web.Page(Web.Contents("https://www.sportingindex.com/spread-betting/golf/ryder-cup/group_c.1ed2996f-9381-40e8-bef8-0f7ae460b2ec/ryder-cup-outright-markets")),
#duration(0,0,0,0)),
    Data0 = Source{0}[Data],
    #"Removed Columns" = Table.RemoveColumns(Data0,{"", "Column6", "Column7", "Current"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{Table.ColumnNames(Data0){0}, "SPIN"}})
in

    #"Renamed Columns"


When the data I want is not returned by the query the first row will be "No markets available". So can anyone help with IF the first row under the header in column 1 is "No markets available" THEN LOOP the data import until row 1 column 1 <> "No markets available".

It feels like it should be really simple to me but I just can't find much online to help me out with it. I thought Function.InvokeAfter may help but no joy (is why it's set at zero above)

Thanks in advance for any help
 
Just remove those rows, there is a remove rows option on the Home tab.
 
Just remove those rows, there is a remove rows option on the Home tab.

Thanks Bob. However, the issue is not having those rows. The issue is when those rows have loaded, the rest of the table has not loaded fully. So when you load up the url for a brief second the table shows "no markets available" before the full data appears. I suspect when power query is scraping this table it just exports whatever it finds on the page first. Unfortunately this seems to randomly switch between the data I want and "no markets available" in the first row.

So my idea to solve it was to keep on looping that query until that first row is NOT "no markets available"
 
Back
Top