Aggregating Dimensions through time


#1

hi everyone,

I’m working on a project and I am a bit stuck on working out a ‘capacity’ type measure that aggregates over a period of time (based on context)
So its your usual orders / stores / dates type scenario, and I have a table for each (orders being my fact table here)
My ‘Stores’ dimension is a bit complex because I have some that are open on weekend days, and some that are not.
So for each Store ID, I have a daily Capacity value, and a true/false column for whether it operates on Saturday and Sunday

What I want to calculate is the total capacity for each store over a given date range, and be able to drill up/down to a daily or weekly level, with it calculating the correct value for a week period whether the particular store is operating on the weekend or not.

To start I have a measure that counts the number of dates in the current context

Number of Dates = COUNTROWS(Dates)

Then I’m working out a basic capacity like this:

Base Capacity By Date = 
VAR DatesSelected = [Number of Dates]
RETURN
       SUMX (
            'Store Capacity',
            'Store Capacity'[Capacity] * DatesSelected ) 

Which is okay, but not accurate enough. I tried adding another column to my Store dimension, giving the number of days per week, but I don’t think using VALUES on this column would work, i.e

    VAR DatesSelected = [Number of Dates]
VAR OperatingDays = VALUES ( 'Store Capacity'[Operating Days] ) 
VAR OpenDates = DatesSelected - ( DatesSelected - OperatingDays )

Any ideas? Happy to provide more info if needed


#2

@ChrisM,
Can you load some sample data and maybe a quick mock-up of what you would like to see?

Enterprise%20DNA%20Expert%20-%20Small


#3

Hi Nick

here is some sample data I have mocked up, the stores tab is the dimension, the plans tab is the fact table. the relationship here is the PlantID.
The date dimension is related to the Fact table by the PackingDate field.

sample.data.xlsx (39.9 KB)

as far as a mockup goes, it want to use the capacity aggregation multiple ways, but here is an example of what is planned vs the combined capacity of all the Plants/Stores currently being shown. Two images of the same visual, where one has been drilled down further in the heirarchy of dates.
i.e. if the store isn’t operating on the weekend, its weekly capacity would be 5 * Capacity, instead of 7 * capacity like I’m getting.


#4

@ChrisM,
Quick question. I’m not 100% clear in your sample data where the capacity is. Is it the weekly capacity in the DimStore table under the PackingCapacity column? I just want to be sure since this will be the starting point for the calculation.

Enterprise%20DNA%20Expert%20-%20Small


#5

Hi Nick,

The field ‘PackingCapacity’ in the stores table is the Daily Capacity - hmmm, what if we worked out the weekly capacity into that dimension table, and then switched between the daily and weekly values depending on the date context?


#6

@ChrisM

Enterprise%20DNA%20Expert%20-%20Small


#7

yeah that is correct - I think when I added the ‘Operating Days’ field, it was 5 + whether the Saturday / Sunday were TRUE


#8

Hi Nick,
Did you manage to work out a solution?


#9

@ChrisM
Sorry about the delay, actually had my first kid a little earlier than anticipated so had to go radio silent there. I will have some sort of solution by end of week at the latest.


#10

Congratulations!

Thanks, I’m not really working to much of a deadline, so take your time :slight_smile:


#11

@ChrisM,
Thanks for the congrats, appreciate that!

Now back to business. I attached the pbix file below. I dont think its 100% what you want, but I think ( hope) it is close or at least something we can work with.

Quick list of things I did:

  1. Go to Power Query and you will see a parameter for the File location. enter in the entire file location of the sample file. This will allow you to see the data in Power Query

  2. There’s a small query that created a DimCalendar table with some additional columns. Pretty standard stuff but needed a Calendar table

  3. A query called PreventFirewall. Probably not an issue here, but sometimes you can get an error if you dont have the correct access to source data. Basically this query gets everything from the excel file and then the FacPlans and DimStores table referenced that.

I toyed with the idea of denomarmalizing a little and putting the Capacity from DimStores directly into the Fact table, but didnt go down that route, but here’s what I got:

To get each stores weekly capacity:
Store Weekly Capacity= SUMX( VALUES( DimStores[Id]), CALCULATE( MAX( DimStores[PackingCapacity]) * MAX( DimStores[Operating Days]) ) )

No idea hat its formatted like that, but here’s a screenshot:
Weekly%20Capacity%20by%20Store

produces this table:
Table%20of%20Total%20Weekly%20Capacity

Then to get the grand total of the weekly capacity:
Total Weekly Capacity =
CALCULATE(
SUMX(
DimStores,
CALCULATE(MAX( DimStores[PackingCapacity]))* CALCULATE(MAX( DimStores[Operating Days]))
)
, ALL( DimStores)
)

which is used as the black line in this chart:

I’m sure this is more that is needed here, but this should be a good start.

Here’s the pbix:
Agg Dimension through Time.pbix (134.0 KB)

Let me know what you think.

-Nick


#12

I feel like congratulations is just the start. Especially if you had an unexpected early arrival! I hope everything is going alright. Your first is always a complete life upheaval :grinning:

thanks for this - I’ll have a look and let you know if I can make it work!


#13

I believe upheaval is the most correct term here! but in the most amazing way for sure :slight_smile:

I’ll be around these parts, so let me know when/if you have any questions.

Thanks again