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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Sebas7
Regular Visitor

TAT Calculation based on Next Group

Hi,

 

I am struggling for some days to calculate the TAT for each case based on the actions done by each group and excluding weekends.

 

For example we have a case which was actioned by Group A, B, C & D and I want to find how long it took to be actioned by that group from start date to end date excluding weekends. It might be that the case was actioned by the same group twice. Each time the TAT is restarted when is actioned by another.

 

How can I calculate the TAT in Power BI. Do you think this is possible? I tried using RANKX and DATESBETWEEN but without success.

 

Below is an example on how my data looks like and how the TAT column should be at the end.

Case

Date

Group

TAT

Case-1879

02/09/2017 01:13

A

0

Case-1879

02/09/2017 02:39

A

Case-1879

02/09/2017 02:39

A

Case-1879

02/09/2017 02:39

B

0

Case-1879

02/09/2017 02:39

B

Case-1879

02/09/2017 02:39

C

1 Day

Case-1879

02/09/2017 02:39

C

Case-1879

02/09/2017 02:39

C

Case-1879

04/09/2017 10:14

C

Case-1879

05/09/2017 06:55

B

1 Day

Case-1879

05/09/2017 06:55

B

Case-1879

05/09/2017 09:55

B

Case-1879

05/09/2017 09:55

B

Case-1879

05/09/2017 15:13

B

Case-1879

05/09/2017 15:14

C

4 Day

Case-1879

09/09/2017 15:15

C

Case-1879

09/09/2017 15:15

D

1 Day

Case-1879

11/09/2017 18:31

D

Case-1879

11/09/2017 18:31

D


Thank you and regards, 

Sebas.

1 ACCEPTED SOLUTION

Hi @Sebas7,

 

You can create a calendar table (Calendar = CALENDAR("2017-9-1",TODAY())) and add a index column in Query Editor,then create calculated columns below in the fact table: 

 

WinStreak =
var LastLossIndex = CALCULATE( MAX('Table1'[Index]),
FILTER('Table1', 'Table1'[Group] <> EARLIER(Table1[Group])),
FILTER('Table1', [Index] <= EARLIER([Index]))
)

return
[Index] - LastLossIndex

 

NewGroup = CALCULATE(MAX(Table1[Index]),FILTER('Table1','Table1'[Index]<=EARLIER(Table1[Index]) && Table1[Group]=EARLIER(Table1[Group])&& Table1[WinStreak]=1&& Table1[Case]=EARLIER(Table1[Case])))

 

NewDate = DATEVALUE('Table1'[Date])

 

Diff = var MaxDate=CALCULATE(MAX('Table1'[NewDate]),FILTER('Table1','Table1'[Case]=EARLIER(Table1[Case])&&Table1[NewGroup]=EARLIER(Table1[NewGroup])))
var MinDate=CALCULATE(MIN('Table1'[NewDate]),FILTER('Table1','Table1'[Case]=EARLIER(Table1[Case])&&Table1[NewGroup]=EARLIER(Table1[NewGroup])))
return
IF(MinDate=MaxDate,0,DATEDIFF(LOOKUPVALUE('Calendar'[Date],'Calendar'[Date],MinDate),LOOKUPVALUE('Calendar'[Date],'Calendar'[Date],MaxDate),DAY)-CALCULATE(COUNTROWS('Calendar'),FILTER('Calendar',('Calendar'[Weekday]=6 || 'Calendar'[Weekday]=7)&&'Calendar'[Date]>=MinDate&&'Calendar'[Date]<=MaxDate))+1)

 

q2.PNG

 

You can download attached pbix file to have a look. 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
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

4 REPLIES 4
v-qiuyu-msft
Community Support
Community Support

Hi @Sebas7,

 

Regarding your sample data, how did you calculate start date and end date then get the TAT column values? Did it calculate like below? 

 

q9.PNG

 

Best Regards,
Qiuyun Yu 

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

Hi Qiuyun,

 

Yes, that is how i calculated the TAT column.

 

Regards,

Sebas

Hi @Sebas7,

 

You can create a calendar table (Calendar = CALENDAR("2017-9-1",TODAY())) and add a index column in Query Editor,then create calculated columns below in the fact table: 

 

WinStreak =
var LastLossIndex = CALCULATE( MAX('Table1'[Index]),
FILTER('Table1', 'Table1'[Group] <> EARLIER(Table1[Group])),
FILTER('Table1', [Index] <= EARLIER([Index]))
)

return
[Index] - LastLossIndex

 

NewGroup = CALCULATE(MAX(Table1[Index]),FILTER('Table1','Table1'[Index]<=EARLIER(Table1[Index]) && Table1[Group]=EARLIER(Table1[Group])&& Table1[WinStreak]=1&& Table1[Case]=EARLIER(Table1[Case])))

 

NewDate = DATEVALUE('Table1'[Date])

 

Diff = var MaxDate=CALCULATE(MAX('Table1'[NewDate]),FILTER('Table1','Table1'[Case]=EARLIER(Table1[Case])&&Table1[NewGroup]=EARLIER(Table1[NewGroup])))
var MinDate=CALCULATE(MIN('Table1'[NewDate]),FILTER('Table1','Table1'[Case]=EARLIER(Table1[Case])&&Table1[NewGroup]=EARLIER(Table1[NewGroup])))
return
IF(MinDate=MaxDate,0,DATEDIFF(LOOKUPVALUE('Calendar'[Date],'Calendar'[Date],MinDate),LOOKUPVALUE('Calendar'[Date],'Calendar'[Date],MaxDate),DAY)-CALCULATE(COUNTROWS('Calendar'),FILTER('Calendar',('Calendar'[Weekday]=6 || 'Calendar'[Weekday]=7)&&'Calendar'[Date]>=MinDate&&'Calendar'[Date]<=MaxDate))+1)

 

q2.PNG

 

You can download attached pbix file to have a look. 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Sebas7
Regular Visitor

Hi,

 

I am struggling for some days to calculate the TAT for each case based on the actions done by each group and excluding weekends.

 

For example we have a case which was actioned by Group A, B, C & D and I want to find how long it took to be actioned by that group from start date to end date excluding weekends. It might be that the case was actioned by the same group twice. Each time the TAT is restarted when is actioned by another.

 

How can I calculate the TAT in Power BI. I tried using RANKX and DATESBETWEEN but without success.

 

Below is an example on how my data look like and how the TAT column should be at the end.

 

Case

Date

Group

TAT

Case-1879

02/09/2017 01:13

A

0

Case-1879

02/09/2017 02:39

A

Case-1879

02/09/2017 02:39

A

Case-1879

02/09/2017 02:39

B

0

Case-1879

02/09/2017 02:39

B

Case-1879

02/09/2017 02:39

C

1 Day

Case-1879

02/09/2017 02:39

C

Case-1879

02/09/2017 02:39

C

Case-1879

04/09/2017 10:14

C

Case-1879

05/09/2017 06:55

B

1 Day

Case-1879

05/09/2017 06:55

B

Case-1879

05/09/2017 09:55

B

Case-1879

05/09/2017 09:55

B

Case-1879

05/09/2017 15:13

B

Case-1879

09/09/2017 15:13

C

4 Day

Case-1879

09/09/2017 15:13

C

Case-1879

09/09/2017 15:13

D

1 Day

Case-1879

11/09/2017 18:31

D

Case-1879

11/09/2017 18:31

D


Thank you and regards,

Sebastian.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.