Dynamically changing aggregation and number of periods

I currently have a custom field called DateSeries which is linked to a parameter and some filters. It allows the user to choose between Daily, Weekly (Mon-Sun) and Monthly.

I want to make it so when you select Daily, it only shows the last 30 days and/or toggles Show Data Zoom for the x axis. The way its currently setup, when you show daily it shows several months of daily observations and looks crowded. Ideally I want to control the number of days or weeks shown depending on what the user selects. e.g., 30 days for days, 20 weeks for Weekly (mon-Sun) and 12 months for month.

The code for the custom field

ifelse(
    ${aggregation} = 'Daily',
        truncDate('DD', Date),
    ${aggregation} = 'Weekly (Mon-Sun)',
        addDateTime(
    1, 
    'DD', 
    truncDate(
        'WK',
        ifelse(
            extract(
                'WD',
                Date
            ) = 1, 
            addDateTime(
                -1, 
                'DD', 
                Date
            ), 
            Date
        )   
    )),
    truncDate('MM', Date)
    )
1 Like

@jm_fen - Thank you for posting your query. I believe you can do this by creating another calculated field with the following code. In my case, I named it “Zoom Bar Control”

Once its created you create a visual level filter by specifying that “Zoom Bar Control” = 1. Hope this helps!

Did my suggestion help you in resolving your query? If yes, would request you to mark the post as “Solution”. This will help the community to find guidance and answers to similar question. Thank you!