I have a spreadsheet containing data from hospital patients. I'm running Excel 2021. I need to create a function (or a macro) that tells me how many people live in the household that has the biggest age difference between the oldest and the youngest person. This is how my data looks like : EDIT: I've changed the screenshot of the data for a table so it's easier to work with.
| hserial | hhsize | age | ||
|---|---|---|---|---|
| 101051 | 1 | 92 | ||
| 101151 | 1 | 63 | ||
| 101201 | 1 | 56 | ||
| 101271 | 2 | 38 | ||
| 101271 | 2 | 25 | ||
| 101351 | 3 | 37 | ||
| 101351 | 3 | 14 | ||
| 101351 | 3 | 10 | ||
| 101371 | 2 | 35 | ||
| 101371 | 2 | 29 | 
where : age: age of the patient hserial: serial number of household. This is how we identify a household. hhsize: household size
I was thinking on maybe using the filter function, and finding the maximum between the subtraction of the oldest and youngest of each household.
                        
You can try the following in
E2cell for O365:You can use instead of
INDEX/MATCHthe followingXLOOKUP(x, hs, hsize).For Excel 2021 you don't have
MAPavailable, but you can use the following approach that replaces the second line of the previous formula and usesXLOOKUPinstead ofINDEX/XMATCH, but you can use them too:Here is the output for the first formula, for the second you get the same result: