Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not 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 hoildays . 

 

for example:

if that date in the as_of_date fall on hoilday we need to  get last working day or if the date in the as_of_date fall on weekday we need get to previous working day. Below is the table for refernece .

as_of_dateBUSINESS_DAY_IN_MNTHDAY_NUM_IN_MNTHPrior date
5/15/201110155/13/2011
5/16/201111165/13/2011
5/17/201112175/16/2011
5/18/201113185/17/2011
5/19/201114195/18/2011
5/20/201115205/19/2011
5/21/201115215/20/2011
5/22/201115225/20/2011
5/23/201116235/20/2011
5/24/201117245/23/2011

 

1 ACCEPTED SOLUTION

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"))

Capture11.JPG

Best Regards
Maggie
Community 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.

 

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

Do you have some column that contains holidays

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not 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_DATEBUSINESS_DAY_IN_MNTHDAY_NUM_IN_MNTHPrior Date
1/1/20090112/31/2008
1/2/20091212/31/2008
1/3/2009131/2/2009
1/4/2009141/2/2009
1/5/2009251/2/2009

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"
    )
)

Capture21.JPGCapture22.JPG

 

Create a calculated column

Column = CALCULATE(MAX('date'[Date]),FILTER(ALL('date'),'date'[Date]<EARLIER('Table'[as_of_date])&&[is or not workday]="workday"))

Capture23.JPG

Best Regards
Maggie
Community 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.
Anonymous
Not applicable

Thanks for your response .. 

 

one doubt , is the earlier function works in the direct query .. 

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"))

Capture11.JPG

Best Regards
Maggie
Community 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.

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.