Import numerical value from a website to Google Sheets - google-sheets

I want to import a numerical value from this website to this spreadsheet.
I want to import LDCP (last day closing price) in cell B2.

In your situation, how about the following sample formula?
Sample formula:
=IMPORTXML(A1,"//div[#data-name='REG']//div[div[#class='stats_label']/text()='LDCP']/div[#class='stats_value']")
In this case, the URL of https://dps.psx.com.pk/company/SYS is put in the cell "A1".
When you want to put the value to the cell "B2", please put =IMPORTXML("https://dps.psx.com.pk/company/SYS","//div[#data-name='REG']//div[div[#class='stats_label']/text()='LDCP']/div[#class='stats_value']") to the cell "B2".
I thought that in this case, the following formula can be also used.
=IMPORTXML(A1,"//div[#data-name='REG']//div[#class='stats_value'][../div[#class='stats_label']/text()='LDCP']")
Result:
Note:
The XPath of this sample formula is for your URL of https://dps.psx.com.pk/company/SYS. So, when you changed the URL, the XPath might not be able to be used. So please be careful about this.

You can use
=REGEXEXTRACT(INDEX(IMPORTXML(A1,"//div[#data-name='REG']"),2,4),"LDCP(\d+\.\d+)")
assuming that =TRANSPOSE(IMPORTXML(A1,"//div[#data-name='REG']")) will give you these informations
By index I fetch the cell I need, then I apply a simple regexextract formula.
This way you can easily retrieve other information.

Related

Formula parse error with AVERAGEIFS in Google Sheets

I want to calculate averages in a column but only on selected rows, depending on specific values in another column. I see that I should probably use AVERAGEIF or AVERAGEIFS, but somehow it does not work, not even if I copy and paste the example from Google's help. I did experience the same in multiple browsers and with both versions of the function. What can be the problem?
Do you need to adjust the formula for your locale?
=AVERAGEIFS(A1:A10;B1:B10;">20")

Looking for a formula to check if a URL from one cell is contained in another in Google Sheets

I have a Google Sheet with a long list of URLs in one column, and in the column to the right of it another URL, but wrapped in an href attribute.
I am trying to find a formula that checks to see if the URL contained inside the href for each row in column B matches the URL in the same row in column A, and returns TRUE or FALSE.
I have attached an image to illustrate what I mean.
I've tried playing around with the REGEXMATCH function but I don't seem to be coming up with the answer.
I'd really appreciate if someone could help. Thanks.
try in C2:
=INDEX(REGEXMATCH(B2:B; A2:A))
What about conditional formating the two rows with a custom formula? E.g.,
=countif(A1:A,A1)>1

How to make importxml only give a certain data

I am trying to get only the number of likes from a website. Currently, I am using
=IMPORTXML("https://www.abillionveg.com/articles/vegan-diet-nutrition-guide","//button")
However, it gives me data from all of the buttons. Can someone help me modify the formula to show only the likes?
Sorry if this is a basic question, I am just learning.
You want to retrieve the number of the number of likes using IMPORTXML.
If my understanding is correct, how about this answer?
Modified formula 1:
=INDEX(SPLIT(IMPORTXML(A1,"//div[#class='ArticleActions__Container-sc-15ye7g8-0 huWdyg'][1]//span[contains(text(),'likes')]")," "),1)
The URL of https://www.abillionveg.com/articles/vegan-diet-nutrition-guide is put in the cell "A1".
The xpath is //div[#class='ArticleActions__Container-sc-15ye7g8-0 huWdyg'][1]//span[contains(text(),'likes')].
Retrieve the value using IMPORTXML.
Retrieve the number of ### from the value like ### likes using SPLIT and INDEX.
Result:
Modified formula 2:
=REGEXEXTRACT(IMPORTXML(A1,"//script[#id='__NEXT_DATA__']"),"likesCount""\:(\d+)") - 1
This result is the same with Modified formula 1.
Note:
For example, if =IMPORTXML(A1,"//div[#class='ArticleActions__Container-sc-15ye7g8-0 huWdyg'][1]//span[contains(text(),'likes')]") is used, 100 likes is retrieved.
References
IMPORTXML
SPLIT
INDEX

How do I conditionally format if value extracted is > number value?

I have a use case where I need to conditionally format a cell if the extracted value from this formula is greater than 5.
=trim(MID(C3:AZ,FIND("-",C3:AZ)+1,FIND("pts",C3:AZ)-FIND("-",C3:AZ)-1))>5
When I lock the cell references, I still don't get any conditional formatting, even though it accepts the formula:
=trim(MID($C$3:$AZ,FIND("-",$C$3:$AZ)+1,FIND("pts",$C$3:$AZ)-FIND("-",$C$3:$AZ)-1))>5
When I do the formula referencing a single cell, I get the expected output:
I've made an example Google Sheet for reference, if you'd like to take a look at the sample dataset.
Any help/advice you all could provide would be greatly appreciated.
Thanks!
Try this formula. The way conditional formatting works is if the range for conditional formatting starts on A3, then you can put that one cell as the checking value, and the spreadsheet is smart enough to then check each cell in the range separately. I put a value around it as well since "trim" makes it a text instead of a number.
=value(trim(MID(A3,FIND("-",A3)+1,FIND("pts",A3)-FIND("-",A3)-1)))>5

reference cell via two partial matches on another cell

I need to match two conditions on the cell Name and add the price information into cell price if both condition match. In other words, if Name contains both conditions, get the price. I tried different approaches using QUERY, SEARCH; FIND; VLOOKUP but I got stuck somewhere in the middle. Here's the example sheet (Google Spreadsheet solution preferred over Excel):
https://docs.google.com/spreadsheets/d/1zwG3_5Ctg_IZ1kI04Uee-qIvMrNQ4GmEwySmYcMKLfA/edit?usp=sharing
Maybe important: Both, the Name values as well as the whole reference table get pulled from other files dynamically. So I don't know anything concerning order or length of these columns in advance, not even if there are matches at all.
In addition to previous answer AND given the current set of data (in a Google spreadsheet), in B2 try:
=ArrayFormula(iferror(vlookup(regexreplace(A2:A; "[^A-Z]"; ""); {E2:E&F2:F\G2:G}; 2; 0)))
and see if that works ?
Based on your spreadsheet table:
you can try the following formula:
this formula works in excel not in google spreadsheets
=IFNA(INDEX($G$2:$G$6;MATCH(1;COUNTIFS(A2;"*"&$E$2:$E$100&"*";A2;"*"&$F$2:$F$100&"*");0));"NOT FOUND")
this is an array formula, so press ctrl+shift+enter to calculate the formula.
i think it will do the job.
here is the example file to download

Resources