Currently have an AVERAGEIFS formula where:
Col A is Arrival to Last Lab Results (POC Glu, POC INR) with the data being numbers
Col B is Activation Type in this case being "EMS (pre-hospital)"
Col C is poc_inr not needed which is either "Yes" or "No"
The formula is applied for a date range of 1 month.
The formula is pasted below:
=AVERAGEIFS(MM[Arrival to Last Lab Results (POC Glu, POC INR)], MM[Arrival Date/Time],">="&A30,MM[Arrival Date/Time],"<="&B30,MM[Activation Type],"EMS (pre-hospital)", MM[poc_inr not needed], "Yes")
Currently, the formula is only looking at cases where [poc_inr not needed] is a "Yes."I wanted a way to incorporate an OR statement where if the [poc_inr not needed] was a "Yes", then the formula would continue to take the values in Col A but if [poc_inr not needed]was a "No" the formula would instead take a look at the values in another column altogether (let's name it Col D for simplicity's sake) and provide me the average of all the numerical values taken from Col A and Col D. All the other criteria and criteria range stay as is.
I have heard that AVERAGEIFS does not allow for OR functions, so I was wondering if anyone had a solution/alternative way of approaching this?
Don't use OR, specify different criteria for each case and just add them together. You will be better off using SUMPRODUCT and named ranges/tables to make your formula easier to read:
You should be able to adjust it without many problems:
=(SUMPRODUCT((Table1[poc_inr]="Yes")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2)*Table1[Last Lab Results])+SUMPRODUCT((Table1[poc_inr]="No")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2)*Table1[Other result]))
/(SUMPRODUCT((Table1[poc_inr]="Yes")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2))+SUMPRODUCT((Table1[poc_inr]="No")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2)))
Related
I'm having an issue with INDEX + MATCH combination:
=INDEX(ALL!$C$1:$I$1,MATCH(TRUE,ALL!C2:I2<>0,0))
At the moment the aforementioned formula does this job to an extent, where if it finds <>0 value in a row it will return header from this specific column. The issue is that the ROW (as above C2:I2) needs to be specified.
I need to vlookup values in the column "A" in sheet "ALL" and based on that, look at corresponding rows between C:I and if the value in that specific row is <>0 then return heading value.
So, in green I would need a formula to pick up numbers from "Data Source" headings, based on value 1 or any value <>0. I'm guessing it all leads somehow to some sort of "vlookup" hybrid.
Any ideas how to combine vlookup in it?
Thanks
If there can only be one '1' per row, I was thinking of this
=SUMIF(INDEX(B:E,MATCH(G2,A:A,0),0),">0",$B$1:$E$1)
Otherwise if there can be more than one '1'
=INDEX($B$1:$E$1,MATCH(TRUE,INDEX(B:E,MATCH(G2,A:A,0),0)>0,0))
to match the first value greater than zero, in this case entered as an array formula.
A simple =SUMIF() formula will do, no other convoluted INDEX() and MATCH() nested formulas required.
Let's presume we have a data-table that starts at B2 and end at
F6, like this:
So now, to comprehend the solution, here's the syntax of SUMIF() formula (Function):
=SUMIF( range, criteria, [sum_range] )
So, what we want to do is:
go over the range of C3:F3 (and each other respective row)
the criteria to when to sum, is when this range contains 1
and we want to sum_range (sum up) fixed array of numbers, so $C$2:$F$2
So the result is (for row 3):
=SUMIF(C3:F3,1,$C$2:$F$2)
and we drag the formula down, producing expected result:
PS: I think this illustrates the point very well, as to why it's important to declare not only what your formula is doing but also, what you're trying to as in whole as there often is a better (easier) way to implement something, that you might not have thought of.
In other words, follow the Minimal, Complete and Verifiable Example
I'm not sure how to phrase this hence the vague title.. sorry.
Here's my scenario.
Data
Table 1
Col A = Home Team
Col B = Away Team
Col C = Home Score
Col D = Away Score
What I would like to do is get an average of a teams last 3 scores in a single formula.
The issue is the team could appear in either column, home or away.
If the team is Col A - I need the value in Col C. If the team is in Col B - I need the value in Col D.
Any ideas are appreciated. I'm stumped.
Thanks
Just for interest, here's a shot at doing it with a single formula
=AVERAGE(INDEX(C1:D7,N(IF({1},LARGE(IF(A2:B7=F2,ROW(A2:B7)*3+COLUMN(A2:B7)),{1,2,3})/3)),
N(IF({1},MOD(LARGE(IF(A2:B7=F2,ROW(A2:B7)*3+COLUMN(A2:B7)),{1,2,3}),3)))))
Has to be entered as an array formula using CtrlShiftEnter and assumes data starts in column A
Edit
Not necessary to do division just for row so can simplify to
=AVERAGE(INDEX(C1:D7,N(IF({1},LARGE(IF(A2:B7=F2,ROW(A2:B7)),{1,2,3}))),
N(IF({1},MOD(LARGE(IF(A2:B7=F2,ROW(A2:B7)*3+COLUMN(A2:B7)),{1,2,3}),3)))))
This will be quite a ugly formula but it helps to get what you want, the average of the LAST three scores of a team:
In this example I have put the search value (Team2) in F9 (used in formulas)
Create a helper column and put this formula in it and drag it down (we need the rownumber of a hit in our future INDEX formula):
=IF(OR(A2=$F$9,B2=$F$9),ROW(A2),"")
Now we need to create a formula that will average the largest 3 numbers
=AVERAGE(INDEX(A1:D7,LARGE(E:E,1),MATCH($F$9,INDIRECT("A"&LARGE(E:E,1)&":B"&LARGE(E:E,1)),0)+2),INDEX(A1:D7,LARGE(E:E,2),MATCH($F$9,INDIRECT("A"&LARGE(E:E,2)&":B"&LARGE(E:E,2)),0)+2),INDEX(A1:D7,LARGE(E:E,3),MATCH($F$9,INDIRECT("A"&LARGE(E:E,3)&":B"&LARGE(E:E,3)),0)+2))
In this case the formula will return 4.33333
There is possibly a better way, however this one works :)
You could use COUNTIFS and SUMIFS to make a logical average calculation.
Formula in H4 below is:
=(SUMIFS(C:C,A:A,G4)+SUMIFS(D:D,B:B,G4))/(COUNTIFS(B:B,G4)+COUNTIFS(A:A,G4))
Another use of AVERAGEIFS with INDEX/AGGREGATE.
=AVERAGEIFS(INDEX(E:E, AGGREGATE(14, 7, ROW($2:$999)/((C$2:C$999=I5)+(D$2:D$999=I5)), 3)):F$999, INDEX(C:C, AGGREGATE(14, 7, ROW($2:$999)/((C$2:C$999=I5)+(D$2:D$999=I5)), 3)):D$999, I5)
Working from this spreadsheet: https://docs.google.com/spreadsheets/d/1aiZzzOFzPDrw_siMhL8XiNIp3q7f8nz58HvwBKn14uA/edit?usp=sharing
Trying to calculate sum of a column where value in another col is true: this works well, like this:
=SUMIF($B$5:$B$17,"NY",G5:G17)
I'd like to be able to calculate this but, also multiply the range in question by another variable, in column C (i.e. the "rate"), so that I get the sum of each number of hours in column G done by the resources in Col A, multiplied by the rate charged for each resource.
this obviously doesn't work, but this is the type of thing I'm looking for: =SUMIF($B$5:$B$17,"NY",G5:G17*(Corresponding value in Col C))
Any ideas?
SUMIFS will only accept a range so I don't think you can do it that way. The alternative is to use SUMPRODUCT.
In Google sheets:
=sumproduct((B5:B17="NY"),C5:C17,G5:G17)
Excel is slightly more picky: you have to coerce the inner bracket to a number, either
=sumproduct(--(B5:B17="NY"),C5:C17,G5:G17)
or
=sumproduct((B5:B17="NY")*C5:C17*G5:G17)
I have 2 columns in my spreadsheet, both contains some numbers, column A has list of all numbers, and column B has some of the numbers from column A, now i want to highlight those numbers in column A, which are in column B here's my scenario:
Column A Column B
20301316 20322063
20302140 20322451
20307329 20326125
20307557 20334858
20314386 20371898
20314840 30368489
20322451 30384472
20326125 30384510
20334858 30384531
20371898 30384661
Here
20322451
20326125
20334858
20371898
should get highlighted. i used vlookup for this but for some reason it's highlighting all the numbers, here's the formula i used inside Conditional Formatting: (considering column A has values between A1:A10 and B has B1:B10)
=NOT(ISNA(VLOOKUP(B1, A1:B10, 1, 0)))
Could anyone please help me with proper formula.
Vlookup returns a value. In this context it is not the best formula to use, especially if you use it to return the value that you are looking up.
MATCH() is a much better fit for this scenario.
=MATCH(A1,$B$1:$B$10,0)
No fuffing around with ISNA() or wrapping in NOT() required. If it's a match it returns a number and will get formatted. If it's not a match, it won't get formatted.
It looks like you got the formula a bit backwards as it's looking in column A for values from column B. Try this instead:
=NOT(ISNA(VLOOKUP(A1,$B$1:$B$10,1,FALSE)))
Also, note that I made the lookup range an absolute reference by adding dollar signs.
Really though, I'd prefer a COUNTIF formula for this, just because I think it's more obvious:
=COUNTIF($B$1:$B$10,A1)>0
I have a question regarding the RANK function in MS Excel 2010. I have a large worksheet whose rows I want to rank based on the values in a column. These values can be positive or negative. I found helpful advice here which explains how to rank the values in a column while excluding all values that equal zero from the ranking and the ranking count. They use the following formula:
IF(O24<0, RANK(O24,$O$24:$O$29) - COUNTIF($O$24:$O$29,0), IF(O24=0, "", RANK(O24,$O$24:$O$29)))
This works great, but it would be even better if I could rank the values only if a corresponding value in the same row but a different column meets certain criteria.
Is something like this possible and how would I do it? How would I update the example formula above to make the change work? Thank you very much in advance for your help.
P.S.: I tried putting in a table but it didn't really work, sorry...
You can use COUNTIFS function to rank based on a condition in another column, e.g. this formula in row 24 copied down [edited to include extra IF)
=IF(O24=0,"",IF(N24="x",COUNTIFS(O$24:O$29,">"&O24,O$24:O$29,"<>0",N$24:N$29,"x")+1,""))
That will rank high to low where column N = "x", ignoring zero values
See this example columns N and O contain random values - press F9 to re-generate new random values and formula results in column Q will change accordingly
It is certainly possible to keep creating more complex formulas whenever you're adding new criteria on which to rank. However by creating intermediary columns with single-step formulas, you'll make your spreadsheet easier to comprehend and easier to add new criteria or edit the existing.
My suggestion is to create a column that excludes the zero's (let's assume this is in column P): =IF(O24 = 0, "", O24)
Then in column R, to eliminate negative values (this step is unnecessary, but your original formula does something similar): =IF(P24 = "", "", P24 - MIN(0, MIN($O$24:$O$29)))
Now in column S, add your newest criteria: =IF(OR(R24="", [enter newest criteria here]), "", R24)
Finally, column T performs the ranking of only the selected rows: =IF(S24="", "", RANK(S24, S$24:S$29))
If exposing columns P, R and S is bothersome, you can always hide them.
A rewording of the answer from barry houdini, using table format.
Value_Col is the column with the values to rank. Group_Column is the column with the group by values, to rank within groups
=COUNTIFS([Value_Col], ">"&[#[Value]], [Value_Column],"<>0", [Group_Column], [#[Group]]) +1