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)
Related
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)))
I've been struggling with this for hours now, and I just can't figure out how to add a second criteria to my formula.
I have this table:
device # date plan used
5 12/2/2017 A
8 12/3/2017 A
9 12/4/2017 B
56 12/2/2017 B
588 12/5/2017 C
56 12/2/2017 C
I am trying to get the number of unique devices, that are on plan A and have the date 12/2/2017. Here is the formula I have now.
=SUM(IF(FREQUENCY(IF(D2:D116005=G2,B2:B116005),IF(D2:D116005=G2,B2:B116005))>0,1))
I have successfully counted the unique devices with the criteria of being on 12/2/2017, but I just cannot figure out how to add additional criteria (i.e. on plan A). The G2 cell is where I am storing the date 12/2/2017 for comparison.
I have tried using IF(AND(.. but I can't seem to get it to work.
Could someone help me with this? Let me know if more information is needed.
Thank you,
Staci
You can use multiplication to return a 1 (equivalent to TRUE) if both match:
IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],"")
Putting it all together:
=SUM(IF(FREQUENCY(IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],""),IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],""))>0,1))
Remember this is an array formula so must be confirmed by holding down ctrl + shift while hitting enter
I used structured references and named cells, but you should be able to transfer to your cell references.
in column D, starting in cell D2, put this formula:
=if(and(B2=date(2017,12,2),c2="A",countif($A$2:A2,A2)=1),1,0)
then just sum that column to get your answer.
Assuming plans in column F try this revised array formula:
=SUM(IF(FREQUENCY(IF(D2:D116005=G2,IF(F2:F116005="A",B2:B116005)),B2:B116005),1))
confirmed with CTRL+SHIFT+ENTER
Notice that it's not necessary to repeat the IF functions I the "bins array" argument of the FREQUENCY function
No formulas required: Simply whip up a PivotTable of the data, put Device and Date in the Rows field, and drag Plan to the Values area, which will automatically be given the COUNT treatment by the PivotTable because it's a text field.
I'm having some issues with a formula. In the formula I'm trying to sum the number of items in column E based upon the condition in column C.The formula I've used is, (which is working correctly.)
=SUM(COUNTIFS('Sheet1'!E:E,C86,'Sheet1'!C:C,{"A","B","C","E1","E2","F","G","X","T"}))
However in the next cell I'm trying go a bit further and trying to count the number of "Yes" and "NA" in column R based upon the condition in column E and Column C. The formula I've used is -
=SUM(COUNTIFS('Sheet1'!E:E,C86,'Sheet1'!C:C,{"A","B","C","E1","E2","F","G","X","T"},'Sheet1'!R:R,{"Yes","NA"}))
This time the formula is counting only "A" in column C and "Yes" in column R. It'll be great help if someone can point what mistake I'm making with this formula.
Thanks in advance!
Best Regards,
gmainak
Change 'Sheet1'!R:R,{"Yes","NA"} to 'Sheet1'!R:R,{"Yes";"NA"}
You can only do two arrays and one needs to be vertical ; and the other horizontal ,:
=SUM(COUNTIFS('Sheet1'!E:E,C86,'Sheet1'!C:C,{"A","B","C","E1","E2","F","G","X","T"},'Sheet1'!R:R,{"Yes";"NA"}))
Please pardon my poor explanation of my problem, any insight would be greatly appreciated.
I am using an average in excel that begins at a fixed cell and fills down.
For example: column B contains values, and column C contains the formula =AVERAGE($B$1:B1) filled down, so at row 10 the formula is =AVERAGE($B$1:B10)
I am wondering if there is a way to calculate this average that will "reset" when the value in the column A changes. Getting a formula for whether column A changes is easy using an IF function but I don't know how to change the reference cell when the average "resets." I attempted to attach an image with the formulas but I do not have 10 reputation so here is a link to a short example sheet:
https://drive.google.com/file/d/0BymZUcneHsYgUnRoYkRkdnJYbmM/view?usp=sharing
I would prefer do accomplish this without VBA if possible.
Thank you very much.
EDIT: would it be possible to have a count function next to the data column that starts over when column A switches from "A" to "B" (or "B" to "A"), then I could simply use an average offset with the resulting value to get the desired average?
You should use the =AVERAGEIF function.
=AVERAGEIF($A$1:A1,A1,$B$1:B1)
Here's how I ended up solving this:
I used =ROW()-MAX(INDEX((A$1:A2<>A2)*ROW(A$1:A2),0 to count down until "A" changed to "B" or vice versa, then used =ROW()-MAX(INDEX((A$1:A2<>A2)*ROW(A$1:A2),0 to average the data with the offset calculated in the previous formula.
Note that the data was still in column B, with "A" or "B" in column A, and these two formulas were placed in I and J, respectively
Thank you very much for all your help
You can use Indirect to resolve a custom range. Since values in "A" can come multiple time in distinct block, you will have to add an extra column to keep track of the starting row of each range :
(starting from row 2, [C1] = 1)
=IF(A2<>A1,ROW(A2),C1)
the result will be in column "D" :
=AVERAGE(INDIRECT("B"& C1 &":B"&ROW(A1)))
I am trying to use vlookup to return information based on the maximum value of a cell within a range.
I have a table in which each row is a sports team and each column is a weekly points total.
I have 2 cells that show the highest points scored in the current week and the name of the team that scored them.
The team name is generated by the formula
=VLOOKUP(MAX(Admin!G3:G16),Admin!G3:K16, 5, FALSE)
This works fine.
I also wish to have 2 cells that show the highest weekly points total ever achieved, along with the name of the relevant team.
However, I can not amend the above formula to work on a range instead of a row, and no matter what I do, it always returns an #N/A result for the team name.
The most logical formula I tried is
=VLOOKUP(MAX(Admin!N18:BE31),Admin!N18:BG31, 47, FALSE)
where columns N through BE are the weekly scores (which are generated by a formula, if that makes a difference?) and column BG contains the team names.
Maybe this function isn't designed to work on a range in the same way as a column, maybe I have made an error in the formula, or maybe there is another better way to retrieve the information?
I just can't work it out, so am sincerely hoping somebody can point me in the right direction.
Many thanks for any assistance.
Indeed, the vlookup function works only with columns. So does the match function. You need here to use a formula array (hit "Ctrl + Shift + Enter" once you've typed the function instead of the usual "Enter").
I came to the following function
=INDEX($A$2:$A$9,SMALL(IF($B$2:$D$9=$H$2,MATCH($A$2:$A$9,$A$2:$A$9,0),""),1))
with :
1) $A$2:$A$9 = The teams
2) $B$2:$D$9 = The weekly scores
3) $H$2 = the maximal score ever achieved
You just need to adapt the ranges and hit "Ctrl + Shift + Enter"
PS: If 2 teams achieved this score, then only the first one will show