Forum Discussion
Date-Range Slicer: Dynamically Change Data Aggregation on Chart based on selected date range
Hi 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.
- stalerik6 years agoHelper II
I don't know if I am smart enough for this. I have a table now, with a datetime column (minutes) and several value columns. There are nearly a million rows of minute-data connected to a database with direct query. I am creating a line chart with a continuous x-axis. I have a slicer on my report. I don't understand how to get to my one table and make a line chart that will change the aggregation based on the slicer range (minutes, hours, days, month). I have tried some of the formulas in these examples but they were not working.