importxml & xpath in google sheets - google-sheets

I am trying to get stock info from Yahoo Finance with the function importxml in google sheets. How can I get to the revenue row?
https://finance.yahoo.com/quote/AMZN/financials?p=AMZN
From this page I would like to go down to income statement and get total revenue for the last 3 years.
First I click inspect the page and copy the full xpath. Then I add it to the formula importxml in google sheets:
=IMPORTXML(
"https://finance.yahoo.com/quote/AMZN/financials?p=AMZN";
"/html/body/div[1]/div/div/div[1]/div/div[3]/div[1]/div/div[2]/section/div[3]/div[1]/div/div[2]/div[1]/div[1]/div[2]")
but it says:
#N/A Error - Resource at url not found

Related

dividend error on Google Sheets with the function IMPORTXML

I want to get the dividend of companies like ENG.MC or other stock like GSY.TO, but Sheets did not find the dividend.
i put on my Google Sheet:
=IMPORTXML($D$25;D24)
I want the "Forward Dividend & Yield" from Yahoo but i recieved a #N/A
example of the error

Google sheets import from multiple sheets giving error

I have created a master sheet which imports the data for the other sheets which are representing the dates of the month. In the sheet the master sheet cell A2 has the formula to import from the other sheets which the google sheet
Google Spread Sheet.
The issue I am facing is that if in the formula I change the sheet 10 range from A2:CH to A2:CO it gives an error
Error
In ARRAY_LITERAL, an Array Literal was missing values for one or more rows.
I am not being able to find the problem as this is not a permissions issue and neither does sheet 10 have any data in this case.
full code is below:
=UNIQUE(query({'1'!A2:CO;'2'!A2:CO;'3'!A2:CO;'4'!A2:CO;'5'!A2:CO;'6'!A2:CO;'7'!A2:CO;'8'!A2:CO;'9'!A2:CO;'10'!A2:CO;'11'!A2:CO;'12'!A2:CO;'13'!A2:CO;'14'!A2:CO;'15'!A2:CO;'16'!A2:CO;'17'!A2:CO;'18'!A2:CO;'19'!A2:CO;'20'!A2:CO;'21'!A2:CO;'22'!A2:CO;'23'!A2:CO;'24'!A2:CO;'25'!A2:CO;'26'!A2:CO;'27'!A1:CO;'28'!A2:CO;'29'!A2:CO;'30'!A2:CO;'31'!A2:CO},"select * where Col1 is not null"))

How to figure out proper xpath for IMPORTXML in Google Sheets - N/A Error?

I'm trying to use the IMPORTXML function on Google Sheets.
For example: =IMPORTXML("https://www.tiktok.com/#charlidamelio?lang=en", XMLPATH) should return "54.3M"
I used the Chrome inspector to copy the xpath, which gives me:
/html/body/div[1]/div/div[2]/div/div[1]/div/header/h2[1]/strong[2]
When I try this in Google Sheets it returns an error: #N/A (Import Content is Empty).
P.S. I'm open to other ways to get the data I need into the google sheet, it doesn't have to use the IMPORTXML function.
How about this answer?
In this answer, IMPORTXML and REGEXEXTRACT are used. And also, it supposes that the URL of https://www.tiktok.com/#charlidamelio?lang=en is put in a cell "A1".
Pattern 1:
In this pattern, "followerCount" is retrieved.
Sample formula:
=REGEXEXTRACT(IMPORTXML(A1,"//script[#id='__NEXT_DATA__']"),"followerCount"":(\d+)")
"followerCount" is retrieved from the script.
In this case, when =VALUE(REGEXEXTRACT(IMPORTXML(A1,"//script[#id='__NEXT_DATA__']"),"followerCount"":(\d+)")) is used, the retrieved value can be used as the number.
Result:
Pattern 2:
In this pattern, "followerCount" is retrieved.
Sample formula:
=REGEXEXTRACT(IMPORTXML(A1,"//meta[#name='description']/#content")," ([\w\d.]+) Fans")
The value of "54.4M Fans" is retrieved from the metadata.
Result:
References:
IMPORTXML
REGEXEXTRACT

How to convert Excel formula to Google Sheets?

This code calculates a sum of string lengths in the range H1:V5 using G as a row index and C as a column index. It works perfectly in Excel:
{=SUMPRODUCT(LEN(INDEX(H1:V5,N(IF({1},ROW(G2:G5))),N(IF({1},C2:C5+1))))*ISNUMBER(G2:G5))}
But when I try it in Google Sheets it doesn't work although Google Sheets recognizes all commands. Is it possible to convert my formula to Google Sheets? Or maybe there is some workaround to get the same result there?
Open with Google Sheets returns incorrect result:
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUMPRODUCT(LEN(INDEX(H1:V5,N(IF({1},ROW(G2:G5))),N(IF({1},C2:C5+1))))*ISNUMBER(G2:G5))), 1, 1)
Unfortunately the construct index...n(if({1}... is peculiar to Excel.
The vlookup function in Google sheets is very versatile and you can use that instead:
=SUMPRODUCT(len(vlookup(row(H1:K5),{row(H1:K5),H1:K5},C1:C5+2,false))*isnumber(G1:G5))

Index Match on 2 separate google sheets

Can you please help me with the index match formula with Google sheets on 2 different workbooks? I know the formula on a regular excel sheet but it just won't do the same with google sheets.
I tried the same formula with the regular excel sheet but it just won't work.
try:
=IMPORTRANGE("1VYCPRlno-upguZFmf-dgVG8pXxkXXTx-OWt_VBv4d5c", "Sheet1A:Z")
note: chenge sheet name if needed
note2: first you will see ref error. hover your cursor over it and a button will popup. click on it to authorize the connection/link between your two spreadsheets

Resources