Can someone help me understand what's wrong with this formula?

Hey there,

I’ve been trying to write a formula to create a filter that adds granularity to the dashboard. However, for the ‘Quarter’ and ‘Year’ options, I want a different formatting where ‘Quarter’ is displayed as (1-2022) and ‘Year’ is displayed as 2022. To achieve this, I’m using the formatDate function with the extract function because the return type of **extract** is an integer and the return type of truncDate is a Date and trying to get everything in Date format. Could someone please help me understand what might be wrong with this formula?

ifelse(${Period} = 'Day', truncDate('DD', {CreatedvsClosed Calculated Field}),
    ifelse(${Period} = 'Month', truncDate('MM', {CreatedvsClosed Calculated Field}),
        ifelse(${Period} = 'Quarter', formatDate(extract('Q', {New Quarter Start Date}), 'Q-YYYY'),
            ifelse(${Period} = 'Week', truncDate('WK', {CreatedvsClosed Calculated Field}),
                ifelse(${Period} = 'Year', formatDate(extract('YYYY', {New Quarter Start Date}), 'YYYY'), null)
            )
        )
    )
)

formatDate returns a string, truncDate returns a date. You need to cast your truncDates to strings with toString