benji
benji

Reputation: 386

User facing date field granularity control

I'm trying to give my users the option to select the date field granularity of their choice, such as day, week, month or year. This is normally controlled on each graph in the menu show below but this isn't available in a published dashboard: enter image description here

My first idea was to create a calculated field that truncates my desired date based on a parameter that I expose through a control. This would like something like this, truncDate(${intervalParameter}, {dateColumn}). The problem with this is that the first argument of the truncDate function must one of valid string literals and will throw an error before saving if it isn't.

Does anyone know of any other ways of achieving this? Or maybe some sneaky way of getting around the error?

Upvotes: 1

Views: 1038

Answers (1)

benji
benji

Reputation: 386

I figured out a work around using ifElse.

ifElse(
    ${intervalParameter} = 'Day', truncDate("DD", {dateColumn}),
    ${intervalParameter} = 'Week', truncDate("WK", {dateColumn}),
    ${intervalParameter} = 'Month', truncDate("MM", {dateColumn}),
    truncDate("DD", {dateColumn})
)

There might be better solutions out there but this is what I've come up with.

Upvotes: 2

Related Questions