Forum Discussion
stalerik
Helper II
6 years agoDate-Range Slicer: Dynamically Change Data Aggregation on Chart based on selected date range
I have added a slicer with dates as a filter to my report. I have a table of one-minute data and created a chart based on it. I would like to change how the data is aggregated on the chart dependin...
Icey
Community Support
6 years agoHi stalerik ,
Try this:
1. Create tables.
Date One-Minute =
ADDCOLUMNS (
VALUES ( 'Table'[DateTime] ),
"Date - m", "Date - m",
"Sum - m", CALCULATE (
SUM ( 'Table'[Value] ),
'Table'[DateTime] <= EARLIER ( 'Table'[DateTime] )
)
)
Date One Hour =
ADDCOLUMNS (
FILTER (
VALUES ( 'Table'[DateTime] ),
MINUTE ( [DateTime] ) - MINUTE ( MINX ( ALLSELECTED ( 'Table' ), [DateTime] ) ) = 0
),
"Date - h", "Date - h",
"Sum - h", CALCULATE (
SUM ( 'Table'[Value] ),
'Table'[DateTime] <= EARLIER ( 'Table'[DateTime] )
)
)
Date One Day =
ADDCOLUMNS (
FILTER (
VALUES ( 'Table'[DateTime] ),
MOD ( DATEDIFF ( MIN ( 'Table'[DateTime] ), [DateTime], MINUTE ), 60 * 24 ) = 0
),
"Date - d", "Date - d",
"Sum - d", CALCULATE (
SUM ( 'Table'[Value] ),
'Table'[DateTime] <= EARLIER ( 'Table'[DateTime] )
)
)
2. Union the above three tables.
Dates = UNION('Date One-Minute','Date One Hour','Date One Day')
3. Create a measure.
Measure =
VAR DateDiff_ =
DATEDIFF ( MIN ( 'Table'[DateTime] ), MAX ( 'Table'[DateTime] ), DAY )
RETURN
SWITCH (
TRUE (),
DateDiff_ < 3, CALCULATE (
SUM ( 'Dates'[Sum - m] ),
FILTER ( Dates, Dates[Date - m] = "Date - m" )
),
DateDiff_ >= 3
&& DateDiff_ < 30, CALCULATE (
SUM ( 'Dates'[Sum - m] ),
FILTER ( Dates, Dates[Date - m] = "Date - h" )
),
DateDiff_ >= 30
&& DateDiff_ < 90, CALCULATE (
SUM ( 'Dates'[Sum - m] ),
FILTER ( Dates, Dates[Date - m] = "Date - d" )
)
)
4. Create visuals.
5. Then you can get this:
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.