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

Date Function (DAX)

I am after a DAX function I can enter into a new collumn into my Dataset that will look at a data field in the same dataset and will give me a date value 2 days from that date.  

 

The kicker is i need it to not include weekends as it needs to be business days only. 

 

Thankyou.  

 

 

 

 

 

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

@Wecks,

 

You may check the DAX below.

Column =
VAR d = USERS[HDATE]
RETURN
    MINX (
        FILTER (
            USERS,
            DATEDIFF ( d, USERS[HDATE], DAY ) >= 2
                && NOT ( WEEKDAY ( USERS[HDATE] ) IN { 1, 7 } )
        ),
        USERS[HDATE]
    )
Community Support Team _ Sam Zha
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
v-chuncz-msft
Community Support
Community Support

@Wecks,

 

You may check the DAX below.

Column =
VAR d = USERS[HDATE]
RETURN
    MINX (
        FILTER (
            USERS,
            DATEDIFF ( d, USERS[HDATE], DAY ) >= 2
                && NOT ( WEEKDAY ( USERS[HDATE] ) IN { 1, 7 } )
        ),
        USERS[HDATE]
    )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for this,  there is only one issue i am seeing and that is that if a day is monday for example i have a HDate that is the 10th od December it is giving me a date of the 14th which is four days not 2 days passed the HDATE,  do you know why that would be?

Greg_Deckler
Super User
Super User

I believe that something like this will work with everything unless your original date is on a weekend. Could add a check for that if necessary and adjust.

 

Column = 
VAR __days = 2
VAR __futureDays = __days + 2
VAR __table = FILTER(ADDCOLUMNS(CALENDAR([Date],[Date]+__futureDays),"__weekday",WEEKDAY([Date],2)),[__weekday]<6)
RETURN
IF(COUNTX(__table,[Date])>__days+1,[Date]+2,MAXX(__table,[Date]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks Greg,

 

I am not as proficient in Power BI as your good self,  i was wondering if you are able to highlight the areas i need to change to fit. 

 

My collumns are HDATE and the Table is called USERS.

 

Also the date from will always be in the week so that should not be a problem.  

 

 

Wecks
Frequent Visitor

Also i forgot to mention HDATE may contain some blanks so this may need to be taken into consideration. 

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.