How to average difference between many value pairs by index - excel

and thanks for your help! Without helper columns/rows I'm trying to find the average difference in LVEDi between first and last visits of the patients.
E.g., by hand you would work it out as:
(diff for patient a + diff for pt b + diff for pt c)/3 =
((55-45) + (40-31) + (25-31))/3 =
(10 + 9 + (-6))/3 =
13/3 =
4.333
I'm sure the answer involves indexing with an array function, but I can't get started on how to tackle it!
Any help?
Thanks!
A | B | C | D | E
01 Patient ID | Date | First-Last | LVEDi | LOTS of similar cols
02 a | 3/3/03 | LAST | 55
03 a | 1/1/01 | FIRST | 45
04 a | 2/2/02 | | 65
05 b | | |
06 b | 3/2/16 | LAST | 40
07 b | | |
08 b | | |
09 b | 2/1/12 | FIRST | 31
10 c | 1/7/14 | LAST | 25
11 c | | |
12 c | 2/2/03 | FIRST | 31
13 c | 2/2/08 | | 46

You can use the * as and AND criterion in arrays, so with MATCH you search for the instance, where both conditions multiplied are TRUE (i.e. 1). The rest is just filling in your calculation:
{=((INDEX(D2:D13,MATCH(1,(A2:A13="a")*(C2:C13="LAST"),0))-INDEX(D2:D13,MATCH(1,(A2:A13="a")*(C2:C13="FIRST"),0)))+(INDEX(D2:D13,MATCH(1,(A2:A13="b")*(C2:C13="LAST"),0))-INDEX(D2:D13,MATCH(1,(A2:A13="b")*(C2:C13="FIRST"),0)))+(INDEX(D2:D13,MATCH(1,(A2:A13="c")*(C2:C13="LAST"),0))-INDEX(D2:D13,MATCH(1,(A2:A13="c")*(C2:C13="FIRST"),0))))/3}
And remember to use CTRL + SHIFT + ENTER to enter the array.

Found a slightly less verbose method:
=SUM(SUMIFS(D:D,C:C,"LAST",A:A,{"a","b","c"})-SUMIFS(D:D,C:C,"FIRST",A:A,{"a","b","c"}))/3
EDIT 1
Building on Lukas' comment:
=(SUMIF(C:C,"LAST",D:D)-SUMIF(C:C,"FIRST",D:D))/COUNTIF(C:C,"LAST")

Related

Can you select the MIN row to display across all "Results Grid" values? (Generic Inquiry)

I have the following tables:
(Example data)
PMProjects
| ContractID | ContractCD | Customer |
| :-------- | :----------| :------- |
| 01 | PR00001 | ABC-Customer |
| 02 | PR00002 | XYZ-Customer |
PMTasks
| Task ID | Project ID| Task CD | Description |
| :--------| :---------| :---------| :-------- |
| 39 | 01 | 01 First | Zulu |
| 40 | 01 | 02 Second | Foxtrot |
| 41 | 01 | 03 Third | Delta |
| 42 | 01 | 04 Fourth | Alpha |
| 55 | 02 | 01 First | Zulu |
| 56 | 02 | 02 Second | Foxtrot |
| 57 | 02 | 03 Third | Delta |
| 58 | 02 | 04 Fourth | Alpha |
I have successfully joined PMTasks to PMProjects on PMProjects.ContractID = PMTasks.ProjectID.
And, I am grouping by PMProjects.ContractID
On the GI, I need to display the MIN TaskID row for each Project.
My GI - Aggregate Functions by MIN value
Result -
When I use the MIN value on the PMTasks.Description field it pulls the value "Alpha".
GI Results
| ContractID | ContractCD | Customer | Task ID | Task CD | Description |
| :--------- | :--------- | :----------- | :------- | :-------- | :---------- |
| 01 | PR00001 | ABC-Customer | 39 | 01 First | Alpha |
| 02 | PR00002 | XYZ-Customer | 55 | 01 First | Alpha |
Documentation - Aggregate Function Descriptions
I see from the documentation that the MIN aggregate function, "Returns the minimum value of all values of the group."
Has anyone found a way to join many-to-one in an Acumatica Generic Inquiry using the MIN (or MAX) value of a row?
Or to put it a different way - has anyone found a way to join one of many rows to a table and have the results grid display only the values from the same row?
I hope this makes sense. Please feel free to ask any clarification questions.
Thanks for any and all feedback.
Example GI related to the question. Please excuse the error under Results Grid - PMProjects.CustomerCD_Description does not need to be aggregated.
You need to add a group by PMContract.ContractID and then add the Min() function in the Data Field

Excel - How to countif within column B excluding duplicate values from column A?

The spreadsheet I am working with houses multiple duplicates for CLIENT_ID and I want to be able to count each CLIENT_ID only once, and then count the amount of a specified value within AGE_CATEGORY. Basically I want to exclude any duplicates and then countif.
| Column A | Column B |
+-----------+--------------+
| CLIENT_ID | AGE_CATEGORY |
| 1514 | 65 |
| 1517 | 65 |
| 1522 | 17 |
| 1519 | 37 |
| 1514 | 65 |
| 1516 | 28 |
| 1503 | 20 |
--- I would like for the count for people >=65 to be 2, since client# 1514 appears twice.
How can I do it?
What you need is first extract unique values from column A then count those IDs. As per my below screenshot use below formulas ExcelO365 formulas.
D2 =UNIQUE(A2:A8)
E2 =COUNTIF(A2:A8,D2#)
Create a list of unique age (category?) values — say, in Column D
— with “Data” → “Sort & Filter” → “Advanced (Filter)”. 
(Sort them if you want.) 
Enter
=SUM(--(FREQUENCY(IF(B$2:B$8=D2,A$2:A$8),A$2:A$8)>0))
into E2, press Ctrl+Shift+Enter,
and copy/drag down. 
This is the result:
| A | B | C | D | E |
---+-----------+--------------+--------------+--------------+-------+
1 | CLIENT_ID | AGE_CATEGORY | | AGE_CATEGORY | |
2 | 1514 | 65 | | 65 | 2 |
3 | 1517 | 65 | | 17 | 1 |
4 | 1522 | 17 | | 37 | 1 |
5 | 1519 | 37 | | 28 | 1 |
6 | 1514 | 65 | | 20 | 1 |
7 | 1516 | 28 | | | |
8 | 1503 | 20 | | | |
Based on this answer by SandPiper.
Assuming your data (to return values) is in A2:A8 and criteria is in B2:B8 use this ARRAY formula to check unique values >=65
=SUM(--(FREQUENCY(IF($B$2:$B$8>=65,MATCH($A$2:$A$8, $A$2:$A$8,0)),ROW($A$2:$A$8)-ROW($A$2)+1)>0))
Note for array formula you have to enter this formula with ctrl + shift + enter so that curly braces appear around the formula automatically.
Needless to say, you can change >=65 to your criteria accordingly. sample check see screenshot

Marking "Ambidextrous" in Excel

This is an example that illustrates my problem
So I have a table of participants, each with their own unique ID number. They all do a writing test and their time, in minutes, is recorded in the fourth column as an integer. Some patients have repeated the test, there is no maximum number of repeats.
+============+===========+===============+======+
| Patient ID | Hand Used | Ambidextrous? | Time |
+============+===========+===============+======+
| 01 | Right | Yes | 12 |
+------------+-----------+---------------+------+
| 01 | Right | Yes | 10 |
+------------+-----------+---------------+------+
| 01 | Right | Yes | 11 |
+------------+-----------+---------------+------+
| 01 | Left | Yes | 13 |
+------------+-----------+---------------+------+
| 01 | Right | Yes | 12 |
+------------+-----------+---------------+------+
| 02 | Right | No | 9 |
+------------+-----------+---------------+------+
| 02 | Right | No | 7 |
+------------+-----------+---------------+------+
| 02 | Right | No | 8 |
+------------+-----------+---------------+------+
| 03 | Left | Yes | 8 |
+------------+-----------+---------------+------+
| 03 | Right | Yes | 8 |
+------------+-----------+---------------+------+
I want the "Ambidextrous?" column to be a formula. I've been trying to accomplish this with INDEX() and MATCH(), to no avail. It needs to check the "Hand Used" column, if there is both a Right handed and Left handed test for a particular Patient ID, we say "Yes".
Use:
=IF(COUNTIFS(A:A,A2,B:B,IF(B2="Right","Left","Right")),"Yes","No")

Conditional count over rows over multiple criteria

I want to answer this question: How many patients have had more than 1 scan? Pseudocode:
Countif >1 (Ans = 2. Two patients have 2 or more scans)
For each Patient ID, count if "scan" nonblank (Ans: a=1, b=2, c=2, d=1)
A | B | C
01 Patient ID | Scan | Other data etc
02 a | |
03 a | 1/1/15 |
04 b | 2/2/15 |
05 b | |
06 b | 3/2/16 |
07 c | 1/3/14 |
08 d | 2/1/12 |
09 c | 1/7/14 |
10 d | |
This is easy to do for just one patient. I.e., =Countifs(A1:10,"a",B1:10,"<>"). How do you count this for all patients?
Help much appreciated!
You will require a helper column - refer the formula below
Helper column =IF(AND(COUNTIF($A$2:$A$10,A2)>1,NOT(ISBLANK(B2)) ),A2,"-")
=IF(COUNTIF(C2:C10,"-")>0,SUMPRODUCT(1/COUNTIF(C2:C10,C2:C10))-1,SUMPRODUCT(1/COUNTIF(C2:C10,C2:C10)))
The formula will need to be entered as an array (once copy and pasted while still in the formula bar hit CTRL+SHIFT+ENTER)
=SUM(--(FREQUENCY(IF(B2:B10<>"",MATCH(A2:A10,A2:A10,0)),ROW(A2:A10)-ROW(A2)+1)>1))
If you have a sheet with every patient you can add a column and use your formula =Countifs(A1:10,"patient_id",B1:10,"<>") to count the number of scans for each patient and then use the same type of formula to count every sum of scans that are greater than 1.
Patient sheet
A | B
01 Patient ID | Scans
02 a | =COUNTIFS(scans!A2:A10; A2;scans!B2:B10;"<>")
03 b | 2
04 c | 2
05 d | 1
06 e | 0
07 f | 0
Scan sheet
A | B | C
01 Patient ID | Scan | Other data etc
02 a | |
03 a | 1/1/15 |
04 b | 2/2/15 |
05 b | |
06 b | 3/2/16 |
07 c | 1/3/14 |
08 d | 2/1/12 |
09 c | 1/7/14 |
10 d | |
Where you want
=COUNTIF(patients!B2:B6;">1")

Excel: sort column with mixed numbers and letters?

I am working of the dataset in Excel that I obtained from an experiment. Since I needed some ratings (and I wanted the raters to be blind) I completely randomized the answers and now I can't put them back in order!
This is what I have:
1A
38R
22R
7A
41R
64A
etc...
And this is what I need in the end:
1A
2A
3A
...
99R
100R
101R
Thank you!
I have created two new columns (B and C in this case, as in the other example posted).
I have typed LEFT(A1,LEN(A1)-1) in column B to get the number; then =RIGHT(A1,1) in column C to get the letter; finally I can sort by B and C.
You will not get your desired output by sorting alphabetically, because 100R would come before 2A.
If your values will always be in the format of a number followed by a single character and will be at most 5 characters long, you can use #Scott Craner's formula =RIGHT("00000"&A1,5) to pad the left of your value with "0" so that you can alphabetize correctly. 100R will become 0100R. 2A will become 0002A. These will now alphabetize correctly.
Now you can simply sort your range by column B ascending alphabetically.
If you need more characters, just add as many zeroes as characters to the formula, and change the 5 in the formula to your new number of characters.
Here is an example excel file.
INPUT
+---+-----+-------+
| | A | B |
+---+-----+-------+
| 1 | 1A | 0001A |
+---+-----+-------+
| 2 | 38R | 0038R |
+---+-----+-------+
| 3 | 22R | 0022R |
+---+-----+-------+
| 4 | 7A | 0007A |
+---+-----+-------+
| 5 | 41R | 0041R |
+---+-----+-------+
| 6 | 64A | 0064A |
+---+-----+-------+
RESULT
+---+-----+-------+
| | A | B |
+---+-----+-------+
| 1 | 1A | 0001A |
+---+-----+-------+
| 2 | 7A | 0007A |
+---+-----+-------+
| 3 | 22R | 0022R |
+---+-----+-------+
| 4 | 38R | 0038R |
+---+-----+-------+
| 5 | 41R | 0041R |
+---+-----+-------+
| 6 | 64A | 0064A |
+---+-----+-------+

Resources