QUERY function not including text cells along with number cells in result - google-sheets

I'm currently trying to copy a list using the QUERY function in google-sheets.
The problem im now facing is that words / letters are not included in the search.
Example picture
Im using the function: "=QUERY(E2:F5;)" but don't get the words included.
Is there any way to include these words by using the formula above as guide?

In google-sheets, use Format, Number, Plain Text on your source range of E2:F5 and your original formula will work.
=QUERY(E2:F5)
From Docs Editor Help - QUERY function
In case of mixed data types in a single column, the majority data type determines the data type of the column for query purposes. Minority data types are considered null values.

Related

Advanced filter/configurator based on dataset

I would like help with a problem, or rather a challenge in Excel and/or Google Sheets.
What we want to develop is as follows:
We have a table of products and certain attributes. Now we want to create a kind of search function based on this table.
Example:
Let me give a simple example. Suppose you have as a product an apple, a banana and an orange. The characteristics associated with these are size, color country of origin. We then want a search function, where you indicate one or more preferences, i.e. size, color and/or country of origin and that based on those criteria, all products that meet these criteria are displayed.
So if you specify oblong as the size and do not specify any other criteria, it only shows "Banana. If the banana and the orange have Holland as their country of origin and you only give Holland as the criteria country of origin, it will show 'Banana' and 'Orange'. If you say country of origin Netherlands and format oblong, it again shows only 'Banana'
See below an image of our document and how we would like this to look approximately.
Currently, there is no existing formula, because we simply do not know if this can be done and how best to do it.
The document can be accessed at:
A copy of our document with sample data:
Document
ADDITION:
Hi, Unfortunately I still am not able to get it to work. I am not really a hero in coding/functions. I created a bit more of a clear view in my file and also set the language of my sample file to english. You can find it here: Sample
What I actually need is just that it shows the data on 'Datasheet' if conditions on the left (parameters/value) are met, but only if they are filled. Probably easy one for you, hard to me haha Could you help me out once more? –
Your question is very generic, I will try provide here some guidelines on how to achieve it in Excel or Google Sheet based on my own experience. The approach used for Excel can be used for Google Spreadsheet, since it is based on FILTER function that both tools have but with different signature. For Google Spreadsheet you can also use QUERY that is very powerful for situation like this.
In all cases, it is a good practice to have a sheet with the input raw data (let's say Input tab), then in second sheet the working data of filtered data (let's say WorkData). This is specially relevant when the raw data is big dataset, so you don't touch the original data set, and instead you have the filtered data in a separated tab.
Both tools offer filter features in the UI or slice. This is something to consider, but using Excel/Google Spreadsheet functions, you can show the filter parameters in a more friendly manner, because you can see the parameters selected without additional click to find what filter values where selected. The approach here is based on Excel/Google Spreadsheet functions.
Excel
Let's say you have a block of filter conditions that you want to apply to a range of data. You can use data validation list so you can select a subset of possible values for each of the filter conditions and then to concatenate such conditions logically (OR or AND) using multiplication of addition.
=FILTER(dataset, condition1 * condition2...conditionN)
where each condition is based on the filter value you want to restrict and each condition represents an array of {TRUE,FALSE} values all of them of the same size as dataset (number of rows).
I use some wildcard values to represent all values of the column, in my case I use ALL, but you can setup in a different way. In such case the filter doesn't take effect, but we want to make it work when a specific value is selected. The following trick can be used for both scenarios.
IF(B3="ALL", D3:D15<>"*",D3:D15=B3)
indicating that if B3 is equal to ALL, then the condition to select all of the D3:D15 rows is the following: <>"*". Otherwise select only the rows equals to B3.
Sometimes I would like to consider OR conditions for a given filter condition, for example for a given filter condition, consider value1 or value2 and it is represented in the filter value as a list of values delimited by comma, for example: value1, value2.
Here, some Stack Overflow questions I posted with answers about how to deal with that:
Filter an excel range based on multiple dynamic filter conditions
Filter an excel range based on multiple dynamic filter conditions (with column values delimited)
Google Spreadsheet
The FILTER function here, allows to add the filter conditions via input arguments, so now we have:
=FILTER(dataset, condition1, condition2...,conditionN)
Note: Keep in mind in Google Spreadsheet we don't need to add the conditions by multiplying each one of them. It is added via input argument.
here you can check some of question I posted related to this topic:
Using ARRAYFORMULA with SUMIF for multiple conditions combined with a wildcard to select all values for a given condition
Using ARRAYFORMULA with SUMIF for multiple conditions combined with conditions using a wildcard. Result by Months
In some cases it is better to use QUERY function.
Here, a sample file using QUERY statement and how to combine multiple conditions inserting IF in the where statement.
sample query on C1 cell:
=query('Jira Issues'!$A:$T, "where "
& IF(B2="", "G is not Null", "G >= date '"
& TEXT(startPeriod,"yyyy-mm-dd")&"'")
& IF(B3="", "", " and G <= date '"
& TEXT(endPeriod,"yyyy-mm-dd")&"'")
& IF(OR(B4="ALL",B4=""), "", " and A='"&B4&"'")
& IF(OR(B5="ALL",B5=""), "", " and I='"&B5&"'")
& " label A 'Team', S 'Reporter', T 'Assignee',
P 'Env.', I 'Release'",1)
The raw data is in Jira Issues tab, the data populated is based on multiple filter conditions. I am using some name ranges for the filter values for a better understanding of the formula, such as: startPeriod, endPeriod, etc. You can test the actual query will be invoked looking at the result of the consolidated string of the query input argument of QUERY function.
Similarly you can stablish a where statement to consider whether the input parameter is empty or not. In such case, you can build a logic like this inserting an IF block as part of the where statement and concatenate the string result.
=QUERY(Input!A:Y,
"select *" & " where A " & IF(B2="", "<>'*'", "='"&B2&"'")
"and " & " where B " & IF(B3="", "<>'*'", "='"&B3&"'")
,1)
The above query for column A or B, returns the entire column via condition: "<>'*'" if the input parameter B2 or B3 were not specified. In a similar way you can add additional conditions for more parameters, repeating the third line of the query and changing the column and the parameter cell.
Recommendations
Focus on a specific tool: Excel or Google Spreadsheet, even they have some similarities, you need to get familiar with the specifics of each one of them.
Try to start working on your specific problem, once you face impediments, do some research, usually you are not the first person facing this problem, if you don't find a solution, then post your specific problem using a sample as an extract of your real problem (in English, your sample is in other language). Generic questions like this one are difficult to get some attention.

The function "query" in Google spreadsheets works for all columns except one

In Google spreadsheets I use the following simple formula:
=QUERY({'pivot data source'!A:AN},"select * where Col1='2021-08' order by Col2")
This works fine so far. However, there is one comment column. It is empty for most rows. Now I added a comment there - it just won't appear in the result of the query formula.
I realized, that it works fine when the comment is a plain number. As soon as there is text, it won't show up.
As stated in the Google Help section for "query":
In case of mixed data types in a single column, the majority data type determines the data type of the column for query purposes. Minority data types are considered null values.
That means: As long as there are more values with numbers (numeric) than values with text (string), the rows with text will not show up. Even if there are as many numbers as text fields (e.g. one numeric value, one string), Google seems to define the column as numeric and strings don't show up.
To solve this problem, you can try to format the corresponding column in tab "pivot data source" as text (Format > Number > Plain text in the menu).

Google Sheets LOOKUP Function returning the wrong values?

I'm creating a crypto tracking spreadsheet and I'm getting some strange results using the LOOKUP function.
I have two named ranges:
The symbol range is called USDCoinSymbols
and the coin name range is called USDCoinNames
Here are some function results when I try using the LOOKUP function:
Apologies for the mixed casing on the search term. I was experimenting, but
it seems the LOOKUP function isn't case sensitive (for example, BNB returned the correct coin name).
I also tried the inverse, looking up a coin symbol with a coin name (2nd result) and that works fine.
I spent a good couple hours trying to figure this out.
Am I missing something or is this a bug?
Edit: Here is a link to sample spreadsheet and I'm using the CoinGecko API to get this data.
I'm trying to pull the coin name using the symbol to fill up a table I'm creating.
This is not a bug. It's just how LOOKUP works.
LOOKUP requires that all search-column information be in strict least-to-greatest order, so it wouldn't work with your data.
I've added a new sheet ("Erik Help") which is a duplicate of your first sheet. In my sheet, I deleted your LOOKUP formulas from B20:B27 and replaced them with one array formula. This formula uses VLOOKUP with FALSE as the final parameter, meaning that your data is NOT ordered in strict least-to-greatest order and that exact matches should be searched anywhere instead. This one formula fills all results for B20:B:
=ArrayFormula(IF(A20:A="",,IFERROR(VLOOKUP(A20:A,B2:C14,2,FALSE))))
If you are going to be applying this to a larger list elsewhere and want to use your named ranges, just replace B2:C14 with {USDCoinSymbols, USDCoinNames}.
References:
LOOKUP
VLOOKUP
You will need to use the VLOOKUP function instead
=INDEX(IFERROR(VLOOKUP(A20:A25, {USDCoinSymbols, USDCoinNames},2,0)))
This single formula is all you need.
Since your lists are NOT sorted you should use 0 in the function
(please -as always- adjust formula according to your ranges and locale)

Query formula not displaying results that start with (') leading apostrophe strings

I have a sheet here where I need to use query formula
It doesn't display data that start with ' symbol (strings).
How do I make them display? The red cells are empty.
You mentioned
I have a sheet here where I need to use query formula
You can use the following formula:
=QUERY(ARRAYFORMULA(IF(LEN(A2:A),TEXT(A2:A,0),"")))
(Following that, you can leave the cells as text or change them to numbers depending on their further use.)
Functions used:
QUERY
ArrayFormula
IF
LEN
TEXT
Query considers only one data type for each column. As it is stated in the official documentation:
In case of mixed data types in a single column, the majority data type
determines the data type of the column for query purposes. Minority
data types are considered null values.
Therefore, the solution is to change the format to Plain text for column A.
Result:
You can also convert column to text inside QUERY:
=ArrayFormula(QUERY(TO_TEXT(Sheet1!A2:A),"select *"))

Google spreadsheets query() is replacing text with null for mostly numeric columns [duplicate]

This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
I have =query(importrange(...);"select * where Col1>' '") formula in my spreadsheet.
Importrange() by itself works ok, loading all the cells from source spreadhseet exactly as they are.
But Col7 contains few text cells, but mostly numbers, and when query() is applied -- numbers are kept as they are, but text is replaced with blank.
I've tried adding options no_format at the end of the query, with no difference.
Here's the contents of Col7, first line gets replaced with blank:
free
41,25
34,25
34,25
48,25
41,25
QUERY won't return columns with mixed data types by design:
In case of mixed data types in a single column, the majority data type
determines the data type of the column for query purposes. Minority
data types are considered null values.
The workaround will depend on how you want to use your data afterwards, and what compromises you would be willing to make. For example you could fairly easily convert the entire dataset into text strings, so that everything will be retained, but then all your numbers will be text strings as well.
If you needed to retain numbers as numbers, often the best bet will be to ImportRange the entire dataset somewhere in your spreadsheet (could be on a hidden sheet), and then use an alternative to QUERY on that (namely FILTER).
You can use vlookup for the columns that need to be a mixed data type. Query the unique row identifier and then vlookup the rest. I often use the following formula:
=arrayformula(if(isblank(A:A), "", vlookup(A:A, search_range, col_index, FALSE)))
Change the format of the whole column to plain text.
The numbers will still read as numbers, and the minority text values will retain their text values. Nothing will be counted as null.

Resources