Question

I think relationally, not cubally. So, I'm not asking this question correctly, and for that, I apologize.

I have a table where each record is a patient, a day, a location, and a drug. When a patient gets more than one dose of any drug on a day, it only counts once. When a patient receives the same drug on the same day, but in different locations, it counts as a drug for each location, but only counts once for that patient day. In order to count correctly when slicing by days or locations, or drugs, I created a hash of "patient-day-drug" and the measure was a "COUNT DISTINCT". That worked great. A patient may be listed at a location without a drug, but would never have a drug without a location.

I got into trouble when I tried to calculate patient-day volumes, slicing by location. I thought I would do the same hash trick with hashing "patient-day". So, if I calculate a patient-day for a specific location, I want every distinct patient-day to count only once. What I found was that I was calculating patient-days in such a way that changed when I changed the scope of the query. If I filtered by the type of drug, it changed patient days.

This is where I get confused. When I filter by a set of locations, I want the calculation of drug-days over patient-days to reflect the filtered locations. But I don't want any filter on drugs (which would change the list of patients) to alter the location day. So, I don't know how to selectively make patient counts invariant.

One thought is to make a view of Day and Location and calculate the Patient-Day, and join that view to the table I have, but I don't know to designate at what levels these numbers can aggregate, where they can't. And then, at each level, the calculation of Drug-Day over Patient-Day must occur after aggregation.

Where is a good place to start for learning about these weird dimension/measure relationships?

Was it helpful?

Solution

[Your question is very broad and as such might be closed]

There are 2 books that I consider to be absolutely required reading:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top