I am trying to get a unique rank value (e.g. {1, 2, 3, 4} from a subgroup in my data. SUMPRODUCT will produce ties{1, 1, 3, 4}, I am trying to add the COUNTIFS to the end to adjust the duplicate rank away.
subgroup
col B col M rank
LMN 01 1
XYZ 02
XYZ 02
ABC 03
ABC 01
XYZ 01
LMN 02 3
ABC 01
LMN 03 4
LMN 03 4 'should be 5
ABC 02
XYZ 02
LMN 01 1 'should be 2
So far, I've come up with this.
=SUMPRODUCT(($B$2:$B$38705=B2)*(M2>$M$2:$M$38705))+countifs(B2:B38705=B2,M2:M38705=M2)
What have I done wrong here?
The good news is that you can throw away the SUMPRODUCT function and replace it with a pair of COUNTIFS functions. The COUNTIFS can use full column references without detriment and is vastly more efficient than the SUMPRODUCT even with the SUMPRODUCT cell ranges limited to the extents of the data.
In N2 as a standard function,
=COUNTIFS(B:B, B2,M:M, "<"&M2)+COUNTIFS(B$2:B2, B2, M$2:M2, M2)
Fill down as necessary.
Filtered Results
Solution basing on OP
Studying your post demanding to post any alternatives, I got interested in a solution based on your original approach via the SUMPRODUCT function.
IMO this could show the right way for the sake of the art:
Applied method
Get
a) all current ids with a group value lower or equal to the current value
MINUS
b) the number of current ids with the identical group value starting count from the current row
PLUS
c) the increment of 1
Formula example, e.g. in cell N5:
=SUMPRODUCT(($B$2:$B$38705=$B5)*($M$2:$M$38705<=$M5))-COUNTIFS($B5:$B$38705,$B5,$M5:$M$38705,$M5)+1
P.S.
Of course, I agree with you preferring the above posted solution, too :+)
Related
I have two separate tables in an Excel worksheet, as illustrated below.
Columns A, B, E, F and G are my input values;
I want a formula that generates the values in Column C
(shown in italics):
A
B
C
D
E
F
G
1
Name
Value
Type
Type
Lower
Upper
2
Andy
35
Spam
Spam
35
39
3
Mark
85
Foo
Ham
25
27
4
Pat
28
N/A
Eggs
91
95
5
Deb
93
Eggs
Foo
82
86
6
Emily
92
Eggs
Bar
65
69
7
Greg
22
N/A
8
Gary
67
Bar
For each row in the first table (i.e., each person),
I want to find that person’s Type based on their Value (Column B)
by finding the row in the second table where the person’s Value
falls within the Lower→Upper range (Columns F and G).
So, for example, Mark (Row 3) has a Type of “Foo”
because his Value (85) falls between 82 and 86,
associated with “Foo” in Row 5 of the second table.
Note that Pat’s Value is 28 (Row 4), which does not match any range.
The ranges are inclusive.
For example, Andy’s Type is “Spam” (Row 2) even though his Value (35)
equals the Lower end of the range for “Spam” (Cell F2).
I know nested IFs are quite hard to debug in Excel,
so I’d like to avoid that if possible.
Modify your source table to show the lower limit for each grade and then use a VLOOKUP with a approximate match
Update to show how to include blank ranges
Filter Solution
If you don't have access to the FILTER function, one option is an INDEX/MATCH array formula, which will need confirmed with Ctrl+Shift+Enter.
=INDEX($F$2:$F$6,MATCH(1,($G$2:$G$6<=B2)*($H$2:$H$6>=B2),0),)
Another option is LOOKUP, which does not need Ctrl+Shift+Enter.
=LOOKUP(1,1/(($G$2:$G$6<=B2)*($H$2:$H$6>=B2)),$F$2:$F$6)
That's my first question here ever, though I am reading questions here since a few year.
I am looking for a way to do the following with excel formula
count how many are line matching a criteria. Sounds maybe easy, but so far I didn't manage it, probably because I didn't do it the right way.
I have a table of this kind (here pets, but also work with any "object" array, like worker and their efficiency)
01.10.2018 02.10.2018 03.10.2018
Menu Wg Sz Menu Wg Sz Menu Wg Sz
Lassie Dry food 23 65 Dry food 22 65 Dry food 23 65
Fusel Meat fodder 12 49 Dry food 14 49 Fish fodder 13 49
Bobo Fish fodder 33 86 Meat fodder 32 86 Meat fodder 34 86
I am asking myself the questions like this:
How many pets ate Fish fodder?
How many pets are under 50cm?
I can do easily this on a row level and then add a sum cell (let's say in A column):
COUNTIF(3:3,"Fish fodder")
COUNTIF(4:4,"Fish fodder")
COUNTIF(5:5,"Fish fodder")
COUNTIF(A:A,">0")
But I am looking for a way to do this in a formula for single cell.
I was thinking to use the crtl+shif+enter way, but then i also need to do it on each row an extra cell to be able cumulate the results.
I hope someone can help.
Thank you.
According the COUNTIF formula you gave, I guess this is something you need.
B9 =SUMPRODUCT(--(MMULT(--($B$3:$J$5=$A9),TRANSPOSE(COLUMN($B$3:$J$3)))>0))
B10 =SUMPRODUCT(--(MMULT(--($B$3:$J$5=$A10),TRANSPOSE(COLUMN($B$3:$J$3)))>0))
B11 =SUMPRODUCT(--(MMULT(--(($B$3:$J$5<50)*(($B$2:$J$2)="Sz")),TRANSPOSE(COLUMN($B$3:$J$3)))>0))
All formulas here are Array Formula so please press Ctrl + Shift + Enter to complete them.
The trick is, in matrix [n x m]*[m x 1] = [n x 1]. However in excel, matrix * matrix directly is not a matrix multiplication [#1]. Array * array returns an array with a11*b11, a12*b12, a13*b13 and so on. We have to use a formula called MMULT for matrix multiplying.
Therefore we built up a [3 x 9] matrix first, and we compare it with the criteria "Dry food" then. We get a [3 x 9] matrix full of True or False, so we add double minus sign before the matrix, forcing them become 1 and 0.
The TRANSPOSE is for generating a [9 x 1] matrix, the value is actually not so important once they are greater than 0. Actually we can use a ROW(1:9) and the effect will be the same. However not everyone knows how to adjust the reference in ROW(). A benefit of TRANSPOSE(COLUMN()) is that the reference inside is just the same as the origin data area.
After executing MMULT, the result become a [3 x 1] matrix. And if it is matched with the criteria, the value is greater than 0, others will be 0. So the next part is checking every elements in side the matrix is >0 or not. And then we add a double minus sign again for converting the boolean to 0 and 1. The last part here is simply sum them up by SUMPRODUCT.
[#1] More about matrix multiplication here: https://en.wikipedia.org/wiki/Matrix_multiplication
You could do this with a simple array formulas, they would need to be configured specific to each question. Here are some examples:
Specific Name, Date, and Food:
Food Type By Date:
These are using array multiplication, basically you end up with an array of 1s and 0s and you just sum them.
These are array formulas and must be confirmed with Ctrl+Shift+Enter
I am trying to get a unique rank value (e.g. {1, 2, 3, 4} from a subgroup in my data. SUMPRODUCT will produce ties{1, 1, 3, 4}, I am trying to add the COUNTIFS to the end to adjust the duplicate rank away.
subgroup
col B col M rank
LMN 01 1
XYZ 02
XYZ 02
ABC 03
ABC 01
XYZ 01
LMN 02 3
ABC 01
LMN 03 4
LMN 03 4 'should be 5
ABC 02
XYZ 02
LMN 01 1 'should be 2
So far, I've come up with this.
=SUMPRODUCT(($B$2:$B$38705=B2)*(M2>$M$2:$M$38705))+countifs(B2:B38705=B2,M2:M38705=M2)
What have I done wrong here?
The good news is that you can throw away the SUMPRODUCT function and replace it with a pair of COUNTIFS functions. The COUNTIFS can use full column references without detriment and is vastly more efficient than the SUMPRODUCT even with the SUMPRODUCT cell ranges limited to the extents of the data.
In N2 as a standard function,
=COUNTIFS(B:B, B2,M:M, "<"&M2)+COUNTIFS(B$2:B2, B2, M$2:M2, M2)
Fill down as necessary.
Filtered Results
Solution basing on OP
Studying your post demanding to post any alternatives, I got interested in a solution based on your original approach via the SUMPRODUCT function.
IMO this could show the right way for the sake of the art:
Applied method
Get
a) all current ids with a group value lower or equal to the current value
MINUS
b) the number of current ids with the identical group value starting count from the current row
PLUS
c) the increment of 1
Formula example, e.g. in cell N5:
=SUMPRODUCT(($B$2:$B$38705=$B5)*($M$2:$M$38705<=$M5))-COUNTIFS($B5:$B$38705,$B5,$M5:$M$38705,$M5)+1
P.S.
Of course, I agree with you preferring the above posted solution, too :+)
I'm trying to do something that is very simple to do in Excel, but seems very tricky in Spotfire:
Imagine you have the following table:
A
1: 10
2: 15
3: 20
... and you want to produce the following:
A B
1: 10 10
2: 15 25
3: 20 45
In other words, add the current value of A to the previous value of B. If this was Excel, the formula in cell B3 would be = A3 + B2... However, I'm not in Excel, I'm using Spotfire... :) Any thoughts?
NB: If it makes any difference to the answer at all, I will need to use the Intersect() function in conjunction with this, as there is a categorical column to factor in as well.
Hope this helps, I have considered the first column as ID
ID A B
1 10 10
2 15 25
3 20 45
If(Sum([A]) over (AllPrevious([ID])) is null,sum([A]) over ([ID]),Sum([A]) over (AllPrevious([ID])))
i tried to adapt this post to mine and did have success:
Using SUMIFS with multiple AND OR conditions
it is almost that one, but I'm stuck.
A B C D E F
n/a name S/F due date cut by cutter
abc 25 Sep-29 Sep-28 H
cde 30 Sep-29 Sep-27 E
efg 35 Sep-29 Sep-27 E
abc 40 Sep-29 Sep-27 H
Want do sumif or something that result in: classify by cutter and date, like this:
9/27 9/28 9/29
Eleanor 65 s/f 00 s/f 00 s/f
Hernan 40 s/f 25 s/f 25 s/f
using the following:
=SUMIF(G3639:G3653,"="&Y3654,C3639:C3653)+SUMIF(F3638:F3654,"="&Z3653,C3638:C3654)
it is working double, if I filled my column F with date, its sum twice, I also tried to use "*" instead "+" and didn't work...
I know its make sense to me, and wont for anyone who is reading, but it is a start.
----------above was an example, below real--------------
........"B"......"C"........."E".........."F"......... G
.....customer.....S/F.......Pick up......Cut by:.....Cutter
.....Chelmsford....76.5.....9/30/2014....9/25/2014....1
.....Chelmsford....24.5.....9/30/2014....9/23/2014....1
.....Chelmsford....14.5.... 9/30/2014....9/22/2014....2
.....Newtonville....48.5....9/30/2014....9/25/2014....1
.....Newtonville......7.....9/30/2014....9/24/2014....2
.....Wakefield.......46.....9/30/2014....9/23/2014....2
.....Harvard........92.5....9/30/2014...9/21/2014.....2
.....N. Reading......27....9/30/2014....9/23/2014.....1
.....N Chelmsford....45....9/30/2014....9/24/2014.....2
.....summary at "Y" "Z"
9/21 9/22 etc
cutter 1
cutter 2
=SUMIF(G3:G11,"="&Y3,C3:C11+SUMIF(F3:F11,"="&Z3,C3:C11)
again, looking for production by cutter (1&2) and also by date cut
Using your first example, enter the cutter in H2; date in I1; and this formula in I2
=SUMIFS($C$2:$C$5,$F$2:$F$5,$H2,$E$2:$E$5,I$1)
With some minor range adjustments you can then drag the formula across and down