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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
byebytoad9766
Regular Visitor

DAX to count how many tasks have not completed in time.

Hi,

I'm currently working on constructing a line chart to illustrate tasks/projects that were not completed within the expected timeframe.

We have four distinct types of tasks: Support call, Task, Assignment, and Project. Each of these tasks has its own predefined time threshold for completion, which are 3, 14, 90, and 180 days respectively.

My aim is to depict, using the first day of each month as a reference point, the combined count of tasks that were still open on that day and exceeded the allotted time, along with tasks that were closed in the previous month but were closed beyond the expected timeframe.

 

Please find below a sample table as an example:

IDNameOpening DateCompletion DateTask Type   
PT00001Name 0000124/08/202301/02/2024Project   
PT00002Name 0000211/09/202328/09/2023Task Project180 days
PT00003Name 0000322/09/2023 Assignment Task14 days
PT00004Name 0000413/10/202323/10/2023Support Ticket Assignment90 days
PT00005Name 0000511/09/202309/01/2024Project Support Ticket 3 days
PT00006Name 0000606/10/202318/10/2024Task   
PT00007Name 0000719/10/202302/02/2024Assignment   
PT00008Name 0000816/11/202320/11/2023Support Ticket   
PT00009Name 0000917/11/2023 Project   
PT00010Name 0001020/11/202321/11/2023Support Ticket   
PT00011Name 0001121/11/202301/12/2023Support Ticket   
PT00012Name 0001222/11/202322/11/2023Support Ticket   
PT00013Name 0001309/12/2023 Project   
PT00014Name 0001424/12/202309/01/2024Task   
PT00015Name 0001518/01/2024 Assignment   
PT00016Name 0001620/01/202428/01/2024Support Ticket   
PT00017Name 0001710/01/202420/01/2024Support Ticket   
PT00018Name 0001831/01/202411/04/2024Task   
PT00019Name 0001922/02/2024 Assignment   

 

 

If the DAX is correct, it should count as follows: 

     Total
SeptID 02 (late completion within the month)   1
OctID04 (late completion within the month)   1
NovID08 (late completion within the month)ID08 (late completion )  2
Dec    0
JanID 003 (Assignment went over the threshold during Jan)  1
FebID 014 (Task went over the threshold during Jan)ID 003 (Assignment went over the threshold during Jan)ID 016 (late completion within the month)ID 017 (late completion within the month)4
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @byebytoad9766 ,

The table  data is shown below:

vzhouwenmsft_0-1709101926456.png

Please follow these steps:
1. Use the following DAX expression to create a column named ‘Spend Time’

 

Spend Time = IF(ISBLANK('Tabelle1'[Completion Date]),0,DATEDIFF('Tabelle1'[Opening Date],'Tabelle1'[Completion Date],DAY)) 

 

2. Use the following DAX expression to create a column named ‘Deadline’

 

Deadline = IF('Tabelle1'[Spend Time] <> 0,
BLANK(),
SWITCH(TRUE(), 
'Tabelle1'[Task Type] = "Project",'Tabelle1'[Opening Date] + 180,
'Tabelle1'[Task Type] = "Task",'Tabelle1'[Opening Date] + 14,
'Tabelle1'[Task Type] = "Assignment",'Tabelle1'[Opening Date] + 90,
'Tabelle1'[Task Type] = "Support Ticket",'Tabelle1'[Opening Date] + 3))

 

3. Use the following DAX expression to create a column named ‘CheckMonth’

 

CheckMonth = IF('Tabelle1'[Spend Time] <> 0 ,
IF('Tabelle1'[Completion Date].[MonthNo] = 12,
DATE('Tabelle1'[Completion Date].[Year] + 1,1,1),
DATE('Tabelle1'[Completion Date].[Year],'Tabelle1'[Completion Date].[MonthNo] +1 ,1)),
IF('Tabelle1'[Deadline].[Day] = 1,[Deadline],
IF('Tabelle1'[Deadline].[MonthNo] = 12,
DATE('Tabelle1'[Deadline].[Year] + 1,1,1),
DATE('Tabelle1'[Deadline].[Year],'Tabelle1'[Deadline].[MonthNo] +1 ,1))))

 

4. Use the following DAX expression to create a column named ‘Whether it timed out’

 

Whether it timed out = IF('Tabelle1'[Spend Time] <> 0,
SWITCH(TRUE(),
'Tabelle1'[Task Type] = "Project" && 'Tabelle1'[Spend Time] <= 180 ,"NO",
'Tabelle1'[Task Type] = "Task" && 'Tabelle1'[Spend Time] <= 14 ,"NO",
'Tabelle1'[Task Type] = "Assignment" && 'Tabelle1'[Spend Time] <= 90 ,"NO",
'Tabelle1'[Task Type] = "Support Ticket" && 'Tabelle1'[Spend Time] <= 3 ,"NO",
"YES"
),
"YES")

 

5. Use the following DAX expression to create a measure named ‘Timeout’

 

Timeout = COUNTROWS(FILTER('Tabelle1','Tabelle1'[Whether it timed out] = "YES"))

 

6. Final output

vzhouwenmsft_0-1709102232054.png

 

vzhouwenmsft_2-1709102139688.png


Best Regards,
Wenbin Zhou
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

2 REPLIES 2
Anonymous
Not applicable

Hi @byebytoad9766 ,

The table  data is shown below:

vzhouwenmsft_0-1709101926456.png

Please follow these steps:
1. Use the following DAX expression to create a column named ‘Spend Time’

 

Spend Time = IF(ISBLANK('Tabelle1'[Completion Date]),0,DATEDIFF('Tabelle1'[Opening Date],'Tabelle1'[Completion Date],DAY)) 

 

2. Use the following DAX expression to create a column named ‘Deadline’

 

Deadline = IF('Tabelle1'[Spend Time] <> 0,
BLANK(),
SWITCH(TRUE(), 
'Tabelle1'[Task Type] = "Project",'Tabelle1'[Opening Date] + 180,
'Tabelle1'[Task Type] = "Task",'Tabelle1'[Opening Date] + 14,
'Tabelle1'[Task Type] = "Assignment",'Tabelle1'[Opening Date] + 90,
'Tabelle1'[Task Type] = "Support Ticket",'Tabelle1'[Opening Date] + 3))

 

3. Use the following DAX expression to create a column named ‘CheckMonth’

 

CheckMonth = IF('Tabelle1'[Spend Time] <> 0 ,
IF('Tabelle1'[Completion Date].[MonthNo] = 12,
DATE('Tabelle1'[Completion Date].[Year] + 1,1,1),
DATE('Tabelle1'[Completion Date].[Year],'Tabelle1'[Completion Date].[MonthNo] +1 ,1)),
IF('Tabelle1'[Deadline].[Day] = 1,[Deadline],
IF('Tabelle1'[Deadline].[MonthNo] = 12,
DATE('Tabelle1'[Deadline].[Year] + 1,1,1),
DATE('Tabelle1'[Deadline].[Year],'Tabelle1'[Deadline].[MonthNo] +1 ,1))))

 

4. Use the following DAX expression to create a column named ‘Whether it timed out’

 

Whether it timed out = IF('Tabelle1'[Spend Time] <> 0,
SWITCH(TRUE(),
'Tabelle1'[Task Type] = "Project" && 'Tabelle1'[Spend Time] <= 180 ,"NO",
'Tabelle1'[Task Type] = "Task" && 'Tabelle1'[Spend Time] <= 14 ,"NO",
'Tabelle1'[Task Type] = "Assignment" && 'Tabelle1'[Spend Time] <= 90 ,"NO",
'Tabelle1'[Task Type] = "Support Ticket" && 'Tabelle1'[Spend Time] <= 3 ,"NO",
"YES"
),
"YES")

 

5. Use the following DAX expression to create a measure named ‘Timeout’

 

Timeout = COUNTROWS(FILTER('Tabelle1','Tabelle1'[Whether it timed out] = "YES"))

 

6. Final output

vzhouwenmsft_0-1709102232054.png

 

vzhouwenmsft_2-1709102139688.png


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

123abc
Community Champion
Community Champion

To construct a DAX (Data Analysis Expressions) formula to count tasks that were not completed within the expected timeframe, you can follow these steps:

  1. Create a calculated column for each task to calculate the expected completion date based on its type.
  2. Use DAX measures to count tasks that were open on the first day of each month and exceeded the allotted time, along with tasks closed in the previous month but beyond the expected timeframe.

Let's break down each step:

  1. Create calculated columns:
    • You need to calculate the expected completion date based on the task type. You can create a calculated column for each task type. Here's how you can calculate the expected completion date for each task type:

Expected_Completion_Date =
SWITCH (
'SampleTable'[Task Type],
"Project", 'SampleTable'[Opening Date] + 180,
"Assignment", 'SampleTable'[Opening Date] + 14,
"Task", 'SampleTable'[Opening Date] + 14,
"Support Ticket", 'SampleTable'[Opening Date] + 3,
BLANK ()
)

 

Create DAX measures:

  • You need to count tasks that were still open on the first day of each month and exceeded the allotted time, along with tasks closed in the previous month but were closed beyond the expected timeframe.

 

Tasks_Not_Completed_On_Time =
VAR CurrentMonth = MONTH ( TODAY () )
VAR CurrentYear = YEAR ( TODAY () )
RETURN
CALCULATE (
COUNTROWS ( 'SampleTable' ),
FILTER (
'SampleTable',
(
YEAR ( 'SampleTable'[Completion Date] ) = CurrentYear &&
MONTH ( 'SampleTable'[Completion Date] ) = CurrentMonth - 1 &&
'SampleTable'[Completion Date] > 'SampleTable'[Expected_Completion_Date]
) ||
(
ISBLANK ( 'SampleTable'[Completion Date] ) &&
YEAR ( 'SampleTable'[Opening Date] ) = CurrentYear &&
MONTH ( 'SampleTable'[Opening Date] ) = CurrentMonth &&
TODAY () > 'SampleTable'[Expected_Completion_Date]
)
)
)

 

Tasks_Not_Completed_On_Time =
VAR CurrentMonth = MONTH ( TODAY () )
VAR CurrentYear = YEAR ( TODAY () )
RETURN
CALCULATE (
COUNTROWS ( 'SampleTable' ),
FILTER (
'SampleTable',
(
YEAR ( 'SampleTable'[Completion Date] ) = CurrentYear &&
MONTH ( 'SampleTable'[Completion Date] ) = CurrentMonth - 1 &&
'SampleTable'[Completion Date] > 'SampleTable'[Expected_Completion_Date]
) ||
(
ISBLANK ( 'SampleTable'[Completion Date] ) &&
YEAR ( 'SampleTable'[Opening Date] ) = CurrentYear &&
MONTH ( 'SampleTable'[Opening Date] ) = CurrentMonth &&
TODAY () > 'SampleTable'[Expected_Completion_Date]
)
)
)

 

 

This measure calculates the count of tasks meeting the specified conditions for each month. It counts tasks closed in the previous month but beyond the expected timeframe, as well as tasks that are still open on the first day of the current month and exceeded the allotted time.

Ensure to replace 'SampleTable' with the actual name of your table in Power BI or whichever tool you're using. Also, ensure that the column names in the formulas match the column names in your dataset.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.