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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
arelf27
Helper II
Helper II

DAX Measure w/ Lookup value equal to Today minus # workdays (already have Dates tbl & Workday fld)

I have a Dates table that has two columns: Date (all calendar dates from 2000 going forward...) and Workday that has 1 for (Mon - Fri) and 0 (if Sat or Sun).   I just need to find today's date minus 10 workdays and use it to filter out data in a visual...

 

I can't figure out how to do it in DAX: Select date from Dates table that's equal to Today, then minus 10 days where Workday is equal to 1. (So I'm trully counting 10 workdays from today, not just 10 days (which would include weekends)

 

Dates:

Date                 Workday

1/30/2018        1

1/31/2018        1 

2/1/2018          1

2/2/2018          1

2/3/2018          0

2/4/2018          0

2/5/2018          1

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @arelf27

 

You can use something like this

 

10 days back =
CALCULATE (
    MIN ( Dates[Date] ),
    TOPN (
        10,
        FILTER (
            ALL ( Dates ),
            Dates[Date] < SELECTEDVALUE ( Dates[Date] )
                && Dates[Workday] = 1
        ),
        [Date], DESC
    )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

Hi @arelf27

 

You can use something like this

 

10 days back =
CALCULATE (
    MIN ( Dates[Date] ),
    TOPN (
        10,
        FILTER (
            ALL ( Dates ),
            Dates[Date] < SELECTEDVALUE ( Dates[Date] )
                && Dates[Workday] = 1
        ),
        [Date], DESC
    )
)

Regards
Zubair

Please try my custom visuals

The TopN function worked beatifully! Thank You 

 

I substituted: Dates[Date] < SELECTEDVALUE ( Dates[Date] ) with just  Dates[Date] < TODAY()

If it's truly just a list of weekday = 1, weekend = 0 and doesn't take into account public holidays then you could just subtract 14 from your current date column, but I'm guessing it actually does...

@arelf27

 

10daysbefore.png


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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