I don't know if this is possible to do without scripting, but I would like to have a block of cells that can be modified by the user where they will enter a string in each cell. For each of these string values I would like to retrieve a number from a table that matches that string and SUM together all of the resulting matched numbers.
With the matching table:
The users enters:
I would like to have the resulting SUM = 1 + 4 + 3 = 8
If your matching table is named namedRange1 and your chosen colours are in A9:A11:
=vlookup(A9,NamedRange1,2,0)+vlookup(A10,NamedRange1,2,0)+vlookup(A11,NamedRange1,2,0)
Alternatively, name the values in the matching table by their corresponding colour and:
=Red+Yellow+Blue
I figured it out.
=SUM(ARRAYFORMULA(IF(UserInput <> "", VLOOKUP(UserInput, ColorMatcher, 2, false), 0)))
SUM - Adds all of the values together
ARRAYFORMULA - Allows the use of a "single target" function to work over an array of values, returns each individual lookup value to SUM
IF(UserInput <> "") - Each of these values is compared to empty string first so that I can have blank cells in the range, otherwise VLOOKUP breaks due to a non-match, returns 0 otherwise
VLOOKUP - Each value in UserInput is compared to a value in the first column of ColorMatcher, and takes the matching value in the 2nd column. In this case the index is not sorted
Related
I'm trying to separate specific rows of data into a new sheet, based on the text string in Column H / 8;
=query({attendees_list!A2:N2},"select Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14 where Col8='Show1 - Adult (Earlybird Pricing)'",1)
The query is working, in that it returns columns 1-14 from the 'attendees_list' sheet, but it doesn't seem to be applying the "where" condition, as its returning all rows regardless of the Column H value, rather than returning the specified value; 'Show1 - Adult (Earlybird Pricing)')
Here is a document with the example of the issue
https://docs.google.com/spreadsheets/d/1LEISiYnFeOloA5FDmzA3B5fhXVY_YJiivxedR5qurpU/edit?usp=sharing
I've tried different string quote types (ie; ''&"") but I can't figure out the issue.
Any idea where I'm going wrong here?
the issue is in the range A2:N2 <- that's one row and then 3rd query argument set to 1 will treat that single row as a header row and always output it whatever you setup in 2nd query argument
try:
=QUERY({attendees_list!A2:N},
"select Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14
where Col8 = 'Show1 - Adult (Earlybird Pricing)'", )
I need to get the letter of the column that has a value in a given row that matches a given value in Google Sheets, assuming that no values in the row are duplicates.
For example, in the above screenshot, if the row is the first row, and the test value is Jun, the formula will return H.
Kind of meta. Appreciate any help.
Answer
The following formula should produce the behaviour you desire:
=REGEXREPLACE(ADDRESS(1,MATCH("Jun",A1:1),4),"[1-9]*",)
Explanation
The =MATCH formula returns the position of the item in a range which has a specified value. In this case, the specified value is "Jun" and the range is A1:1.
=ADDRESS returns the A1 notation of a row and column specified by its number. In this case, the row is 1 and the column is whichever number is returned by the =MATCH. The 4 is there so that =ADDRESS returns H1 instead of $H$1 (absolute reference is its default).
=REGEXREPLACE looks through a string for a specified pattern and replaces that portion of the string with another string. In this case, the pattern to search for is any number. The last argument of =REGEXREPLACE is blank so it simply removes all numbers from the string.
What is left is the letter of the column where the value is found.
Functions Used:
=MATCH
=ADDRESS
=REGEXREPLACE
Now that Google Sheets has added Named Functions, there is an easier way to do this.
To use named functions, go to Data -> Σ Named Functions. A sidebar will pop up. At the bottom use "Add new function" to create a new named function.
I created two functions to do this:
First, COL_CHAR which will take a column reference and return its letter
Second, ALPHA_CHAR which takes a numeric input and converts it to letters. I made this one recursive, so if it's an n-letter column name, it will keep calling itself until it gets the full name.
COL_CHAR just converts the referenced column to a column number and passes that to ALPHA_CHAR. It's formula is:
=ALPHA_CHAR( column(cell) )
where cell is an Argument placeholder. Make sure to add that to the argument placeholder list in the sidebar.
Here is the (recursive) formula for ALPHA_CHAR:
=IF( num > 26, ALPHA_CHAR( INT( num / 26 ) ), "") & CHAR( CODE("A") - 1 + MOD( num, 26 ) )
where num is an Argument placeholder.
By making this recursive, even if Google Sheets expands to allow 4-letter (or more) columns in the future, it will keep iterating through every letter regardless of how many there is.
Then, to get the letter of a column in the spreadsheet, you just call COL_CHAR and pass the cell in the column you want, for example:
= COL_CHAR(BK1)
Will return the string "BK"
I have a row with the following values in each cell from A1 until F1
A,A,A,A,A,A
Then in row 2 I have
A,B,A,A,A,A
Since some columns are empty (no value) I filter the row to get only cells with value:
=filter(A1:F1, A1:F1<>"")
then how can i get a true/false response if all values/strings in the filter array are equal?
Similar answer given here, but that was for a set of arbitrary cells, not a range.
Using range notation:
=COUNTUNIQUE(A1:F1)=1
As implied by the function name, it counts the number of unique values. If there is only one unique value, then we know all the cells are equal. Since COUNTUNIQUE disregards blank values, there is no need to use FILTER first. If you want TRUE for all blanks, change = to <=, as it will return 0 in that case.
If you later decide you do want to consider blank values:
=COLUMNS(UNIQUE(A1:F1, 1))=1
This counts the number of columns returned by UNIQUE(..., 1) (1 means "by column"). If it's 1, then all cells are equal.
I'm trying to get the sum of all items in column F:F when Column J:J = "Channel"and Column K:K = "Country"
=DSUM(Sheet1!$A$1:$K$142,Sheet1!$F$2:$F$142,{{Sheet1!K:K;"Channel"},{Sheet1!L:L;"Country"}})
The above query returns a 0 when it should return a 7.
Try:
=DSUM(Sheet1!$A$1:$L$142, Sheet1!$F$1, {{Sheet1!$K$1; "Channel"}, {Sheet1!$L$1; "Country"}})
Notice changes about the parameters:
Sheet1!$A$1:$L$142 column L:L should be included if you want to use it in your criteria.
Second parameter just needs a column name (Sheet1!$F$1) or its number (6). No need to place the whole range there.
You need to have a two strings range for criteria: first one with the column name, second with the criteria for that column. You set before the whole column K:K and L:L and placed a string to match at the bottom. Only the first tow rows were used, so you criteria was actually like this: kolumn K:K should be like the value in K2 and column L:L like the value in L2 (but this one didn't actually worked as this column was not a part of your table (the 1st parameter)).
Or you can use SUMIFS:
=SUMIFS(Sheet1!$F$2:$F$142, Sheet1!$K$2:$K$142, "Channel", Sheet1!$L$2:$L$142, "Country")
Or if you need to sum the whole column (not just down to 142 row):
=SUMIFS(Sheet1!$F:$F, Sheet1!$K:$K, "Channel", Sheet1!$L:$L, "Country")
Here's a basic proof-of-concept.
Count all vegetables
Answer: 18
Formula: =DSUM(A4:D10,"Qty",{"Category";"Vegetable"})
Count all vegetables at Safeway
Answer: 10
Formula: =DSUM(A4:D10,"Qty",{{"Category";"Vegetable"},{"Store";"Safeway"}})
In our Staff timetable, employees can have an "A"shift (which starts at 9am) a "B" shift (which starts at 10:30am) etc.
I need to know how many shifts in total the employees make so what I use now is a multiple times COUNTIF to count the presents of a few arguments in a range of cells
=countif(D8:BM8;A43)+countif(D8:BM8;A44)+countif(D8:BM8;A45)+countif(D8:BM8;A46)++countif(D8:BM8;A47)
Where field A43 contains "A" field A44 cointains "B" etc.
This works perfect, however, I want to have a smarter way to do this, so I tried to use "COUNTIFS" but the result is always 0 and I can't find why
=COUNTIFS(D8:BM8;A43;D8:BM8;A44;D8:BM8;A45;D8:BM8;A46;D8:BM8;A47)
if looks like all arguments are checked with a logical and, but I need a logical and in this case or a solution with dcounta
You are getting a 0 because there is no cell that will meet ALL conditions.
Instead, maybe try something like
=sum(ArrayFormula(--regexmatch(D8:BM8; textjoin("|"; 1; A43:A47))))
Regexmatch returns a boolean, for all the cells in D8:BM8 (true if a match is found, false otherwise). These booleans are converted into 1 and 0 (see the -- in front of the regex). Then all those values are summed.
Copy and paste the code in a module.(VBA)
Select the cell you want to have the results
Use COUNTIFMATCH Function as the usally functions.
The first Argument is the range you want to count. The second Argument is the range with your criteria. e.g
=COUNTIFMATCH($A$1:$A$20,$C$1:$C$3) or =COUNTIFMATCH($A$1:$A$20,($B$1,$D$1))
whatever you need based on your needs.
Option Explicit
Function COUNTIFMATCH(Range As Range, Criteria As Range) As Integer
'counts the number of cells in one range by the values of another range.
Dim datax As Range
Dim rslt As Range
Dim i As Integer
Set rslt = Range
For Each datax In Criteria
i = i + WorksheetFunction.CountIf(rslt, datax)
COUNTIFMATCH = i
Next datax
End Function