<aside>
By Locominder | Notion Templates | Twitter | Threads
</aside>
<aside>
Write formula for “Return a workday date excluding weekends within the property “Date”’s month based on the “Workday Number” property
</aside>
lets(
/* Get the input date or default to today */
inputDate, if(empty(prop("Date")), today(), prop("Date")),
/* Get the workday number or default to 1 */
workdayNum, if(empty(prop("Workday Number")) or prop("Workday Number") < 1, 1, prop("Workday Number")),
/* Get the first day of the month */
firstDay, dateAdd(inputDate, -1 * date(inputDate) + 1, "days"),
/* Get the last day of the month */
lastDay, dateSubtract(dateAdd(firstDay, 1, "months"), 1, "days"),
/* Calculate total days in month */
daysInMonth, date(lastDay),
/* Create a list of all days in the month */
allDays, map(slice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], 0, daysInMonth),
dateAdd(firstDay, index, "days")
),
/* Filter to only weekdays (day returns 1-7 where 1=Monday, 6-7=weekend) */
weekdaysOnly, filter(allDays, day(current) < 6),
/* Get the Nth workday or return error message if out of range */
if(workdayNum <= weekdaysOnly.length(),
weekdaysOnly.at(workdayNum - 1),
"No valid workday found")
)