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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Mark_Ball
Frequent Visitor

DAX Help: Calculate second last working day

Good day, Everyone

I need some DAX help. Our Operations wants to measure activity in the last couple ‘Workdays’ of each month (our heaviest billing days). Workdays will be considered M-F (holidays are not a factor). In my dimDate table I have successfully calculated the last working day of each month. Now I need a calculated column to identify the second last work day of the month. If I use a formula like: ‘Last working day’ minus 1 it works for Tuesday through Friday, but Monday turns into Sunday (I would need previous Friday).

 

Calculated Columns in table: (Weekdays = 1, else 0)

Last Work Day =

CALCULATE(MAX([Date]),FILTER(DimDate,DimDate[Workday]=1 && DimDate[FirstOfMonth]=EARLIER([FirstOfMonth])))

 

What did not work for second last workday of month:

First Test =

VAR vLWD = CALCULATE(MAX([Date]),FILTER(DimDate,DimDate[Workday]=1 && DimDate[FirstOfMonth]=EARLIER([FirstOfMonth])))

VAR vResult =

    vLWD - 1

RETURN

vResult

 

also tried the below to provide an identifier like second last work day = 0, this worked for some months, not all:

Work Days from EoM =

VAR vDaycount = if (DimDate[Date] > [Last Work Day], -9, [Last Work Day] - DimDate[Date])

VAR vNonWorkDayCount = CALCULATE(COUNTROWS(DimDate),FILTER(DimDate,DimDate[Date] < EARLIER([EoM]) && DimDate[Date] > EARLIER([Date]) && DimDate[Workday]=0))

VAR vResult = vDaycount - vNonWorkDayCount

RETURN

vResult

 

Any help is appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Mark_Ball ,

 

I think you can try this code to create a calculated column.

 

Second last workday = 
CALCULATE (
    MAX ( DimDate[Date] ),
    FILTER (
        DimDate,
        DimDate[Workday] = 1
            && DimDate[FirstOfMonth] = EARLIER ( DimDate[FirstOfMonth] )
            && DimDate[Date] < DimDate[Last Work Day]
    )
)

 

Result is as  below.

RicoZhou_0-1663655878103.png

We can see that in January 2022, last work day is 2022/01/31 (Monday), the second work day is 2022/01/28.

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Mark_Ball
Frequent Visitor

Thank you both for your suggested formulas. @Anonymous your formula worked perfect! I also attemped yours @amitchandak but the final rank formula was missing something after 'earlier([monthend]) and i couldn't finish it off to make it work for me. I appreciate everyones help!

Anonymous
Not applicable

Hi @Mark_Ball ,

 

I think you can try this code to create a calculated column.

 

Second last workday = 
CALCULATE (
    MAX ( DimDate[Date] ),
    FILTER (
        DimDate,
        DimDate[Workday] = 1
            && DimDate[FirstOfMonth] = EARLIER ( DimDate[FirstOfMonth] )
            && DimDate[Date] < DimDate[Last Work Day]
    )
)

 

Result is as  below.

RicoZhou_0-1663655878103.png

We can see that in January 2022, last work day is 2022/01/31 (Monday), the second work day is 2022/01/28.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Mark_Ball ,

 

Create a new columns ---

 

work date = if(weekday([Date],2) <6, [Date], blank())

month end  = eomonth([Date],0)

 

Work day rank = if(isblank([work date]) , blank(), rankx(filter(Date,[month end]  = earlier([month end])) , [work date],,desc,dense)

 

Final rank = [Work day rank] - minx(filter(Date,[month end]  = earlier([month end])), [Work day rank]) +1

 

 

Because of blank rank may start with 2, so adjusted that.

 

Now you need final rank =2

 

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.