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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
carlosagarcia
Helper I
Helper I

Count week days to calculate delivery time

Hello guys.

 

I am trying to create a meassure that only counts week days to calculate the delivery for an item.

I have a purchasing lead time of 10 days, if the order is entered today 06/12/2020, the estimated time of delivery should be 06/25/2020

 

Part     Lead time    Delivery date

123          10                 ??? 

 

I know it sounds easy, I have tried different methods with no luck.

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

Hi @carlosagarcia ,

 

You need to create a date dimension.

Date =
CALENDAR ( DATE ( 2020, 01, 01 ), DATE ( 2020, 12, 31 ) )

Then create columns to show working days and running total. 

Count =
VAR a = WEEKDAY ( 'Date'[Date], 2 ) RETURN IF ( a < 6, 1, 0 )
Sum =
CALCULATE (
    SUM ( 'Date'[Count] ),
    FILTER ( 'Date', 'Date'[Date] <= EARLIER ( 'Date'[Date] ) )
)

Create a measure to show date.

Measure =
VAR a =
    SELECTEDVALUE ( 'Table'[Date] )
VAR b =
    SELECTEDVALUE ( 'Table'[Days] )
VAR c =
    CALCULATE ( MAX ( 'Date'[Sum] ), FILTER ( 'Date', 'Date'[Date] = a ) )
RETURN
    CALCULATE (
        MAX ( 'Date'[Date] ),
        FILTER ( 'Date', 'Date'[Sum] = b + c - 1 && 'Date'[Count] = 1 )
    )

Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

5 REPLIES 5
v-eachen-msft
Community Support
Community Support

Hi @carlosagarcia ,

 

You need to create a date dimension.

Date =
CALENDAR ( DATE ( 2020, 01, 01 ), DATE ( 2020, 12, 31 ) )

Then create columns to show working days and running total. 

Count =
VAR a = WEEKDAY ( 'Date'[Date], 2 ) RETURN IF ( a < 6, 1, 0 )
Sum =
CALCULATE (
    SUM ( 'Date'[Count] ),
    FILTER ( 'Date', 'Date'[Date] <= EARLIER ( 'Date'[Date] ) )
)

Create a measure to show date.

Measure =
VAR a =
    SELECTEDVALUE ( 'Table'[Date] )
VAR b =
    SELECTEDVALUE ( 'Table'[Days] )
VAR c =
    CALCULATE ( MAX ( 'Date'[Sum] ), FILTER ( 'Date', 'Date'[Date] = a ) )
RETURN
    CALCULATE (
        MAX ( 'Date'[Date] ),
        FILTER ( 'Date', 'Date'[Sum] = b + c - 1 && 'Date'[Count] = 1 )
    )

Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Hello, 

 

I am ready to test your answer but I get stuck on the Messure column.

I get an error on 

 

Measure =
VAR a =
SELECTEDVALUE ( 'Table'[Date] ),  I need this section to be today ot tomorrows date.
I have no date to go by, I am just assuming that if the parts are ordered today or tomorrow, what the expected date should be.
I tried creating a column with todays date but the messure doesnt see it.
Any ideas?

 

 

Hi @carlosagarcia ,

 

Change it to be TODAY() or TODAY()+1.

var a = TODAY()

Make sure that the date dimension have all dates you need in the future.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Thank you, worked like a charm. 

amitchandak
Super User
Super User

@carlosagarcia , Have a date table with following field

Table
Date = CALENDAR(date(2018,01,01), date(2021,12,31)) 
Columns
Work Day = if(WEEKDAY([Date],2)>=6,0,1) 
Work Date = if(WEEKDAY([Date],2)>=6,BLANK(),[Date])  
Work Date Cont = if([Work Day]=0,maxx(FILTER('Date',[Date]<EARLIER([Date]) && [Work Day]<> EARLIER([Work Day]) ),[Date]),[Date])
Work Date cont Rank = RANKX(ALL('Date'),[Work Date Cont],,ASC,Dense)

Use Rank to Travel . Example Measure
Plus 10 Days = var _max =maxx(ALLSELECTED('Date'),'Date'[Work Date cont Rank])
return CALCULATE(Min('Date'[Date]),filter(ALL('Date'),'Date'[Work Date  Rank] =_max+10))

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.