Forum Discussion
Filtering relative date ranges
- Anonymous4 years ago
Hi Anonymous ,
Thank you for your assistance!
Unfortunately I am still receiving the same error which is quite puzzling as none of the data is stored as Text.
I've done a workaround for now; using SQL to create a date table, checking how many Months in the Past a Date is from the current server time, and then applying that as a filter on separate cards for each category.
HI Anonymous,
I think these should be related to your expressions and you are writing conditions to compare text and date values in the 'switch' function. You can try to use the following measure formula if helps:
formula =
VAR selection =
SELECTEDVALUE ( Table[Segment] )
VAR _max1 =
MAXX ( ALLSELECTED ( 'Date' ), 'Date'[Date Name] )
VAR _min =
EOMONTH (
_max1,
SWITCH (
selection,
"Last Month", -2,
"Last 1-3 Months", -3,
"Last 3-6 Months", -6,
"Last 6-9 Months", -9,
"Last 9-12 Months", -12,
"12+ Months", 12
)
) + 1
VAR _max =
IF (
selection <> "12+ Months",
EOMONTH (
_max1,
SWITCH (
selection,
"Last Month", -1,
"Last 1-3 Months", 0,
"Last 3-6 Months", -3,
"Last 6-9 Months", -6,
"Last 9-12 Months", -9
)
),
EOMONTH ( _max1, 12 ) + 1
)
RETURN
CALCULATE (
SUM ( 'Orders'[Order Total Amount] ),
FILTER ( 'Date', 'Date'[Date Name] >= _min && 'Date'[Date Name] <= _max ),
USERELATIONSHIP ( 'Orders'[InvoiceCreatedAt], 'Date'[Date Name] )
)Regards,
Moonlight
Hi Anonymous ,
Thank you for your assistance!
Unfortunately I am still receiving the same error which is quite puzzling as none of the data is stored as Text.
I've done a workaround for now; using SQL to create a date table, checking how many Months in the Past a Date is from the current server time, and then applying that as a filter on separate cards for each category.