Forum Discussion
Re:
- 4 years ago
HI frittle
Interesting question ๐
I have attached a sample PBIX.
This is how I would recommend setting this up:
- Set up the fact table (I've called it Measurement below), with separate Date and Time columns, with Time at the 20 minute granularity (see here for discussion):
- Create Timestamp Bin (as you already have), but just containing the time part.
- Create a Date column containing just the date part (there wasn't a date in your example table, but I assume there must be one).
- The original Timestamp column can be optionally removed (as it is a high cardinality column), and I recommend creating with a Timestamp Index column solely for the purpose of breaking ties between two Timestamps in the same bin.
- This is how the final Measurement table looks in my PBIX (my date format is d/mm/yyyy):
- Create Date and Time dimension tables, with Time being at 20 minute granularity.
- Mark Date table as a date table.
- Create relationships so the data model looks like this, with :
- Create measures as follows, with Last Value being the final measure to use in visuals:
-- =================================================== -- Value Average -- Base measure averaging the Value column -- =================================================== Value Average = AVERAGE ( Measurement[Value] ) -- =================================================== -- Value Average Breaking Ties -- If multiple Timestamp indexes exist in the same bin -- use the one with the max index -- =================================================== Value Average Breaking Ties = AVERAGEX ( SUMMARIZE ( Measurement, 'Date'[Date], 'Time'[Time] ), -- Use Timestamp Index to break ties. LASTNONBLANKVALUE ( Measurement[Timestamp Index], [Value Average] ) ) -- =================================================== -- Last Value -- Takes all Date/Time values existing in Measurement -- up to the max filtered date, determines the max -- Date/Time, and returns [Value Average Breaking Ties] -- for that Date/Time. -- =================================================== Last Value = VAR OverallMaxDateTime = CALCULATE ( MAXX ( Measurement, 'Measurement'[Date] + Measurement[Timestamp bin] ), REMOVEFILTERS () ) VAR MaxDate = MAX ( 'Date'[Date] ) VAR MaxTime = MAX ( 'Time'[Time] ) VAR MaxDateTime = MaxDate + MaxTime RETURN IF ( MaxDateTime <= OverallMaxDateTime, VAR PastDateTime = FILTER ( CALCULATETABLE ( SUMMARIZE ( Measurement, 'Date'[Date], 'Time'[Time] ), 'Date'[Date] <= MaxDate, REMOVEFILTERS ( 'Time' ) ), 'Date'[Date] + 'Time'[Time] <= MaxDateTime ) VAR LatestDateTimeWithValue = TOPN ( 1, PastDateTime, 'Date'[Date] + 'Time'[Time] ) VAR Result = CALCULATE ( [Value Average Breaking Ties], LatestDateTimeWithValue, REMOVEFILTERS ( 'Time' ) -- Time filters must be explicitly removed ) RETURN Result )Notes on Last Value:
- The Last Value is the measure to display on visuals.
- I tried a few approaches, including some built-in functions LASTNONBLANK/LASTNONBLANKVALUE, but the above code performed best in my testing.
- It will only return values up to the latest date/time in the dataset due to this condition (this can be changed):
MaxDateTime <= OverallMaxDateTime - With the logic in the above measures, the Last Value at 10:00 is 76, since that had the later timestamp in the 10:00 bin.
Sample table in report:
I realise that was quite a long-winded answer, but hopefully the sample PBIX makes it clearer.
Please post back with any other question ๐
Regards,
Owen
- Set up the fact table (I've called it Measurement below), with separate Date and Time columns, with Time at the 20 minute granularity (see here for discussion):
- 4 years ago
HI frittle
Interesting question ๐
I have attached a sample PBIX.
This is how I would recommend setting this up:
- Set up the fact table (I've called it Measurement below), with separate Date and Time columns, with Time at the 20 minute granularity (see here for discussion):
- Create Timestamp Bin (as you already have), but just containing the time part.
- Create a Date column containing just the date part (there wasn't a date in your example table, but I assume there must be one).
- The original Timestamp column can be optionally removed (as it is a high cardinality column), and I recommend creating with a Timestamp Index column solely for the purpose of breaking ties between two Timestamps in the same bin.
- This is how the final Measurement table looks in my PBIX (my date format is d/mm/yyyy):
- Create Date and Time dimension tables, with Time being at 20 minute granularity.
- Mark Date table as a date table.
- Create relationships so the data model looks like this, with :
- Create measures as follows, with Last Value being the final measure to use in visuals:
-- =================================================== -- Value Average -- Base measure averaging the Value column -- =================================================== Value Average = AVERAGE ( Measurement[Value] ) -- =================================================== -- Value Average Breaking Ties -- If multiple Timestamp indexes exist in the same bin -- use the one with the max index -- =================================================== Value Average Breaking Ties = AVERAGEX ( SUMMARIZE ( Measurement, 'Date'[Date], 'Time'[Time] ), -- Use Timestamp Index to break ties. LASTNONBLANKVALUE ( Measurement[Timestamp Index], [Value Average] ) ) -- =================================================== -- Last Value -- Takes all Date/Time values existing in Measurement -- up to the max filtered date, determines the max -- Date/Time, and returns [Value Average Breaking Ties] -- for that Date/Time. -- =================================================== Last Value = VAR OverallMaxDateTime = CALCULATE ( MAXX ( Measurement, 'Measurement'[Date] + Measurement[Timestamp bin] ), REMOVEFILTERS () ) VAR MaxDate = MAX ( 'Date'[Date] ) VAR MaxTime = MAX ( 'Time'[Time] ) VAR MaxDateTime = MaxDate + MaxTime RETURN IF ( MaxDateTime <= OverallMaxDateTime, VAR PastDateTime = FILTER ( CALCULATETABLE ( SUMMARIZE ( Measurement, 'Date'[Date], 'Time'[Time] ), 'Date'[Date] <= MaxDate, REMOVEFILTERS ( 'Time' ) ), 'Date'[Date] + 'Time'[Time] <= MaxDateTime ) VAR LatestDateTimeWithValue = TOPN ( 1, PastDateTime, 'Date'[Date] + 'Time'[Time] ) VAR Result = CALCULATE ( [Value Average Breaking Ties], LatestDateTimeWithValue, REMOVEFILTERS ( 'Time' ) -- Time filters must be explicitly removed ) RETURN Result )Notes on Last Value:
- The Last Value is the measure to display on visuals.
- I tried a few approaches, including some built-in functions LASTNONBLANK/LASTNONBLANKVALUE, but the above code performed best in my testing.
- It will only return values up to the latest date/time in the dataset due to this condition (this can be changed):
MaxDateTime <= OverallMaxDateTime - With the logic in the above measures, the Last Value at 10:00 is 76, since that had the later timestamp in the 10:00 bin.
Sample table in report:
I realise that was quite a long-winded answer, but hopefully the sample PBIX makes it clearer.
Please post back with any other question ๐
Regards,
Owen
- Set up the fact table (I've called it Measurement below), with separate Date and Time columns, with Time at the 20 minute granularity (see here for discussion):
OwenAuger
Hello Owen,
following up on this topic there is a new function that I have to create and I have faced a small problem, and I was wondering whether you might have an idea on how to solve it. Based on your measure that gives me the buffer fill level every 20 minutes per day (and fills in the last non blank value if no value is found), I assigned percentage Intervals (in 20% steps) based off of the maximum capacity of each buffer to every value I get using your measure with a switch function. I now count the amount every percentage interval occurs per day, so that I know if my buffer is rather empty or rather full. I display this information using a pie chart. To see what I mean check out my dashboard below:
i have two buffers "HB-G2x Speicher Bahn Zu-Ablauf" and "VB-G2x Speicher Zu-Ablauf" that I can select using the BESCHREIBUNG slicer. These two buffers have different capacities though, so I created the Table "MAXTABLE" that contains the buffers name and its maximum.
So that the percentage calculation is right it has to use the right maximum value for the right buffer:
Puffer Max Dummy =
CALCULATE (
SELECTEDVALUE ( MAXTABLE[MAXWERT] ),
CROSSFILTER ( MAXTABLE[BESCHREIBUNG], 'Puffer Vergleich'[BESCHREIBUNG], BOTH )
)
Puffer Fรผllstand test =
VAR CurrentValue = [Last Value final 20 minute stamp]
VAR MaxPufferInRage = [Puffer Max Dummy]
RETURN
SWITCH (
TRUE (),
CurrentValue <= MaxPufferInRage * 0.2, "<20%",
CurrentValue > MaxPufferInRage * 0.2
&& CurrentValue < MaxPufferInRage * 0.4, "20-40%",
CurrentValue >= MaxPufferInRage * 0.4
&& CurrentValue <= MaxPufferInRage * 0.6, "40-60%",
CurrentValue > MaxPufferInRage * 0.6
&& CurrentValue < MaxPufferInRage * 0.8, "60-80%",
CurrentValue >= MaxPufferInRage * 0.8, ">80%"
)
The Problem I'm facing now is that my measure "Puffer Max Dummy" gives me blanks (as you can see in the table above) If the measure "Last Value final 20 minute stamp" returns a lastnonblank value. If you have an idea on how I can fill the missing maximum values, I would highly appreciate it, since my interval count is otherwise misleading. Many thanks in advance.
Best Regards,
Leo