median by date excel - excel

My current (simplified) data set is shown below. It has the date and a column called x.
I want to compute the median for each different date, but still list them line by line, like seen in my desired data set below.
I have tried to combine the median and if function to do this, however I can't get it to work line by line like my desired result below.
How can I achieve this on excel? Thanks.
current
desired
date x median
1/01/2021 6 8
1/01/2021 8 8
1/01/2021 9 8
1/01/2021 5 8
1/01/2021 8 8
2/01/2021 4 7
2/01/2021 4 7
2/01/2021 7 7
2/01/2021 7 7
2/01/2021 9 7
3/01/2021 8 4
3/01/2021 2 4
3/01/2021 6 4
3/01/2021 5 4
3/01/2021 2 4
3/01/2021 3 4
4/01/2021 5 3.5
4/01/2021 2 3.5
5/01/2021 8 4
5/01/2021 4 4
5/01/2021 3 4

Try below array formula. Array formula needs to enter by CTRL+SHIFT+ENTER.
=MEDIAN(INDEX(B:B,MIN(IF($A$1:$A$22=A2,ROW($A$1:$A$22),""))):INDEX(B:B,MAX(IF($A$1:$A$22=A2,ROW($A$1:$A$22),""))))
If you have Excel-365 then can use simplified formula like below.
=MEDIAN(FILTER($B$2:$B$22,$A$2:$A$22=A2))

Related

I would like to change the color of a row if two rows with the same contents in one column differ in value in another column

