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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Generate Date Difference Calculation Formulas

Good afternoon, how are you? I have a question in Power bi.

I have the following problem: I have a data table, where I have a "Project" column, an "Initial Status" column, and a "Result Status" column. When a project is created, an identifier is assigned, and it is set to "Created" in the initial state, and when the project is submitted, it is set to "Submitted" in the result state.

I need to calculate the average number of days between when the project is created and when it is submitted.

I don't know how to calculate the delay of days per project, then do the sum and divide by the number of projects. Can you help me? Thank you!

ProjectInitial StatusEstado Result.F. This. TareaF. Real Purpose
INFM-23016In EstimationIn Approval31/1/20231/2/2023
INFM-23016CreatedUnassigned31/1/202331/1/2023
INFM-23016UnassignedIn Estimation31/1/202331/1/2023
INFM-23016In EstimationIn Review31/1/20239/2/2023
INFM-23016CreatedIn Estimation31/1/202331/1/2023
INFM-23016In Approval100% Progress1/2/20239/2/2023
INFP-21591In PlanningIn Approval16/3/202316/3/2023
INFP-21591In ApprovalApproved16/3/202316/3/2023
INFM-23016In ReviewIn Planning9/2/202313/2/2023
INFP-21591EnvoyOvercome15/3/202315/3/2023
INFP-21591In ReviewIn Planning15/3/202316/3/2023
INFP-21591CreatedEnvoy20/10/202224/10/2022
INFM-23016In PlanningIn Approval13/2/202313/2/2023
INFP-21591ApprovedEnvoy16/3/202317/3/2023
INFM-23016In ApprovalApproved13/2/202314/2/2023
INFF-23103CreatedIn Estimation3/7/20233/7/2023
INFM-23016ApprovedEnvoy14/2/202315/2/2023
1 ACCEPTED SOLUTION

@Syndicate_Admin 

then you need to create a date table.

Table 2 = CALENDAR(min('Table'[F. This. Tarea]),max('Table'[F. Real Purpose]))
 
and create a column
isworkday =
VAR _weekday=weekday('Table 2'[Date],1)
return if(_weekday=1 ||_weekday=7,0,1)
 
11.PNG
 
then create measures
new_days =
VAR _min=min('Table'[F. This. Tarea])
var _max=max('Table'[F. Real Purpose])
return sumx(FILTER('Table 2','Table 2'[Date]>=_min&&'Table 2'[Date]<=_max),'Table 2'[isworkday])
 
new_days2 = [new_days]/DISTINCTCOUNT('Table'[Project])
 
11.PNG
pls see the attachment below




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Thank you very much, if that's what I want. I forgot to request that it be difference of working days, Saturday and Sunday is not counted. What would it be like? With networkdays?.

Thanks a lot!

@Syndicate_Admin 

then you need to create a date table.

Table 2 = CALENDAR(min('Table'[F. This. Tarea]),max('Table'[F. Real Purpose]))
 
and create a column
isworkday =
VAR _weekday=weekday('Table 2'[Date],1)
return if(_weekday=1 ||_weekday=7,0,1)
 
11.PNG
 
then create measures
new_days =
VAR _min=min('Table'[F. This. Tarea])
var _max=max('Table'[F. Real Purpose])
return sumx(FILTER('Table 2','Table 2'[Date]>=_min&&'Table 2'[Date]<=_max),'Table 2'[isworkday])
 
new_days2 = [new_days]/DISTINCTCOUNT('Table'[Project])
 
11.PNG
pls see the attachment below




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

@Syndicate_Admin 

is this what you want?

days = DATEDIFF(min('Table'[F. This. Tarea]),max('Table'[F. Real Purpose]),DAY)
days2 = sumx(VALUES('Table'[Project]),[days])
 
average = [days2]/DISTINCTCOUNT('Table'[Project])
 
11.PNG
pls see the attachment below
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

Top Solution Authors