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
TStan
Frequent Visitor

HELP ME!

Hi there,

 

I need some DAX code which matches an upload date (today's date) in my fact table to the Date column in my Date Table. I then need a column which returns True if the date falls within the previous 7 working days and false if it does not. 

I intend to then add that as a filter to my visual to get a dynamic 7 day rolling result.

Thanks in advance.

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @TStan ,

 

Here are the steps you can follow:

1. Create measure.

Flag =
var _if=
IF(
    WEEKDAY(MAX('Fact Table'[Date]),2) in {6,7} || MAX('Fact Table'[Date])>TODAY(), BLANK(),
RANKX(
    FILTER(ALLSELECTED('Fact Table'),
    NOT(WEEKDAY('Fact Table'[Date],2)) in {6,7} &&'Fact Table'[Date]<=TODAY() ),CALCULATE(MAX('Fact Table'[Date])),,DESC))
return
IF(
    _if>1&&_if<=8&&_if<>BLANK(),1,0)

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1697600149217.png

3. Result:

vyangliumsft_1-1697600149218.png

 

 

Best Regards,

Liu Yang

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

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @TStan ,

 

Here are the steps you can follow:

1. Create measure.

Flag =
var _if=
IF(
    WEEKDAY(MAX('Fact Table'[Date]),2) in {6,7} || MAX('Fact Table'[Date])>TODAY(), BLANK(),
RANKX(
    FILTER(ALLSELECTED('Fact Table'),
    NOT(WEEKDAY('Fact Table'[Date],2)) in {6,7} &&'Fact Table'[Date]<=TODAY() ),CALCULATE(MAX('Fact Table'[Date])),,DESC))
return
IF(
    _if>1&&_if<=8&&_if<>BLANK(),1,0)

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1697600149217.png

3. Result:

vyangliumsft_1-1697600149218.png

 

 

Best Regards,

Liu Yang

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

Thank you so much - this works perfectly.

Best Regards,

Tim

vicky_
Super User
Super User

Consider using the NETWORKDAYS function to find the previous 7 working days:

dateInLast7WorkingDays =
var a = CALCULATE(NETWORKDAYS(SELECTEDVALUE('Table'[Date]), TODAY()), KEEPFILTERS('Table'[Date])) 
return COUNTROWS(FILTER('Table', a > 0 && a <= 8))

You can pass in a list of holidays to the NETWORKDAYS() function for more accurate results. 

TStan
Frequent Visitor

That works however I need it to exclude Saturday/Sundays and return the last 7 working days. Any ideas?

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

April Fabric Community Update

Fabric Community Update - April 2024

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

March 2024 PBI Gallery Image

Power BI Monthly Update - March 2024

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

Top Solution Authors