match merge for repeated measures in excel - excel-formula

I haven't been having much luck with this so I can hopefully get some help (I feel like there's an easy answer out there but don't seem to have landed on it)
I have multiple rows per ID number (160 per person based on trials of a cognitive task) and I want to keep all of the rows but attach a new column to the end of my dataset that will be the same for every participant which I have matched per subject ID
subj_index Block subj_index SUIPRONE
1 C1 1 1
1 C1 2 3
2 C2
2 C2
I just want to append a column to the first two columns that matches subject index and if that match is true, insert value of suiprone. I just need to scale this up over thousands of rows. Any suggestions?
subj_index Block SUIPRONE
1 C1 1
1 C1 1
2 C2 3
2 C2 3

Assuming subj_index, Block, subj_index, and SUIPRONE are columns A, B, C, and D, respectively, the I believe you are looking for the following in E2:
=IF(A2=C2,D2,"")
Then just drag down using the box in the lower-right corner.

Related

Displaying a label, sorted in a third column pulled from the first column according to data in the second column? i.e. Ranking

Imagine you have spreadsheet with data in a fixed # of contiguous rows.. let's say row 1 through row 20
Now let's say you have 3 columns of interest.
A, B and C
Column A is a label column.. the data in there are just string labels.. let's say types of canned food.. Tuna, Spam, Sardines, etc.
Column B is our number column.. let's say it is prices. e.g. 2 for Tuna, 5 for Spam and 3 for Sardines. These prices can change often very rapidly.. ok so prices are not the best example but let's imagine that prices change rapidly.
Now Column C is where we want to put the formula.
I would like to have a formula in Column C that will pull the labels from Column A, based on their prices in column B and rank them from highest to lowest.. that is C1 would calculate to "Spam", C2 to "Sardines" and C3 to "Tuna"
right now there are 20 rows of data.. but maybe at some other point there might be 30 or 6 or 40, etc.
So can someone help me out with the formula or at least explain what functions I need to use and the general idea involved? thanks
=IF(A2:A200<>"";SORTBY(A2:A200;B2:B200;-1);"")
You can simply use SORT formula. In this case =SORT(A1:B1000,2,-1) where A1:B1000 is range to be sorted, second parameter 2 is column number from range to sort by, 3rd parameter for order (-1 is desceding).
Place formula in C1 and you will get spilled array.

Determine the max value of a group, and display that row

I've got a few thousand rows in an excel spreadsheet, which (simplified) looks like this:
ID Category Animal Version Value
100 A Dog 1 20
100 B Cat 2 50
100 C Dog 3 50
200 A Dog 1 100
200 A Cat 2 100
300 B Cat 1 80
400 C Dog 1 80
I need to have the row with the highest/max version for each group of ids listed.
So in other words, I'd want these showing:
ID Category Animal Version Value
100 C Dog 3 50
200 A Cat 2 100
300 B Cat 1 80
400 C Dog 1 80
Is this possible?
Finding and showing the maxima/minima for grouped data with a single formula in only one cell can be done with the following formula:
=UNIQUE(FILTER(MyArray,MMULT(((ValueRange>TRANSPOSE(ValueRange))+(ValueRange=TRANSPOSE(ValueRange))-(GroupRange=TRANSPOSE(GroupRange)))*(GroupRange=TRANSPOSE(GroupRange)),SEQUENCE(ROWS(GroupRange),1,1,0))=0),FALSE,FALSE)
For an example, see this screenshot: Link
The output automatically adjusts for any number of groups in the data array.
With the operator > used in the formula, it will return the maximum. By using < it will return the minimum.
Note that the UNIQUE() function will only show distinct rows for each group maximum (see group 'Alpha' in screenshot).
If there is more than one maximum in a group and more than just the group and value column, the UNIQUE() function will show all distinct rows taking into account all columns (as can be seen for group 'Alpha' and 'Gamma' here: Link).
You can use the Advanced Filter with a formula criteria:
=D9=AGGREGATE(14,6,1/(A9=Table1[ID])*Table1[Version],1)
where D9 is the location of the first entry in the Value Column
Before applying Filter
After applying Filter
Suppose your data is in range A1:E8,
In cell A11, put in the following formula to find unique ID, drag it down until there is a #N/A error:
=INDEX($A$2:$A$8,MATCH(0,INDEX(COUNTIF($A$10:A10,$A$2:$A$8),0),0))
In cell B11, put in the following formula and drag it down to find the latest Version:
=AGGREGATE(14,6,$D$2:$D$8/($A$2:$A$8=A11),1)
In cell C11, D11 and E11, put in the following formulas respectively and drag them down to find the corresponding Category, Animal and Value:
=INDEX($B$2:$B$8,MATCH(1,INDEX(($A$2:$A$8=A11)/($D$2:$D$8=B11),0),0))
=INDEX($C$2:$C$8,MATCH(1,INDEX(($A$2:$A$8=A11)/($D$2:$D$8=B11),0),0))
=INDEX($E$2:$E$8,MATCH(1,INDEX(($A$2:$A$8=A11)/($D$2:$D$8=B11),0),0))
Let me know if there is any question. Cheers :)
For a list without duplicates you can put this in cell G2 ARRAY-FORMULA: CTRL + SHIFT + ENTER
=IFERROR(INDEX(A:A,MATCH(1,(COUNTIF(G$1:G2,A$1:A$99)=0)*(A$1:A$99<>""),0)),"")
This gives you a list with unique ID's. Now you can use the max formula to get the max version number of each ID. ARRAY-FORMULA: CTRL + SHIFT + ENTER
=MAX(IF($A$2:$A$2000=G3,$D$2:$D$2000,0))
The rest can be done with INDEX/MATCH formulas.

A function that will lookup a reference

Before I get started thanks for taking your time and helping.
This is what my worksheet looks like:
Row # B C D E F
2 1 Product 1 B2 B3 B4
3 2
4 6
5 1 Product 2 B5 B6
6 5
7 4 Product 3 B7
I was trying to follow this formula: (The best answer one or green check mark) return values from multiple matching rows
I got all the way to the =IFERROR(INDIRECT(lookups!H5),"") but can not get this to work.
What I am tying to do is order the numbers in Column B to go to the right of the product. Which I was able to get the column it is in (B) and the row number it is in (B2). I would like to change the value (B2) to the number that is there.
I would like it to look like this:
Row # C D E F
2 Product 1 1 2 6
3
4
5 Product 2 1 5
6
7 Product 3 4
If someone could help explain this to me or find a better way that would be great.
Not sure what is to happen to columnB but if you replace B with "="B throughout columns D:F then select each of these in turn and apply Text to Columns with Tab as the delimiter the 'cell references' convert to formulae referring to the values in B. If you want to delete columnB copy D:F and Paste Special, Values over the top.

Sum the values in Excel cells depending on changing criteria

In an Excel spread sheet I have three columns of data, the first column A is a unique identifier. Column B is a number and column C is either a tick or a space:
A B C
1 d-45 150 √
2 d-46 200
3 d-45 80
4 d-46 20 √
5 d-45 70 √
Now, I wish to sum the values in column B depending on a tick being present and also relative to the unique ID in column A. In this case rows 1 and 5. Identifying the tick I use
=IF(ISTEXT(C1),CONCATENATE(A1))
&
=IF(ISTEXT(C1),CONCATENATE(B1)).
This leaves me with two arrays of data:
D E
1 d-45 150
4 d-46 20
5 d-45 70
I now want to sum the values in column E depending on the ID in column D, in this case row 1 and 5. I can use a straight forward SUMIFS statement to specify d-45 as the criteria however this unique ID will always change. Is there a variation of SUMIFS I can use?
I also wish to put each new variation of ID number into a separate header with the summed totals underneath, that is:
A B
1 d-45 d-46
2 220 20
etc...
You can try this:
To get the distinct ID's write (in H1 then copy right):
This one is an array formula so you need Ctrl Shift Enter to enter the formula
=INDEX($A$1:$A$5;SMALL(IF(ROW($A$1:$A$5)-ROW($A$1)+1=MATCH($A$1:$A$5;$A$1:$A$5;0);ROW($A$1:$A$5)-ROW($A$1)+1;"");COLUMNS($A$1:A1)))
Now to get the sum (H2 and copy right)
=SUMPRODUCT(($A$1:$A$5=H1)*ISTEXT($C$1:$C$5)*$B$1:$B$5)
Data in the example is in A1:C5
Depending on your regional settings you may need to replace ";" field separator by ","
Try this,
SUMIFS
=SUMIFS(B1:B5,A1:A5,"=d-45",C1:C5,"<>")
where "<>" means that the cell is not empty...

Top third, next third of items by sales

I have an excel sheet as shown below. I need to get the top third/ next third items by sales count. Is there a way to get this done in Excel?
Item Count
1 100
2 90
3 80
4 60
5 55
6 50
7 45
8 35
9 25
Dividing into 3 buckets, so 540/3 = ~180 items in each –
Bucket 1 – Items 1 and 2 (Count = 190)
Bucket 2 – Items 3, 4 and 5 (Count = 195)
Bucket 3 - Items 6, 7, 8, 9 (Count = 155)
There are multiple ways to achieve this. Assuming that your Item and Count data are in columns A and B, then the shortest path is to use the following formula in cell C2:
=ROUND(3*SUM($B$2:$B2)/SUM($B$2:$B$10),0)
After entering that into C2, select that cell and drag down the right-bottom corner of the cell all the way to the last row. Note the $ sign that is "missing" on purpose before the second 2. That takes care of the auto-fill behavior needed when dragging down the corner.
If you are allowed to use a helper column, you can create a computationally more efficient method using following layout:
If you want to, you can hide column C. It contains cumulative values of the different sales counts. Cell C1 is set to 0, cell C2 contains the formula =$C1+$B2. Column D then approximates the buckets by using the formula =ROUND(3*$C2/$C$10,0) in cell D2, and then again dragging down the bottom-right corner. This might be the better approach if you have many rows on your sheet.
Note that both solutions yield the same results. The value in one or more buckets could become 0, which is not exactly right. That can be avoided using ROUNDUP in stead of ROUND, but since you have not indicated clearly where you want the boundaries of the buckets to fall exactly in different situations, I thought I leave that as an exercise to you :-).

Resources