Two-dimensional lookup, fixing issues with duplicate data

virtuosok

Board Regular
Joined
Sep 2, 2020
Messages
209
Office Version
  1. 365
Platform
  1. Windows
Hi,
Posting my workbook on Google Docs as it will be impossible to explain otherwise...
https://docs.google.com/spreadsheets/d/1NIm7gY2FvcgehehyFTUuJETvU2DgQv-O/edit?usp=sharing&ouid=100510883221888486550&rtpof=true&sd=true
Tab IWRS is the source, tab Dashboard is the output; the actual formulas are on tab Calc.
In column Z I have a two-dimensional lookup, formula
Excel Formula:
=INDEX($I$2:$W$751,MATCH(A2,$A$2:$A$751,0),MATCH((XLOOKUP(E2,I2:W2,$I$1:$W$1)+1),$I$1:$W$1,0))
It works well as long as there are no duplicates in visit date. However if there's 2 visits for the same subject, on the same day (see rows 33/34), the formula is stuck. How can this be addressed? It may as well be a different type of formula, it's the best I could produce so far...
Formula in column G is also stuck, I'm not too worried about that one, but if this can be fixed as well it would be awesome.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
...or, I guess, this may well need further explanation.
So, on IWRS (source) tab, all patients are listed in column E. A typical subject will be listed more than once in column E as each visit to the clinic (see column K for visit names) is a new line. There is a subset of patients who are receiving a specific medication dose (column P) throughout specific timeframe. That timeframe spans from date noted in column L, till the next visit date in the same column for the same patient. Sometimes patients are administered the same dose on the next visit, but sometimes this may be a different dose... and so on, multiple times throughout the study. Patient may stay on 10 mg from visit to visit, or can flip between 5, 10, and 15 mg, in-between individual visits.
If next visit date is not listed for a given patient, we have to assume that this date is TODAY()
...unless the last/previous registered date for this subject was associated with the following visit name (see column K): Treatment Discontinuation or Completion. That means there will be no other visits (and there's no dose prescribed at these visits anyway).
I'm trying to find out how many days the patient X, Y, and Z, were on 5mg, 10mg, and 15mg (there are no other doses possible), to output this on Dashboard tab. I added multiple helper columns on Calc tab while trying to find the best solution.
Hope this explains the conundrum - happy to provide further info!
 
Upvote 0
On the calc sheet
In G2 fill down use
Excel Formula:
=COUNTIFS(A$2:A2,A2)
And in Z2 filled down
Excel Formula:
=INDEX($I$2:$W$751,MATCH(A2,$A$2:$A$751,0),G2+1)
 
Upvote 0
Solution
Wowwwww this is so beautifully elegant, thank you Fluff!
Last related question, is there a way to get the max # of contiguous days for each dose for each patient?
E.g. subject 11 (lines 21-27 on Calc tab) was on 10 mg for 54 days, but only 46 of these are contiguous. So I would need another formula to return "46" if possible...
 
Upvote 0
As that's a totally different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,229
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top