Filter
Hi Team,
How can I create a date filter for “previous working day”?
I need it so that when a user logs in on Monday, the “previous day” filter returns Friday’s data (skipping Saturday and Sunday). I also want the filter to work over the last 45 days and current date.
5 replies
-
Ok, let's break it down.
First, - to find today as a date we use the date() function, to which we can add days using addDays().
Next we need to figure out how to take a date and convert it to an element in the date column - you need to convert it to a timestamp and use StrToDate:StrToMember([Dates].[Date],DateToTimeStamp(date())) /* today */ StrToMember([Dates].[Date].[dt],DateToTimeStamp(addDays(date(),-1))) /* yesterday */The next step is to find out what day it is today - you can use DateFormat() function with "E" for the masking to receive the abbreviated day name.
and lastly - you need to use an if statement:
{if( DateFormat(date(), "E") = "Mon", {StrToMember([Dates].[Date],DateToTimeStamp(AddDays(date(),-3)))}, if(DateFormat(date(), "E") = "Sun", {StrToMember([Dates].[Date],DateToTimeStamp(AddDays(date(),-2)))}, /* for Sunday - go back 2 days*/ {StrToMember([Dates].[Date].[dt],DateToTimeStamp(AddDays(date(),-1)))} /* for any other case - go back 1 days*/ ) ) }I hope this helps,
Moshe
-
Hi ,
The items you suggested are working, but our previous “prior period” formulas are no longer behaving correctly after we added the custom date filter.
We have two formulas:
Formula A shows the current period values.
Formula B should show the previous period values.
For example, when we select “Current Week”, Formula A should show this week’s values and Formula B should show last week’s values. After adding the custom filter, Formula A still works, but Formula B no longer returns the correct prior period.
Could you please suggest how to adjust the “previous period” formula so it works with the new custom date filter? Ideally, we would like it to work dynamically so that, for any selected date range, the second formula always shows the corresponding previous range.
Thank you in advance. -
you should try out the Time Calc Wizard. It will help you build some of this logic and you can then edit it as needed.