Calculating Storage Occupancy from History of Multiple Item Stages - Measure or Calculated Column?

Barhomopolis

New Member
Joined
Jan 10, 2012
Messages
21
Hello Everyone,

I have this dataset (click here) of items with time stamped stages. Some stages mean the item is occupying space in the storage. The other stages mean it's not. I need to use Power Pivot 2016 (not Power BI) to produce the chart below for avg. storage occupancy over time for the same time period of the same week day (we call it "time of week" for short). For instance, the chart should answer the question, "How many items on average do we have in storage on Sundays between 12 & 4 PM?" I also need to show percentiles on the same chart as below.



Before going into averages and percentiles, I first tried to create this measure to calculate the occupancy itself at any given "time of week":
SQL:
Occupancy:=CALCULATE(DISTINCTCOUNT('Source data'[ItemKey]),'Source data'[Stage] <> "Arrival" && 'Source data'[Stage] <> "Transport"),'Source data'[DateKey]))-CALCULATE(DISTINCTCOUNT('Source data'[ItemKey]),'Source data'[Stage] = "Arrival" || 'Source data'[Stage] = "Transport")

I was getting negative numbers, which is impossible. Then I realised I have to include items that entered the storage in the past and haven't left yet, but I couldn't figure out how to do it in Power Pivot 2016. It looks like there are new DAX functions in Power BI that do just this, but we can't use Power BI.

When I tried to calculate it in a calculated column:
SQL:
=CALCULATE(DISTINCTCOUNT('Source data'[ItemKey]),'Source data'[Stage] <> "Arrival" && 'Source data'[Stage] <> "Transport",'Source data'[DateKey]<=EARLIER('Source data'[DateKey]))-CALCULATE(DISTINCTCOUNT('Source data'[ItemKey]),'Source data'[Stage] = "Arrival" || 'Source data'[Stage] = "Transport",'Source data'[DateKey]<=EARLIER('Source data'[DateKey]))

I got an out of memory error, although the dataset is fewer a hundred thousand rows.

I would appreciate the help.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
To clarify more:
I'm trying to calculate how many items are occupying storage space at the time of calculation. I'm trying to do this by counting how many items came in (since the oldest time in the dataset all the way until the time of calculation), then subtracting how many came out (also from the oldest time until the time of calculation).

Each item goes through several time-stamped stages.

The stage "Arrival" means it's not yet occupying storage space.
The stage "Transport" means that after the "Transport" time stamp, an item is not occupying space anymore, but right until the "Transport" time stamp, it was occupying storage space.
All other stages happen after "Arrival" and before "Transport" and they mean that the item is occupying storage space.

The occupancy needs to be measured for four-hour intervals (called "time of week", e.g. Sunday 12AM - 4AM or Wednesday 8PM to Thursday 12AM). Then it needs to be averaged (and percentiles calculated) over all the occurrences of each time interval in the dataset to produce the chart above but with fewer bars (only one bar per 4-hour interval, no minor tick marks on the axis).

The aggregation (averages and percentiles) is easy. I just don't know how to count correctly XD

The dataset sample is here.

Thanks in advance!
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,150
Members
452,615
Latest member
bogeys2birdies

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