Feb 26, 2024 01:24 PM
Hey all,
I could use some help and I'm hoping this isn't too difficult. I am trying to add a formula that compares an event date to the date of the next time change. If it is before the date of the time change, it runs one formula, if after, it runs another formula. I thought this would be simple enough but I keep getting an error. The formula I am using is below:
Feb 26, 2024 02:20 PM
Feb 27, 2024 04:12 AM
Hi,
You can use quoted date in ISO format, '2024-03-10'
also, you should adjust brackets
Here is your non-working formula:
IF( is_before_statement , 'result_before' ) ,
IF( is_after_statement , 'result_after' )
you can build it as nested IF:
IF( is_before_statement , 'result_before' ,
IF ( is_after_statement , 'result_after' )
)
or, personally I like it more, as 2 independent IFs, just replace comma with ampersand
IF( is_before_statement , 'result_before' ) &
IF( is_after_statement , 'result_after' )
Feb 27, 2024 06:49 AM
Thank you for this, it was super helpful! I'm no longer getting an error, but it's also not returning a value at all. I know that the two timezone calculations work separately, so I'm assuming there must be a problem with how I have them nested or something. I'll include a screenshot of my formula!
Feb 27, 2024 02:40 PM - edited Feb 27, 2024 06:37 PM
I think, you need to simplify your formula
put multiple IFs inside single DATEADD
instead of
IF(IS_BEFORE({Session Date), DATETIME_PARSE("03/10/2024", 'MM/DD/YYYY'),
IF(textCalendlyTimezone='America/Los_Angeles',
DATEADD(calculatedCalendlyStartTimeGMT,8, 'hours'),
IF(textCalendlyTimezone='America/Denver',
DATEADD(calculatedCalendlyStartTimeGMT, 7, 'hours'),
IF(textCalendlyTimezone='America/Chicago',
DATEADD(calculatedCalendlyStartTimeGMT, 6, 'hours'),
IF(textCalendlyTimezone='America/New_York',
DATEADD(calculatedCalendlyStartTimeGMT,5, 'hours')
)
)
)
turn them to switch:
IF(IS_BEFORE({Session Date},'2024-10-03',
DATEADD(calculatedCalendlyStartTimeGMT,
SWITCH(textCalendlyTimezone,
'America/Los_Angeles',8,
'America/Denver',7,
'America/Chicago', 6,
'America/New_York', 5),
'hours'))
Also, if you need just 2 possible options: Yes or No, you don't need to use both BEFORE and AFTER. You need it for 3 possible options 'before date' , 'equal to date' , 'after date'
Since you want to know whether you need to shift one hour according to a point in time,
it's OK to use only IS_BEFORE({date} , Yes - add one hour , No - don't add )
or use AFTER to substract. But not both.
You can cut out half of your formula.
Thus, you get:
DATEADD(calculatedCalendlyStartTimeGMT,
SWITCH(textCalendlyTimezone,
'America/Los_Angeles',8,
'America/Denver',7,
'America/Chicago',6,
'America/New_York',5)
-IF(IS_AFTER({Session Date},'2024-03-10 00:00'),1,0),
'hours')
You can also use trick: IF( logical_statement , 1 , 0 ) can be replaced with (statement)
in math formula, TRUE will be converted to 1 , FALSE to 0
Also, last replace to make it simple and understandable
DATEADD(calculatedCalendlyStartTimeGMT,
IS_BEFORE({Session Date},'2024-03-10')+
SWITCH(textCalendlyTimezone,
'America/Los_Angeles',7,
'America/Denver',6,
'America/Chicago',5,
'America/New_York',4),
'hours')
i would think to add default value in SWITCH after ',4
for the case of failed timezone. but that's another story...
Feb 28, 2024 05:09 AM
Last night I had an epiphany as I was trying to fall asleep. (If you're over 50, you understand this completely; if you're not, this is what happens when you're over 50: you forget why you walked into literally every room and right before you're falling asleep you remember AllOfTheThings.) But! The epiphany will only work if the calculateCalendlyStartTimeGMT is calculated using the Session Date field.
I'm imagining that your Session Date is just a date with no time, like 02/15/2024. Then the calculateCalendlyStartTimeGMT converts that Session Date a dateTime field, which in this case would be 02/15/2024 12:00am, and you then want to apply the time zone in the textCalendlyTimezone field to that time.
IF(textCalendlyTimezone='America/Los_Angeles',
SET_TIMEZONE(calculateCalendlyStartTimeGMT,'America/Los_Angeles'),
IF(textCalendlyTimezone='America/Denver',
SET_TIMEZONE(calculateCalendlyStartTimeGMT, 'America/Denver'),
IF(textCalendlyTimezone='America/Chicago',
SET_TIMEZONE(calculateCalendlyStartTimeGMT, 'America/Chicago'),
IF(textCalendlyTimezone='America/New_York',
SET_TIMEZONE(calculateCalendlyStartTimeGMT, 'America/New_York')
)
)
)
)