As part of a larger formula I need to use an AND statement to compare 2 columns. An example is a table like this:
| A | B |
|---|---|
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
The formula I'm trying is pretty simple. Basically just ARRAYFORMULA(AND(A1:A>2, B1:B>3)). My expectation is the result would be
False
False
True
But I just get False on a single line. Can you use AND in an ARRAYFORMULA?
AND is not supported in ARRAYFORMULA
do:
=ARRAYFORMULA((A1:A>2)*(B1:B>3))
Related
There's a google sheet with content like this:
| A | B |
------------------------------
1 | Banana | Brazil |
2 | Banana | Uruguay |
3 | 2022-02-28 by flight | // Cell spans over two columns
4 | Pineapple | Paraguay |
5 | Banana | Brazil |
6 | 2022-03-08 by Ship | // Cell spans over two columns
7 | Coconut | Uruguay |
8 | Banana | Peru |
I need the amount of non "Brazil" entries of certain lines (excluding the combined ones). It should be st like this =COUNTIF(INDIRECT({B1:B2;B3:B5;B7:B9});"<>Brazil") which doesn't work. Is there an applicable way without using a series of COUNTIFS in which the condition has to be set for every single range?
If this is not possible that way then QUERY might be helpful (see Google Sheets Query Non-Contiguous Range). Then how to obtain the number of the results?
Thank You very much.
perhaps you overthinking it:
=COUNTIF(B:B; "Brazil")
update:
=COUNTIFS(B:B; "<>Brazil"; B:B; "<>")
You don't even need INDIRECT: Just =COUNTIF({B1:B2;B3:B5;B7:B9},"<>Brazil") will work.
To create skips, use FILTER+SEQUENCE.
For eg, This skips row 3 and 6:
=LAMBDA(ar,len,COUNTIF(FILTER(ar,SWITCH(SEQUENCE(len),3,0,6,0,1));"<>Brazil"))(B1:B9,ROWS(B1:B9))
Or with a named function:
SKIP(arr,rows_to_skip):
=FILTER(arr,
MAP(SEQUENCE(ROWS(arr)),
LAMBDA(n, AND(MAP(rows_to_skip,LAMBDA(s, s<>n))))
)
)
Then,
=COUNTIF(SKIP(B1:B9,{3,4,6}),"<>Brazil")
Skips row 3, 4 and 6 in the array B1:B9
I am trying to get data from a "flexible" sheet.
The idea is to add in a row a string, and next to it add a formula that from another sheet, it looks up the string and returns the cell just at the right.
Example:
Data Sheet: DataCollection
| | A | B | C | D |
| 1 | Pepper | 2 | Sugar | 5 |
| 2 | Carbon | 3 | Toy | 34 |
so if in my other sheet, the "Summary" I add to A1 Sugar I would like to see in A2 a 5.
What I have tried so far
VLOOKUP function
=VLOOKUP(A1,'DataCollection'!A2:B&'DataCollection'!C2:D,1,false)
didn't work! I keep receiving a parse formula error.
QUERY function
=QUERY(DataCollection, "SELECT B WHERE A = A1")
that does not work either, I need many different Named Ranges and add a different query for each of them.
Here is a test spreadsheet in case it explains better that my wall of text:
https://docs.google.com/spreadsheets/d/15L5nPGfZ8OXS5Rhl3PdIVhtF7D3QzerkARskflDiJL4/edit?usp=sharing
you almost had it. try:
=VLOOKUP(A1, {'DataCollection'!A2:B; 'DataCollection'!C2:D}, 2, 0)
for an array use:
=ARRAYFORMULA(IFERROR(VLOOKUP(A1:A, {'DataCollection'!A2:B; 'DataCollection'!C2:D}, 2, 0)))
Goal: Use SUMIFS to get the sum of value if color is Red or Yellow. Outcome should be 3.
+---+--------+-------+---+-----------+
| | A | B | C | D |
+---+--------+-------+---+-----------+
| 1 | Key | Value | | Condition |
| 2 | Red | 1 | | Red |
| 3 | Yellow | 2 | | Yellow |
| 4 | Green | 3 | | |
+---+--------+-------+---+-----------+
Problem:
It works if I hardcode the condition {"Red","Yellow"}. The result is 3.
=SUM(SUMIFS(B2:B4, A2:A4, {"Red","Yellow"}))
But if I reference the condition by cell D2:D3, I get 0.
=SUM(SUMIFS(B2:B4, A2:A4, D2:D3))
Question: How do I reference the condition dynamically by cell and make it work?
Use SUMPRODUCT() instead of SUM():
=SUMPRODUCT(SUMIFS(B2:B4,A2:A4,D2:D3))
One note:
This variation allows the expansion of the lists without the need to reapply the ranges:
=SUMPRODUCT(SUMIFS(B:B,A:A,D2:INDEX(D:D,MATCH("zzz",D:D))))
Alternatively, you can use SUMIF() together:
=SUMIF(A2:A4,"Red",B2:B4)+SUMIF(A2:A4,"Yellow",B2:B4)
Or make sure you're using CTRL+SHIFT+ENTER with your current formula attempt.
I'm working through an Excel exercise in which I need to SUMPRODUCT two tables of related values. Unfortunately, I can't be sure the tables will always be ordered identically.
To get around this, I have looked up their values into a new third table; this works, however I'm now looking for a way to do it in one cell.
My code is currently
SUMPRODUCT(Resources_Used18[In House],OFFSET(Rate_comparison[Role],MATCH(Resources_Used18[Role],Rate_comparison[Role],0)-1,1))
For some reason however this doesn't seem to work and only ever returns zeros. The OFFSET(,MATCH()) is meant to reconstruct the second data array, this appears to work and when I test it with F9 it produces the array I'm expecting.
Additionally when I manually enter the array, it provides the correct answer.
So I think the error must be with SUMPRODUCT failing to recognise it as an array.
Where is the error and how can I correct my formula? Thanks for your help.
EDIT: Actually I need to correct myself, OFFSET produce the correct array when run in a cell of its however after I run the cell if I don't ctrl-shift-enter then produces an array of errors.
EDIT:EDIT: An example of the sort of data I'm looking is this,
Rate_comparison
| Role | Rate |
|------|------|
| 1 | 50 |
| 2 | 100 |
| 3 | 150 |
| 4 | 200 |
| 5 | 250 |
| 6 | 300 |
| 7 | 350 |
| 8 | 400 |
| 9 | 450 |
And
Resources_Used18
| Role | In house |
|------|----------|
| 9 | 23 |
| 8 | 24 |
| 4 | 25 |
| 3 | 26 |
| 1 | 27 |
| 7 | 28 |
| 6 | 29 |
| 5 | 30 |
| 2 | 31 |
I have seen this issue before, and cannot explain it. However, if you enclose the OFFSET function inside the N function, the actual values will be returned.
I did not check to see if the result (59,300) is correct however.
=SUMPRODUCT(Resources_Used18[ [ In house ] ],N(OFFSET(Rate_Comparison[ [ Role ] ],MATCH(Resources_Used18[ [ Role ] ],Rate_Comparison[ [ Role ] ],0)-1,1)))
According to Tushar Metar, The OFFSET function, when used with an array as the 2nd or 3rd argument, returns an undocumented data structure that is understood only by Excel. The N function converts the data from the internal structure into one that can be displayed or used for further analysis. Laurent Longre deserves the credit for discovering this capability of the N function.
I want to add a placeholder to a cell that includes a count of rows from that dataset that have that the same value.
Example:
| ID | Value |
| 1 | 123 (3) |
| 2 | 123 (3) |
| 3 | 456 (2) |
| 4 | 123 (3) |
| 5 | 456 (3) |
| 6 | 789 (1) |
This is what I have so far, but it obviously doesn't work:
Fields!cpt4_code.Value
Instead of it indicating how many times that value occurs, it simply count the number of rows return in that dataset.
Is this even possible with one dataset?
You should use LookupSet for this:
=LookupSet(Fields!fieldOne.Value, Fields!fieldOne.Value, Fields!fieldOne.Value, "DataSetNameHere").Length
LookupSet returns an array, hence the ".Length" at the end.
Think this kinda thing is what you need
=Sum(IIF(Fields!field name.value,1,0),"DatasetNameHere")