Forum

can you use an if t...
 
Notifications
Clear all

can you use an if then when trying to download elements rather than a table?

2 Posts
2 Users
0 Reactions
133 Views
(@dougm10)
Posts: 1
New Member
Topic starter
 

This is my first question to the group so be kind.

I have developed a power query to Yahoo Finance that extracts every table from the summary & statistics pages and places it into one table. really slick use of that turning a web query into a function and the function reads the input from each address in the table. the issue is that when i come to the financial pages, they are only html documents. so i created same function but i used the xpath addresses. it works but .... one of the companies is behind in its reporting. thus each company has the same number of rows ... cash, equity, revenue. but this one has less columns because it is behind two quarters.

https://finance.yahoo.com/quote/MPXOF/financials?p=MPXOF   1-quarterly column and 1 trailing 12 month column

https://finance.yahoo.com/quote/EOSE/financials?p=EOSE       4-quarterly columns and 1 trailing 12 month column

 

thus, when i compare the xpath, i get this difference

  EOSE MPXOF
TRUE html[1] html[1]
TRUE body[1] body[1]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[3] div[3]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[2] div[2]
FALSE div[1]  
FALSE div[1]  
TRUE section[1] section[1]
TRUE div[3] div[3]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[1] div[1]
TRUE div[2] div[2]
TRUE span[1] span[1]

thus, a query using the 5 columned table for MPXOF comes back with an error and the query only keeps everything up to MPXOF. There are only two levels separating the two so can you say in the function if no error use xpath1 and there is an error use xpath2?

 

thanks;

Doug Marcus

 
Posted : 07/04/2023 3:42 pm
(@catalinb)
Posts: 1937
Member Admin
 

Hi Doug,

You can try:

try Function(xpath1) otherwise Function(xpath2)

 
Posted : 09/04/2023 6:03 am
Share: