How to 'group' data in excel and find the maximum in the group - excel

I have parent and child accounts that make a family. If the Parent_acct = Accnt_no then its parent. I need to find the maximum Term in the family and show as Family_term (this is to be calculated) for each account. What's the good way to do it? Sorry cannot post an image yet.
Parent_acct_no Account_no Type Term Family_term(max)
565 565 Parent 45 78
565 256 Child 78 78
331 331 Parent 23 87
331 754 Child 87 87
331 823 Child 19 87

You can use an array formula of max combined with if. Assume the columns are A (Parent_Account_No) through E (Family term max), the formula in column E should be (starting with E2):
{=max(if($A$2:$A$6=A2,$D$2:$D$6,FALSE))}
Make sure to press Ctrl+Shift+Enter when entering the formula to make it an array formula (see details here: http://www.cpearson.com/excel/ArrayFormulas.aspx)

Lets assume the following columns:
A B C D E
Parent_acct_no Account_no Type Term Family_term(max)
And you want to sum up Family_term grouped by each Type=Parent then you could use the following formula in Column F
(F2) =if(c2="Parent";sumif(A$2:A$500;B2;E$2:E$500);"")
If you name the column A (P_acc=A$2:A$500) and E (F_term=E$2:E$500) you can write
(F2) =if(c2="Parent";sumif(P_acc;B2;F_term);"")
Since I don't have access to excel at home I could not test it tho.
Hope that helps.
Edit: Corrected my denglish excel command (when->if) Thx.

Related

How do I find the largest numbers in a area, and then find the value of a number in the same row?

I cannot find a way to do this, is it possible (with excel functions or VBS)?
For example, these would be the initial values:
Number
Value
101
234
102
324
103
345
104
325
105
437
106
443
107
806
108
476
109
538
110
546
And after taking the three highest numbers, this would be the output:
Number
Value
107
806
110
546
109
538
The data is constantly updating, so that might cause some issues.
You can use FILTER in combination with LARGE function to achieve this:
Columns A and B represent sample data. Cell D2 can contain this formula:
=FILTER($A$2:$B$9,$B$2:$B$9>=LARGE($B$2:$B$9,3))
If data is constantly updating, better to have an Excel Table (I named TB_NumVal), so the range index get automatically updated.
In cell: J2:
=SORT(FILTER(SORT(TB_NumVal,2), (ROW(TB_NumVal[Number])-1)
> ROWS(TB_NumVal[Number])-3),2,-1)
Here is the output:
Explanation
We sort the data, then since we start on row 2 (row 1 is the header) we substract 1. So
ROW(TB_NumVal[Number])-1
will provide the row number starting from one.
ROWS(TB_NumVal[Number])
is the total number of rows, in our case 10.
Using a filter condition like this:
(ROW(TB_NumVal[Number])-1) > ROWS(TB_NumVal[Number])-3)
ensures only the last three row will be selected, then finally sorted the filtered result by value in descending order to match the result of the screenshot of the question.

Is there a way to match a value to a range in a lookup table?

I have two separate tables in an Excel worksheet, as illustrated below. 
Columns A, B, E, F and G are my input values;
I want a formula that generates the values in Column C
(shown in italics):
 
A
B
C
D
E
F
G
 1
Name
Value
Type
Type
Lower
Upper
 2
Andy
35
Spam
Spam
35
39
 3
Mark
85
Foo
Ham
25
27
 4
Pat
28
N/A
Eggs
91
95
 5
Deb
93
Eggs
Foo
82
86
 6
Emily
92
Eggs
Bar
65
69
 7
Greg
22
N/A
 8
Gary
67
Bar
For each row in the first table (i.e., each person),
I want to find that person’s Type based on their Value (Column B)
by finding the row in the second table where the person’s Value
falls within the Lower→Upper range (Columns F and G). 
So, for example, Mark (Row 3) has a Type of “Foo”
because his Value (85) falls between 82 and 86,
associated with “Foo” in Row 5 of the second table. 
Note that Pat’s Value is 28 (Row 4), which does not match any range.
The ranges are inclusive. 
For example, Andy’s Type is “Spam” (Row 2) even though his Value (35)
equals the Lower end of the range for “Spam” (Cell F2).
I know nested IFs are quite hard to debug in Excel,
so I’d like to avoid that if possible.
Modify your source table to show the lower limit for each grade and then use a VLOOKUP with a approximate match
Update to show how to include blank ranges
Filter Solution
If you don't have access to the FILTER function, one option is an INDEX/MATCH array formula, which will need confirmed with Ctrl+Shift+Enter.
=INDEX($F$2:$F$6,MATCH(1,($G$2:$G$6<=B2)*($H$2:$H$6>=B2),0),)
Another option is LOOKUP, which does not need Ctrl+Shift+Enter.
=LOOKUP(1,1/(($G$2:$G$6<=B2)*($H$2:$H$6>=B2)),$F$2:$F$6)

How to compare 2 massive/huge/long lists and output any non matching results in one field

I have 2 massive columns filled with studentids
Column 1(SID) has 110,000 rows
Column 2(SID2) has 100,000 rows
How do I make a check of column 1 = column 2 or vice versa and then finally place it all in one field!
Current Results
SID SID2
45 45
142 142
237 218
238 441
410 410
440 442
452 237
452
Final Expected output
SID SID2 Check
45 45
142 142
237 218
238 441 238,441
410 410
440 442 440
452 237
452
238,441,440
As you can see, all the ids that dont match should be placed in one field so I can easily spot them rathen than looking though 100,000 rows
Looks like SolarMike answered assuming that the test is A2=B2, but I think you're asking if A2=[Anything in Column B] and if B2=[Anything in Column A]. Here's how I'd test that:
Column C:
=IFERROR(IF(MATCH(A2,B:B,0)>1,"",A2),A2)
Column D:
=IFERROR(IF(MATCH(B2,A:A,0)>1,"",B2),B2)
Column E (very crude, but effective):
=IF(AND(C2="",D2=""),"",CONCATENATE(C2,",",D2,","))
Now, your real problem is getting it all into one single cell. The only way I know how to do this is to use Concatenate, but it requires you to select EACH CELL individually.
=CONCATENATE(E2,E3,E4,E5,E6,E7,E8,E9,E10)
For 10000 rows, that doesn't seem feasible. Also, that output isn't very flexible, but I digress.
If you want to concatenate everything together in one cell, you have two options.
A) Use the VBA code here (it's pretty simple, this seems like a viable option): Concatenate Excel Ranges with VBA
B) Hope that you have Office 365 with TEXTJOIN() See Support article here.
You could use match() with iferror() and if():
=IF(IFERROR(MATCH(A1,B1,)>0,0),"ok",A1)
see:
To get both fields back use:
=IF(IFERROR(MATCH(A1,B1,)>0,0),"ok",A1)&" , "&IF(IFERROR(MATCH(A1,B1,)>0,0),"ok",B1)

Tricky counting formula

My data looks like this
1|1|1|1 101
1|1|1|2 101
1|1|1|3 101
1|1|2|1 102
1|1|2|2 102
1|1|3|1 103
1|1|3|2 103
1|1|3|3 103
1|1|3|4 103
1|1|3|5 103
1|1|4|1 104
1|1|4|2 104
1|1|4|3 104 <--- my eq works till here
1|2|1|1 105 <--- my eq needs to return 105 but all my eq modifications have failed
1|2|1|2 105
1|2|2|1 106
1|2|3|1 107
2|1|1|1 201 <--- my eq figures this switch out without issue
2|1|1|2 201
2|1|2|1 202
2|2|1|1 203 <--- my eq fails here
2|2|1|2 203
2|2|1|3 203
2|2|2|1 204
2|2|2|2 204
I'm trying to find a formula or a macro anything that will result in the column on the far right (101, 102, 103, etc). My current formula take Col 1 and Col 3 and combines them. The challenge is that when Col 1 is the same but the 2nd column switches I need to keep counting up.
I have tried finds, index(match,match), search, max above. I can't find the right combinations of (Excel functions, haven't tried a macro yet since I'm not quite sure how to get what I want) function to make this work please help. If extra columns are needed that's find I just can't change the first four columns.
With the following data layout:
You can use following formula in E2and drag down:
=100*A2+IF(A2<>A1,1,MOD(E1,100)+(C2<>C1))
If you don't have column headers, use your formula in E1.
Put your data in columns A, B, C, D.
Put number "101" in cell E1.
Put this formula in cell E2: =IF(AND(A2=A1;C2<>C1);E1+1;E1) and drag it down.

Tableau - lookup letter grade from range

I have two Excel spreadsheets. One contains average numerical grade for a student and the other a list of letter grades for numeric grades between a min and max
Spreadsheet 1
Student Avg Letter Grade
Mike 91
Joe 76
Mary 84
Sally 78
Spreadsheet 2
Min Max LetterGrade
90 100 A
81 89 B
71 80 C
61 70 D
0 60 F
How do I return the proper grade for each student in Tableau? It seems trivial but I can't figure out the calculation. Thank you for your help!!!
There is an easier way to do this by using Groups.
Import Spreadsheet 1 as a data source
Right Click on "Avg" and select Create Group
From there use Shift Click to group your ranges using Spreadsheet 2 as your reference, using labels "A, B, C"
On the top of the Create Group dialog box, make sure you rename your Field Name as "Letter Grade"
The weakness of this approach is that you have to check/redefine your groups if you are updating your data source. Using IF-ELSEIF statements may be more flexible as Inox suggested in the comments. But this is a relatively easy trick, without any programming involved. :-)
For more info, visit: http://kb.tableau.com/articles/knowledgebase/use-ad-hoc-groups-categorize
Hope this helps!

Resources