So I have been working on this for a while now but can't seem to get it.
Essentially if the contents in column C (NAME) match, I need to see if their rows match value in column K (Y/N).
If they differ in Column K, the entirety of both rows should turn yellow.
Additionally, I would like that if they match in column C, and they are both "No" in column K, both rows turn red.
I believe this to be done as a custom rule in conditional formating but this is all I could come up with, unsure how to proceed. (I am operating in Google Sheets since its a shared doc but I can manage with Excel.
=AND($C1<>"",COUNTIF($C:$C,$C1)>1, COUNTIFS($C:$C,$C1,$K:$K,$K1)>0)
Some sample data; here both of Jane's rows should be red and Alex's rows should be yellow:
43425.45184 NA Morg 4 7 5 6 7 6 6 Yes
43423.65523 NA Alee 4 9 8 7 8 8 9 Yes
43425.4461 NA Alee 4 8 8 8 8 8 8 Yes
43420.93822 NA Bale 4 8 7 7 6 10 7 Yes
43424.40326 NA Jane 5 9 8 8 9 9 7 No
43430.45766 NA Jane 5 10 10 10 10 10 10 No
43424.51362 NA Alex 3 8 8 8 4 6 6 Yes
43430.48237 NA Alex 4 6 3 5 2 7 6 No
43428.76583 NA Allison 4 8 8 8 7 6 8 Yes
Think these two will do it.
=AND(COUNTIF($C:$C,$C1)=2,COUNTIFS($C:$C,$C1,$K:$K,"No")=2)
Above is fill red
=AND(COUNTIF($C:$C,$C1)=2,COUNTIFS($C:$C,$C1,$K:$K,"Yes")=1)
Above is fill yellow

SUM function produces a #VALUE! error when using in array formula

I have the following values in a sheet (in A1:G10) range:
1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5
6 6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8
9 9 9 9 9 9 9
10 10 10 10 10 10 10
I need to calculate the sum of differences of values between two rows in the array above when both rows are defined by row numbers, for example: sum of differences of values between 10-th and 1-st rows, between 9-th and 2-nd rows and so on. Row numbers I defined in J1:K10 range:
1 10
2 9
3 8
4 7
5 6
6 5
7 4
8 3
9 2
10 1
Then I selected L1:L10 range, and in the first cell of it I entered the following formula:
=SUM((OFFSET(A1,INDEX(K1:K10,ROW(K1:K10)-ROW(K1)+1)-1,0,1,7)-OFFSET(A1,INDEX(J1:J10,ROW(J1:J10)-ROW(J1)+1)-1,0,1,7)))
and then pressed CTRL+SHIFT+ENTER so the formula is enterd as an array formula. And the formula returned a #VALUE! error for each cell in the range.
I tried to evaluate the formula, and it evaluates correctly except the last step: SUM({9,9,9,9,9,9,9}) becomes a #VALUE!
Here is a screenshot of the sheet for clarity:
What I'm doing wrong? Please suggest.
use SUMPRODUCT in L1:
=SUMPRODUCT(INDEX($A$1:$G$10,J1,0)-INDEX($A$1:$G$10,K1,0))
and copy down.

count with multiple crieria

I am stuck with a problem. Lets say I have the following data in range A1:K4
row1 1 2 3 4 5 6 7 8 9 10
row2 2 3 4 5 6 7 8 9 10 11
row3 3 4 5 6 7 8 9 10 11 12
row4 3 5 6 7 8 9 10 11 12 13
And the following data in range N1:P4
1 2 3
2 3 4
3 4 5
11 12 13
I want formulas in range R1:R4
The desired output should be R1=1, R2=2, R3=3, R4=1
i am trying to evaluate first set of numbers 1 2 and 3 and check in every row from row1 to row4 and find out how many rows matched all 3 numbers and the put the value in cell R1.. continue this for all 4 sets of number. Can someone help me with a formula?
Thanks
You could use this formula in R1 copied down to R4
=SUMPRODUCT((MMULT(COUNTIF(OFFSET(B$1:K$4,ROW(B$1:K$4)-ROW(B$1),0,1),N1:P1),{1;1;1})=3)+0)
although I've cheated a bit, there, because {1;1;1} is variable based on the number of columns in N1:P1 (and so is the 3), so for a more generic version (which would allow N1:P1 to be any size row) you can use this "array formula"
=SUM((MMULT(COUNTIF(OFFSET(B$1:K$4,ROW(B$1:K$4)-ROW(B$1),0,1),N1:P1),TRANSPOSE(COLUMN(N1:P1)^0))=COLUMNS(N1:P1))+0)
confirmed with CTRL+SHIFT+ENTER

Excel - calculating the median without removing duplicates

I have a table that looks like this:
ID Total
3 3
3 3
3 3
4 11
4 11
4 11
4 11
4 11
4 11
6 9
6 9
7 13
7 13
7 13
7 13
7 13
7 13
7 13
7 13
7 13
7 13
7 13
7 13
7 13
I would like to calculate the median of column B (Total), excluding duplicate combinations of columns A and B. This could be achieved by constructing a table as below, and calculating the median from that table.
ID Total
3 3
4 11
6 9
7 13
Is there any way of obtaining the median without having to go through this process of manually deleting duplicates?
=MEDIAN(IF(FREQUENCY(MATCH(A2:A25&"|"&B2:B25,A2:A25&"|"&B2:B25,0),ROW(A2:A25)-MIN(ROW(A2:A25))+1),B2:B25))
There is a way with two additional columns. The first column is concatenation of ID and Total, the second counts occurences of each individual combination. Then you just do the median on those rows where the combination occurs for the first time.

Sort a group of data based on a column

I have an input file that contains following data:
1 2 3 4
4 6
8 9
10
2 1 5 7
3
3 4 2 9
2 7
11
I'm trying to sort the group of data based on the third column and get such an output:
2 1 5 7
3
1 2 3 4
4 6
8 9
10
3 4 2 9
2 7
11
Could you tell me how to do so?
sort -nk3r
will sort in reverse order based on 3rd column. Note however, that this outputs
2 1 5 7
1 2 3 4
3 4 2 9
10
11
2 7
3
4 6
8 9
because of the way bash sort functions, and this produces a different result than the output you posted, but correct according to the question.

Resources