Calculate Average Across Multiple Pairs/Permutations - excel

Not sure how to use AVERAGEIFS or a combination of SUMIFS and COUNTIFS to efficiently solve this, or some other function.
Basically, assume I have the following dataset of trip times between certain points
Start End Trip Time(Minutes)
A B 12
A B 8
B A 9
B A 2
A C 15
C A 5
C B 11
C B 9
B C 7
A B 16
A D 18
D C 21
E A 11
X Y 19
There could be n number of points in the dataset, but assume we are only interested in the average trip time of all trip pairs between 4 cities (A,B,C,D). i.e. AB, BA, AC, CA, BD, DB, etc. but not AA, BB, CC, DD.
How can I go about averaging the trip time between all these permutations? Much help would be appreciated..thank you!

Not very pretty, but using a named range "CITIES" (A20:A23 below)
In E3 to arrange as unique pairs regardless of direction (and fill down):
=IFERROR(INDEX(CITIES,MIN(MATCH(A3,CITIES,0),MATCH(B3,CITIES,0)))&":"&
INDEX(CITIES,MAX(MATCH(A3,CITIES,0),MATCH(B3,CITIES,0))),"")
In F3:
=IF(E3<>"",AVERAGEIFS($C$3:$C$16,$E$3:$E$16,E3),"")
You can copy/paste values/remove duplicates to get the unique pairs.

Related

How can I count the number of values by group in excel

I was wondering if there was a way to count the number of values by category. Example:
A 3
A 3
A 3
B 4
B 4
B 4
B 4
C 5
C 5
C 5
C 5
C 5
D 2
D 2
What is happening there is that there are 5 categories "A, B, C, D" and there are different counts of it. Duplicate values. I would like to create a new column and output the number of times it occurs in a different column as shown above. Please no VBA as i don't know it.
Try this...
=IF(A2<>A1,COUNTIF(A:A,A2),"")

Get number of unique values from a column with multiple criteria

I am working on an Excel problem. Here is my questions:
name department year
a cs 5
b cs 8
c cs 2
d cs 3
a cs 1
b cs 10
a ma 7
f ma 8
h ma 2
The question is to get the number of unique name (only occur once) with department="cs" and year >2, in this case the result is 2 (i.e,"a" and "d" only occur once).
I knew the formula below might do the trick, but did not know how to put the range filtered by department="cs" and year >2 into the below formula.
=SUM(IF(COUNTIF(range, range)=1,1,0))
Use SUMPRODUCT:
=SUMPRODUCT((COUNTIFS(A:A,A2:INDEX(A:A,MATCH("zzz",A:A)),B:B,"cs",C:C,">2")=1)*(B2:INDEX(B:B,MATCH("zzz",A:A))="cs")*(C2:INDEX(C:C,MATCH("zzz",A:A))>2))

Excel Formula comparing two columns

Below is a sample of the data I have. I want to match the data in Column A and B. If column B is not matching column A, I want to add a row and copy the data from Column A to B. For example, "4" is missing in column B, so I want to add a space and add "4" to column B so it will match column A. I have a large set of data, so I am trying to find a different way instead of checking for duplicate values in the two columns and manually adding one row at a time. Thanks!
A B C D
3 3 Y B
4 5 G B
5 6 B G
6 8 P G
7 9 Y P
8 11 G Y
9 12 B Y
10
11
12
11
12
I would move col B,C,D to a separate columns, say E,F,G, then using index matches against col A and col B identify which records are missing.
For col C: =IFERROR(INDEX(F:F,Match(A1,E:E,0)),"N/A")
For col D: =IFERROR(INDEX(G:G,Match(A1,E:E,0)),"N/A")
Following this you can filter for C="N/A" to identify cases where a B value is missing for an A value, and manually edit. Since you want A & B to be matching here col B is unnecessary, final result w/ removing col B and C->B, D->C:
A B C
3 Y B
4 N/A N/A
5 G B
6 B G
7 N/A N/A
Hope this helps!

Count using a category and Median using a category

I have two problems here.
The data is as follows:
Col X Col Y
A 10
A 12
A
A 32
B 11
B 31
B 9
C 8
C 7
C 3
D 1
D 3
D
D 9
I need to do the following:
Count the entries in Column Y using the Categories in Column X, for ex. A repeats 4 times in Column X but has 3 total corresponding numbers in column Y, i need the 3 count of the numbers in Column Y.
Calculate the median of those numbers using the category (excluding blanks whenever there are, not to be assumed as 0 by the code), for ex. Median for A is 12, Median for D will be 3.
Please help.
So 1 is:
=COUNTIFS(X:X,"A",Y:Y,"<>")
2 is:
=MEDIAN(IF(X:X="A",IF(NOT(ISBLANK(Y:Y)),Y:Y)))
Hold down ctrl + shift when you're using 2 as it's an array formula

How to sum constants if the values of a row contian a specific value in excel?

I have the following row in excel:
12 4 12p 12a 12b
I need to sum this elements with their values from the legend.
12 = 12;
4 = 4;
12p = 12,5;
12a = 12,2;
12b = 12,3;
For example
=12 + 4 + 12,5 + 12,2 + 12,3
Any ideas?
If you have all the elements within one cell as a single string of text, the optimal approach would be to start by using text-to-column to split them up. So you'll have 12 in A, 4 in B, 12p in C, 12a in D, 12b in E. If that's not an option, I can show you string manipulations that can be an alternative.
You'll need to turn your "legend" into a look-up table, (perhaps on sheet2?), with column A having: p, a, b, etc.. and column B having the relative values.
Once that's done, place this formula on sheet1, in F column:
=A2+IFERROR(VLOOKUP(RIGHT(A2),Sheet2!$A:$B,2,FALSE),0)
Then drag it to the right 5 times, and it will have the values of the elements "translated".
You can sum the translated range easily.

Resources