Hi - Not sure if anyone can help. But I'm struggling to filter records where the date is the day before the current date, and if its a Sat or Sun then select the previous Friday.
The EFFECTDATE is a text field so I converted it to date format. but i'm stuck as I can't even get it to filter for the previous day today()-1, so I wouldn't know how to filter for the previous friday if the previous day is a weekend.
Hi @daniela,
Here is a formula that would return the last Friday for previous dates falling on a weekend:
let previous = [Date as number] - 1
IF isweekend(previous) THEN weekend(previous)-1 ELSE previous
Example:
previous-weekday.morph (3.4 KB)
1 Like
Thank you so much! I would never have figured this out! ![:slight_smile: :slight_smile:](https://community.easymorph.com/images/emoji/twitter/slight_smile.png?v=12)
Hi @dgudkov
For some reason the one that i downloaded results in future dates and not previous dates. Not sure why that is
I noticed it only does it for the dates that land on Monday.
this sort of works - it at least works for today's date, not sure why it messes up once it hits Sunday. But I may be able to work with it ![:slight_smile: :slight_smile:](https://community.easymorph.com/images/emoji/twitter/slight_smile.png?v=12)
Oh, I misunderstood the initial question. You need to check whether the current day falls on a weekend, not the previous one. In this case, the expression would be:
IF isweekend([Date as number]) THEN weekend([Date as number] - 1)-1 ELSE [Date as number]
The logic of the expression works as follows:
IF isweekend([Date as number])
checks whether the current date falls on a weekend (i.e. Sat or Sun).
If it does, then weekend([Date as number] - 1)
returns the end of the week (as you can understand of the function name). We deduct 1, so that for Sundays it returns the previous Saturday, not the next one.
Finally, -1
to receive Friday from Saturday, because we need the last workday of that week.
Here is the updated example:
previous-weekday.morph (3.4 KB)
![image](https://community.easymorph.com/uploads/default/original/2X/7/74816caefb676cdd1516b840de0ce1acff476620.png)
Ah yes, I'm sorry I didn't explain it well. Thank you so much ! this is exactly what I"m looking for! ![:slight_smile: :slight_smile:](https://community.easymorph.com/images/emoji/twitter/slight_smile.png?v=12)