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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply

Generating Average time to resolution excluding weekends in last 30 days

Hi,

  I am trying to create a report that displays the average time to reolve a ticket in the last 30 days. This must exclude weekends.

How can I achieve this with DAX?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Radhika_Kanaka ,

 

You will need to create a weekday column.

_weekday = WEEKDAY('Table'[date])
Then create a rank column.
ranks =
var _rank = RANKX(FILTER('Table','Table'[_weekday]<6),'Table'[date],,DESC,Skip)
return
IF('Table'[_weekday]<6,_rank,99999)
Then create the average column.
_average = CALCULATE(AVERAGE('Table'[value]),FILTER('Table','Table'[ranks]<EARLIER('Table'[ranks])+30&&'Table'[ranks]>=EARLIER('Table'[ranks])))
vjaywmsft_0-1649184140703.png

 

Best Regards,

Jay

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Radhika_Kanaka ,

 

You will need to create a weekday column.

_weekday = WEEKDAY('Table'[date])
Then create a rank column.
ranks =
var _rank = RANKX(FILTER('Table','Table'[_weekday]<6),'Table'[date],,DESC,Skip)
return
IF('Table'[_weekday]<6,_rank,99999)
Then create the average column.
_average = CALCULATE(AVERAGE('Table'[value]),FILTER('Table','Table'[ranks]<EARLIER('Table'[ranks])+30&&'Table'[ranks]>=EARLIER('Table'[ranks])))
vjaywmsft_0-1649184140703.png

 

Best Regards,

Jay

When I tried to invoke the function with Datetime datatype columns. The resultant custom column is displaying the below error:

 

Expression.Error: We cannot convert the value #datetime(2022, 3, 22, 17, 34, 0) to type Date.
Details:
Value=3/22/2022 5:34:00 PM
Type=[Type]

if this the custom function

(InitialDate as date, FinalDate as date ) as number => 
let
DaysBetweenDates = Duration.Days(FinalDate-InitialDate),
DaysList = List.Dates(List.Min({InitialDate,FinalDate}),Number.Abs(DaysBetweenDates)+1, Duration.From(1)),
WeekDaysList = List.Select(DaysList, each (Date.DayOfWeek(_, Day.Monday) < 5) ),
WorkingDays = (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList)
in
WorkingDays


You might want to consider InitialDate as datetime, FinalDate as datetime

Also check this tutorial out. I hope it helps

@Tutu_in_YYC  Thank you for your quick response.

I managed to get M code that displays resolution time in days excluding weekends. My requirement is to get the resolution time (difference between created date and resolved date)in hours, minutes, seconds. M code is new to me. Would you be able to help on this?? Attaching the M code for reference. Appreciate your response.

 

(InitialDate as date, FinalDate as date ) as number => 
let
DaysBetweenDates = Duration.Days(FinalDate-InitialDate),
DaysList = List.Dates(List.Min({InitialDate,FinalDate}),Number.Abs(DaysBetweenDates)+1, Duration.From(1)),
WeekDaysList = List.Select(DaysList, each (Date.DayOfWeek(_, Day.Monday) < 5) ),
WorkingDays = (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList)
in
WorkingDays

 

Tutu_in_YYC
Super User
Super User

Hi Radhika,
There are so many options, it will depends on the data that you have and how you want to model it. If you have some sample data that you are working on, we can probably figure out a direction and try to leverage the function DATEDIFF.

But the general idea is to use time-intelligence functions to generate the metrics you want to track. Have a look at these DAX patterns

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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