Excel Formula, Sumifs, condition is an array range - arrays

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.

Related

Best way of storing enumerated fields with ability to change order Postgres

What is the best way for storing enumerated fields with ability to change its order?
Lets say my database looks like this:
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 2 | 2nd | 2 |
| 3 | 3rd | 3 |
| 4 | 4th | 4 |
Now, when user change order in such a away
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 4 | 4nd | 2 |
| 2 | 2nd | 3 |
| 3 | 3rd | 4 |
Here I would have to update all rows in this table.
I consider 2 solutions
Solution 1)
When inserting row X between for example order 2 and order 3, I would change row's X order field to 3.5, So I would choose number in the middle between adjacent orders.
Above table would look like this
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 4 | 4nd | 2.5 |
| 2 | 2nd | 2 |
| 3 | 3rd | 3 |
Then, after for example 16 changes I would update table and normalize all order fields, so table after normalization would be like this:
| Table |
|---------------------|
| id | name | order|
| 1 | 1st | 1 |
| 4 | 4nd | 2 |
| 2 | 2nd | 3 |
| 3 | 3rd | 4 |
Solution 2)
I also consider adding fields "next" (or "next" and "prev") to each row, but it looks for me like waste of memory.
I really dont want to update whole table every time somebody change order. What is the best way of solving this problem?

Comparing Multiple Values with AND using ARRAYFORMULA

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))

comma-separated value to rows and split other colums also /2 or /3

I have a table like this
MeterSizeGroup | WrenchTime | DriveTime
1,2,3 | | 7.843 || 5.099 |
I want to separate the comma delimited string into three rows as
MeterSizeGroup | WrenchTime | DriveTime
1 | | 2.614 | | 1.699 |
2 | | 2.614 | | 1.699 |
3 | | 2.614 | | 1.699 |
please help me how to write a query for this type of split it has to split in such a way that wrech time and driver time also has to be split by 3 enter image description here

SUMPRODUCT doesn't recognise OFFSET array

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.

SSRS 2008 how to count values equal to the current cell?

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")

Resources