Forum Discussion
Anonymous
6 years agoNot applicable
Prior Date logic needed
i have these fields (as_of_date,BUSINESS_DAY_IN_MNTH,DAY_NUM_IN_MNTH) in my db. now i want to calculate the prior business day(Prior date) . Consider weekends(sat and sun) , 1st jan and 25th jan are ...
- 6 years ago
Hi Anonymous
As tested, earlier function doesn't work for direct query, create a measure instead
Measure = CALCULATE(MAX('date'[Date]),FILTER(ALL('date'),'date'[Date]<MAX('Sheet1$'[as_of_date])&&[is or not workday]="workday"))Best Regards
MaggieCommunity Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
6 years agoSuper User
Do you have some column that contains holidays
Anonymous
6 years agoNot applicable
ya sir ..
like the below table . On 1st jan is holiday we get 12/31 . for 2 nd jan , we get 12/31 as 1st jan was hoilday .
| AS_OF_DATE | BUSINESS_DAY_IN_MNTH | DAY_NUM_IN_MNTH | Prior Date |
| 1/1/2009 | 0 | 1 | 12/31/2008 |
| 1/2/2009 | 1 | 2 | 12/31/2008 |
| 1/3/2009 | 1 | 3 | 1/2/2009 |
| 1/4/2009 | 1 | 4 | 1/2/2009 |
| 1/5/2009 | 2 | 5 | 1/2/2009 |
- v-juanli-msft6 years agoCommunity Support
Hi Anonymous
Create a new table
date = ADDCOLUMNS ( CALENDARAUTO (), "year", YEAR ( [Date] ), "weeknum", WEEKNUM ( [Date], 2 ), "weekday", WEEKDAY ( [Date], 2 ), "is or not workday", IF ( WEEKDAY ( [Date], 2 ) IN { 6, 7 } || ( MONTH ( [Date] ) = 1 && DAY ( [Date] ) = 1 ) || ( MONTH ( [Date] ) = 1 && DAY ( [Date] ) = 25 ), "not workday", "workday" ) )Create a calculated column
Column = CALCULATE(MAX('date'[Date]),FILTER(ALL('date'),'date'[Date]<EARLIER('Table'[as_of_date])&&[is or not workday]="workday"))Best Regards
MaggieCommunity Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- Anonymous6 years agoNot applicable
Thanks for your response ..
one doubt , is the earlier function works in the direct query ..
- v-juanli-msft6 years agoCommunity Support
Hi Anonymous
As tested, earlier function doesn't work for direct query, create a measure instead
Measure = CALCULATE(MAX('date'[Date]),FILTER(ALL('date'),'date'[Date]<MAX('Sheet1$'[as_of_date])&&[is or not workday]="workday"))Best Regards
MaggieCommunity Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.