How can I cap my result to 1 with importXML - xpath

Using importXML I am searching for the class 'current' which contains 'current-price'.
Using this code it returns the same result 3 times as the 'current' class exists 3 times on the website.
=importxml("https://www.currys.co.uk/gbuk/tv-and-home-entertainment/televisions/televisions/lg-55sm8200pla-55-smart-4k-ultra-hd-hdr-led-tv-with-google-assistant-10191769-pdt.html", "//div//strong[contains(#class, 'current')]")
Is there a simple way to cap my search to 1 result so that it doesn't overlap data on the row below?

sure, you can use INDEX like:
=INDEX(IMPORTXML("https://www.currys.co.uk/gbuk/tv-and-home-entertainment/televisions/televisions/lg-55sm8200pla-55-smart-4k-ultra-hd-hdr-led-tv-with-google-assistant-10191769-pdt.html",
"//div//strong[contains(#class, 'current')]"), 1, 1)

Related

QUERY + IMPORTRANGE : Did I reached a limit of 999 rows?

Issue with an incomplete import in google sheet
Following this thread :
VLOOKUP + QUERY + IMPORTRANGE > import all lines with condition true
I have a list of spells that today exceeds 1010 items.
The source data is imported in different spreadsheets with the following formula that does work : =ARRAYFORMULA(IFNA(VLOOKUP(A3:A; QUERY({IMPORTRANGE(A1; I1)}; "select Col2,Col1,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15 where Col1=TRUE"; ); {3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12\ 13\ 14\ 15}; )))
However, I reach a limit at row A1001 ; the following wont get filled with any data even though the remaining items in the source data followed the query rules.
I import a table of 15 columns, so I was wondering if there was a limit of 15*1000 cells in google sheet and if so, what was the best way of getting the extra rows.
Thanks !
Try inserting in Sheet 2 the full QUERY:
=QUERY({IMPORTRANGE(Sheet1!A1;Sheet1!I1)}; "select Col2,Col1,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15 where Col1=TRUE"; )
(PS: I'm guessing your first sheet is called Sheet1, please check it)
And in Sheet1 you can use FILTER:
=BYROW(A3:A,LAMBDA(each,IFNA(FILTER(Sheet2!B:O,Sheet2!A:A=each))))
Let me know!

Google Sheets - Find and match value with filter

I have try using query, vlookup and filter to get data from other tab sheets
I don't know how to get data with logic condition.
Here my sheets :
https://docs.google.com/spreadsheets/d/1sukCRlU1UuXS6IaR8xCYs8QScH4B2m60bqsrypDkzTM/edit?usp=sharing
Step 1 :
I have tab sheet with list of reward
Step 2 :
in the other tab sheet (cust_point), in column C i want to get value from tab sheet Reward where it use match and logic condition >= and <=.
Then here my expectation :
Problem :
First, i try with formula
=QUERY(Reward!A2:B, "SELECT A WHERE B <= '"&C2&"'", 1)
then the result just showed but doesn't match
Second, i try with formula
=FILTER(Reward!A2:B,C2>=Reward!B2:B)
Third, i try with formula
=IF(VLOOKUP(C2,Reward!B2:B,1,FALSE), C2>=Reward!B2:B)
They all formula doesn't get value with match data like my expectation
How can I achieve that?
use:
=ARRAYFORMULA(IFNA(VLOOKUP(10000-B2:B;
SORT({10000-Reward!B2:B\Reward!A2:A}); 2; 1)))

Xpath operators for WP All Import

I want to import all products filtering these they applied all 3 criteria:
1) they are in stock (DIM)
2) stock is more than 3 pcs (stock_indicator)
3) and they belong to one (any) of these groups 1 or 4
I want all 3 criteria, but in 3rd any of these options
i.e.:
/product[dim1[1] = "1" and stock_indicator[1] > 3 and group[1] = "1" or group/category/id[1] = "4"]
The above does not returns any product, like no product have all these requirements.
What am I doing wrong?
Dim = availability
XML sample:
/product[dim1[1] = "1" and stock_indicator[1] > 3 and group[1] = "1" or group/category/id[1] = "4"]
First of all your XPath assumes that all product elements are at root level, which would not make for a well-formed XML document; the all should be wrapped in some element.
If that is no problem in your environment (since we do not know the whole setup from your question) probably the most prominent problem in your XPath is that you try to compare the value of stock_indicator against a xs:integer but in fact your data sample encodes them as xs:string.
Consequently
stock_indicator[1] > 3
will always return falseā€¦
Try
stock_indicator[1]/number() > 3
or
number(stock_indicator[1]) > 3
instead.
Nevertheless depending on the data structure (e.g. multiple stock_indicatorelements in one product [whatever that might mean]) this could return false positives.
You can use the following XPath to filter the products :
//product[availability="1"][stock_indicator>3][group/id=1 or group/id=4]
// at the beginning as stated by #Benjamin W. Bohl to catch all products
availability is used instead of "Dim"
cleaner syntax used for predicates
no position indexes used ([1]) assuming you only have 1 availability, 1 stock_indicator, 1 id per group in each product
XML used to test.
XPath :
XML is filtered (2 of the 4 products fulfill the conditions) :

Creating a dynamically sorted and filtered list from a range using a single formula in Google Sheets

I'm trying to do something similar to this question: Google sheets using Filter and Sort together
I have an input range with two columns, and as output I want to create a dynamically sorted and filtered list from the input range, using a single formula.
See this document for the desired result: https://docs.google.com/spreadsheets/d/109xcbORFZxTjH0Vjd6PVqYlOxMIdK7aXqf5-jnMMPik/edit?usp=sharing
I tried the formula: =SORT(FILTER(B11:C100, B11:B100 = or(I11,I12,I13,I14)), 2, 0) but it doesn't work. What I am doing wrong here? Any help much appreciated.
try:
=ARRAYFORMULA(QUERY(B11:C,
"where lower(B) matches '"&TEXTJOIN("|", 1, LOWER(I11:I))&"'
order by C desc", 0))
You can modified or(,,,,) like follow:
=SORT(
FILTER(B11:C100,
((B11:B100 = I11)*1+(B11:B100 = I12)*1+(B11:B100 = I13)*1+(B11:B100 = I14)*1)>0
)
, 2, 0
)

How to filter clickhouse table by array column contents?

I have a clickhouse table that has one Array(UInt16) column. I want to be able to filter results from this table to only get rows where the values in the array column are above a threshold value. I've been trying to achieve this using some of the array functions (arrayFilter and arrayExists) but I'm not familiar enough with the SQL/Clickhouse query syntax to get this working.
I've created the table using:
CREATE TABLE IF NOT EXISTS ArrayTest (
date Date,
sessionSecond UInt16,
distance Array(UInt16)
) Engine = MergeTree(date, (date, sessionSecond), 8192);
Where the distance values will be distances from a certain point at a certain amount of seconds (sessionSecond) after the date. I've added some sample values so the table looks like the following:
Now I want to get all rows which contain distances greater than 7. I found the array operators documentation here and tried the arrayExists function but it's not working how I'd expect. From the documentation, it says that this function "Returns 1 if there is at least one element in 'arr' for which 'func' returns something other than 0. Otherwise, it returns 0". But when I run the query below I get three zeros returned where I should get a 0 and two ones:
SELECT arrayExists(
val -> val > 7,
arrayEnumerate(distance))
FROM ArrayTest;
Eventually I want to perform this select and then join it with the table contents to only return rows that have an exists = 1 but I need this first step to work before that. Am I using the arrayExists wrong? What I found more confusing is that when I change the comparison value to 2 I get all 1s back. Can this kind of filtering be achieved using the array functions?
Thanks
You can use arrayExists in the WHERE clause.
SELECT *
FROM ArrayTest
WHERE arrayExists(x -> x > 7, distance) = 1;
Another way is to use ARRAY JOIN, if you need to know which values is greater than 7:
SELECT d, distance, sessionSecond
FROM ArrayTest
ARRAY JOIN distance as d
WHERE d > 7
I think the reason why you get 3 zeros is that arrayEnumerate enumerates over the array indexes not array values, and since none of your rows have more than 7 elements arrayEnumerates results in 0 for all the rows.
To make this work,
SELECT arrayExists(
val -> distance[val] > 7,
arrayEnumerate(distance))
FROM ArrayTest;

Resources