Forum Discussion
Dynamic Time X Axis with hourly data
- 1 year ago
Hi showy ,
Create a field parameter table with the columns you need for aggregation this will be something similar to this:
Parameter = { ("BIS", NAMEOF('F_Energieverbrauch'[BIS]), 0, 1), ("Date", NAMEOF('F_Energieverbrauch'[Datum]), 1, 2), ("Date", NAMEOF('F_Energieverbrauch'[Datum]), 1, 3), ("Date", NAMEOF('F_Energieverbrauch'[Datum]), 1, 4), ("Date", NAMEOF('F_Energieverbrauch'[Datum]), 1, 5), ("Date", NAMEOF('F_Energieverbrauch'[mONTH]), 1, 6) }Now create a relationship one to many between the parameter table and the Datumfilter table now you can have the aggregation has needed.
I have also created a month column for the last aggregation that you need at year level.
Check Bottom chartPlease see file attach.
You can achieve a dynamic X-axis in Power BI using a Calculation Group (via Tabular Editor) or a DAX measure that switches aggregation based on a slicer:
- Create a “Time Selection” table with options like Today, Last 7 Days, Last Year, etc.
- Create a measure (DynamicSales) that aggregates depending on selection:
DynamicSales :=
SWITCH(
TRUE(),
SELECTEDVALUE('Time Selection'[Time Selection]) = "Today", [SalesAmount] (hourly),
SELECTEDVALUE('Time Selection'[Time Selection]) IN {"Last 7 Days","Last Calendar Week","Last 31 Days","Last Month"}, CALCULATE([SalesAmount], 'Date'[Date]),
SELECTEDVALUE('Time Selection'[Time Selection]) = "Last Year", CALCULATE([SalesAmount], 'Date'[YearMonth])
)
3.Use the full date column on X-axis; the measure dynamically aggregates to hourly, daily, or monthly based on selection.
No bookmarks or multiple fields needed.