Hello!
I have a daily_date in my dataset and a reporting_period control that has Week, Month, Quarter and Year as grain selection options. This is how the formula looks (below)
My question is - when a user selects Year, I want to display 2023 instead of Jan 31, 2023. Is there a way to achieve that?
I saw Dynamic date hierarchy selection to do this but I don’t want to change my date datatype to string by doing this because I need to use this date for more calculations that need a date datatype. Thank you!!
ifelse(${Granularity}=‘Year’,addDateTime(-1, ‘DD’, addDateTime(1, ‘MM’, truncDate(“YYYY”,{report_day}))),
${Granularity}=‘Quarter’,truncDate(“Q”,{report_day}),
${Granularity}=‘Month’,addDateTime(-1, ‘DD’, addDateTime(1, ‘MM’, truncDate(“MM”,{report_day}))),
${Granularity}=‘Week’, addDateTime(-1, ‘DD’, addDateTime(1, ‘MM’,truncDate(“WK”,{report_day}))),
truncDate(“MM”,{report_day})
)