Hi,
In the previous calculated field I had some redundant logic, which I went ahead and updated. And like I mentioned, I want to add an additional parameter which is a ‘Period Selection’ parameter, which gives the user the ability to choose the period to be either a ‘Month (MTD)’, ‘Quarter (QTD)’, ‘Year (YTD)’. While I did add this in the calculated field as well. But it’s not working as excepted for the ‘Month’ and ‘Quarter’.
The issue arises when I select the period to be ‘Month’ (for example, if the {$DatePram} is set to 7/22/2024). In this case, for the MTD, I do not have any sales for MTD (July 2024), and if I have selected the {$DateRange} to be ‘1 Year’, and I do have sales for the previous MTD of ( July 2023 - 7/22/2023). What happens is it shows me only the MTD sales of 7/22/2023, which, let’s say, is 1. It shows this correctly, but it does not show anything for 7/22/2024. What I expected it to show was 2023 = 1 and 2024 = 0. The same happens with QTD, where I expect it to show as Q3 2024 = 0 and Q3 2023 = 15, but it only shows me Q3 2023 = 15
Could someone help me understand what I am missing and what I need to add to get the desired outcome.
ifelse
(
/* This calculates the MTD for 1 Year */
${DateRange} = '1 Year' AND ${PeriodSelector} = 'Month' AND
(
(truncDate('DD', {Created Date}) >= truncDate('MM', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram})
OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', $ {DatePram})
)
),
'Include',
/* This calculates the QTD for 1 Year */
${DateRange} = '1 Year' AND ${PeriodSelector} = 'Quarter' AND
(
(truncDate('DD', {Created Date}) >= truncDate('Q', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram})
OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', $ {DatePram})
)
),
'Include',
/* This calculates the YTD for 1 Year */
${DateRange} = '1 Year' AND ${PeriodSelector} = 'Year' AND
(
(truncDate('DD', {Created Date}) >= truncDate('YYYY', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram})
OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', $ {DatePram})
)
),
'Include',
/* This calculates the MTD for 2 Years */
${DateRange} = '2 Years' AND ${PeriodSelector} = 'Month' AND
(
(truncDate('DD', {Created Date}) >= truncDate('MM', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram})
OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram}))
OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})
)
),
'Include',
/* This calculates the QTD for 2 Years */
${DateRange} = '2 Years' AND ${PeriodSelector} = 'Quarter' AND
(
(truncDate('DD', {Created Date}) >= truncDate('Q', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram})
OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram}))
OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})
)
),
'Include',
/* This calculates the YTD for 2 Years */
${DateRange} = '2 Years' AND ${PeriodSelector} = 'Year' AND
(
(truncDate('DD', {Created Date}) >= truncDate('YYYY', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram})
OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram}))
OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})
)
),
'Include',
/* This calculates the MTD for 3 Years */
${DateRange} = '3 Years' AND ${PeriodSelector} = 'Month' AND
(
(truncDate('DD', {Created Date}) >= truncDate('MM', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram}) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-3, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-3, 'YYYY', ${DatePram})
)
),
'Include',
/* This calculates the QTD for 3 Years */
${DateRange} = '3 Years' AND ${PeriodSelector} = 'Quarter' AND
(
(truncDate('DD', {Created Date}) >= truncDate('Q', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram}) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-3, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-3, 'YYYY', ${DatePram})
)
),
'Include',
/* This calculates the YTD for 3 Years */
${DateRange} = '3 Years' AND ${PeriodSelector} = 'Year' AND
(
(truncDate('DD', {Created Date}) >= truncDate('YYYY', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram}) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-3, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-3, 'YYYY', ${DatePram})
)
),
'Include',
/* This calculates the MTD for 5 Years */
${DateRange} = '5 Years' AND ${PeriodSelector} = 'Month' AND
(
(truncDate('DD', {Created Date}) >= truncDate('MM', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram}) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-3, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-3, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-4, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-4, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('MM', addDateTime(-5, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-5, 'YYYY', ${DatePram}))
),
'Include',
/* This calculates the QTD for 5 Years */
${DateRange} = '5 Years' AND ${PeriodSelector} = 'Quarter' AND
(
(truncDate('DD', {Created Date}) >= truncDate('Q', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram}) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-3, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-3, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-4, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-4, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('Q', addDateTime(-5, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-5, 'YYYY', ${DatePram}))
),
'Include',
/* This calculates the YTD for 5 Years */
${DateRange} = '5 Years' AND ${PeriodSelector} = 'Year' AND
(
(truncDate('DD', {Created Date}) >= truncDate('YYYY', ${DatePram}) AND truncDate('DD', {Created Date}) <= ${DatePram}) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-1, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-1, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-2, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-2, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-3, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-3, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-4, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-4, 'YYYY', ${DatePram})) OR
(truncDate('DD', {Created Date}) >= truncDate('YYYY', addDateTime(-5, 'YYYY', ${DatePram})) AND truncDate('DD', {Created Date}) <= addDateTime(-5, 'YYYY', ${DatePram}))
),
'Include',
'Exclude'
)
Thank you,
Akshay