Reply
ludvigreck
Frequent Visitor
Partially syndicated - Outbound

Calculating actual time spent on appointment

Hello,

 

I need help to calculate the following problem

 

 

Skærmbillede 2024-08-16 083625.png

 

TIA,

 

Ludvig Reck

1 ACCEPTED SOLUTION
SamWiseOwl
Super User
Super User

Syndicated - Outbound

Hi @ludvigreck 

You can use variable to capture the data for the current row.

Return the smallest date in the table after filter to appointments after.

Then do an IF between the two:

Time Diff calc =
var star = --Capture current app time
SELECTEDVALUE('Table'[Appointment Time])
VAR DUR = --Capture current duration
SELECTEDVALUE('Table'[Duration])
var nextStar = --Calculate next start
CALCULATE(
    min('Table'[Appointment Time])
    ,ALLSELECTED('Table')
    ,'Table'[Appointment Time] > star)
var TimeDiff = DATEDIFF(star,nextStar,MINUTE)
var final =
IF(
    TimeDiff < DUR --if time diff shorter 
     ,TimeDiff --return diff
     ,DUR
)
Return final 
SamWiseOwl_0-1723793517723.png

 




If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

View solution in original post

3 REPLIES 3
ludvigreck
Frequent Visitor

Syndicated - Outbound

Fantastic, thank you!

SamWiseOwl
Super User
Super User

Syndicated - Outbound

Hi @ludvigreck 

You can use variable to capture the data for the current row.

Return the smallest date in the table after filter to appointments after.

Then do an IF between the two:

Time Diff calc =
var star = --Capture current app time
SELECTEDVALUE('Table'[Appointment Time])
VAR DUR = --Capture current duration
SELECTEDVALUE('Table'[Duration])
var nextStar = --Calculate next start
CALCULATE(
    min('Table'[Appointment Time])
    ,ALLSELECTED('Table')
    ,'Table'[Appointment Time] > star)
var TimeDiff = DATEDIFF(star,nextStar,MINUTE)
var final =
IF(
    TimeDiff < DUR --if time diff shorter 
     ,TimeDiff --return diff
     ,DUR
)
Return final 
SamWiseOwl_0-1723793517723.png

 




If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Syndicated - Outbound

Hello Sam,

 

Thanks for the input,

 

We have this table in a data warehouse in Fabric. Do you know how to use this dax code to handle the transformation at the data warehouse-level, before data enters Power BI?

 

All the best,

 

Ludvig

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)