Help

Move task on the monday when it's saturday or sunday?

Topic Labels: Formulas
Solved
Jump to Solution
1555 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Jacek_Greber
4 - Data Explorer
4 - Data Explorer

Hey Guys,

first time here. Airtable support forwarded me here. I need your help.

I have a such formula:

IF(
{routine type}=‘daily’,
DATEADD({task date}, 1, ‘days’),
IF(
{routine type}=‘weekly’,
DATEADD({task date}, 7, ‘days’),
IF(
{routine type}=‘bi-weekly’,
DATEADD({task date}, 14, ‘days’),
IF(
{routine type}=‘monthly’,
DATEADD({task date}, 30, ‘days’)
)
)
)
)

and I would like to combine it with something like this:

IF(
WEEKDAY({next date})=0,
DATEADD({next date}, 1, ‘days’),
IF(
WEEKDAY({next date})=6,
DATEADD({next date}, 2, ‘days’),
{next date}
)
)

Can you help me, please? The first formula creates new task depending on the routine type. Weekly routine, monthly routine, etc. The second formula should move the task to the Monday if the first formula lands task on the Saturday or Sunday.

Appreciate your help.

Jack

1 Solution

Accepted Solutions

You could simplify that a great deal with SWITCH()

IF(
AND({routine type}, {task date}),
DATEADD({task date}, SWITCH(
  {routine type},
  'daily', SWITCH(WEEKDAY(DATEADD({task date}, 1, 'days')), 0, 2, 6, 3, 1),
  'weekly', SWITCH(WEEKDAY(DATEADD({task date}, 7, 'days')), 0, 8, 6, 9, 7),
  'bi-weekly', SWITCH(WEEKDAY(DATEADD({task date}, 14, 'days')), 0, 15, 6, 16, 14),
  'monthly', SWITCH(WEEKDAY(DATEADD({task date}, 30, 'days')), 0, 31, 6, 32, 30),
  0
), 'days'))

See Solution in Thread

5 Replies 5

Hi @Jacek_Greber ,

Welcome to Airtable Community !

Can you please screenshot those fields so we can understand the relation between them? For example, where is the data for {next date} coming from?

Tip: When pasting a formula here, paste it in the Preformatted text as to make it easier to copy

The formula would look something like that

IF(
{routine type}='daily',
IF(WEEKDAY(DATEADD({task date}, 1, 'days'))=0, 
DATEADD({task date}, 2, 'days'),
IF(WEEKDAY(DATEADD({task date}, 1, 'days'))=6,
DATEADD({task date}, 3, 'days'),
DATEADD({task date}, 1, 'days'))),
IF(
{routine type}='weekly',
IF(WEEKDAY(DATEADD({task date}, 7, 'days'))=0, 
DATEADD({task date}, 8, 'days'),
IF(WEEKDAY(DATEADD({task date}, 7, 'days'))=6, 
DATEADD({task date}, 9, 'days'),
DATEADD({task date}, 7, 'days'))),
IF(
{routine type}='bi-weekly',
IF(WEEKDAY(DATEADD({task date}, 14, 'days'))=0, 
DATEADD({task date}, 15, 'days'),
IF(WEEKDAY(DATEADD({task date}, 14, 'days'))=6, 
DATEADD({task date}, 16, 'days'),
DATEADD({task date}, 14, 'days'))),
IF(
{routine type}='monthly',
IF(WEEKDAY(DATEADD({task date}, 30, 'days'))=0, 
DATEADD({task date}, 31, 'days'),
IF(WEEKDAY(DATEADD({task date}, 30, 'days'))=6, 
DATEADD({task date}, 32, 'days'),
DATEADD({task date}, 30, 'days')))
)
)
)
)

Hope this helps :slightly_smiling_face: If it does, please mark it as Solution

You could simplify that a great deal with SWITCH()

IF(
AND({routine type}, {task date}),
DATEADD({task date}, SWITCH(
  {routine type},
  'daily', SWITCH(WEEKDAY(DATEADD({task date}, 1, 'days')), 0, 2, 6, 3, 1),
  'weekly', SWITCH(WEEKDAY(DATEADD({task date}, 7, 'days')), 0, 8, 6, 9, 7),
  'bi-weekly', SWITCH(WEEKDAY(DATEADD({task date}, 14, 'days')), 0, 15, 6, 16, 14),
  'monthly', SWITCH(WEEKDAY(DATEADD({task date}, 30, 'days')), 0, 31, 6, 32, 30),
  0
), 'days'))

Jacek_Greber
4 - Data Explorer
4 - Data Explorer

I love you Guys! It works :winking_face: