Reply
henkka
Helper II
Helper II
Partially syndicated - Outbound

Duration of the chained workleaves

Hi,

 

I have a table where there is id. next chained id Start date, End date.

 

What I'm trying to achieve is to calculate the total duration of the work leaves but I'm not able to come up with the solution how the "edge case" is recognized that it is the last workleave that is part of the whole chain and the bolded "False" should also be True 

henkka_0-1683551837122.png

 

This is my best effor (calculated column

IsLastWorkleave =
VAR current_id = FactWorkleaves[Workleave.id]
VAR next_id = FactWorkleaves[Nextchainedworkleave.id]
VAR last_id =
    IF(
        next_id = BLANK(),
        current_id,
        CALCULATE(
            MAX(FactWorkleaves[Workleave.id]),
            FILTER(
                ALL(FactWorkleaves),
                FactWorkleaves[Workleave.id] <> current_id &&
                FactWorkleaves[Workleave.id] > current_id &&
                FactWorkleaves[Workleave.id] <= next_id &&
                FactWorkleaves[Nextchainedworkleave.id] <> BLANK() &&
                FactWorkleaves[Nextchainedworkleave.id] <> current_id
            )
        )
    )
RETURN
    current_id = last_id
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Read about the PATH functions.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

View solution in original post

5 REPLIES 5
lbendlin
Super User
Super User

Read about the PATH functions.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Syndicated - Outbound

Hi here is a table with expected end result Workleaves table 

Syndicated - Outbound

Access is denied.

Syndicated - Outbound

Hi here it is another try Table 

Syndicated - Outbound

I got a bit forward with this and got the dax to calculate the total duration of the chained work leaves

ChainedWorkLeavesDuration =
VAR CurrentWorkLeaveId = FactWorkleaves[Workleave.id]
VAR ChainedWorkLeaves =
FILTER 
FactWorkleaves , PATHCONTAINS FactWorkleaves[path] , CurrentWorkLeaveId )
           )
RETURN  
SUMX ChainedWorkLeaves , FactWorkleaves[Duration] )
 
But still have a problem how to calculate the work leave total duration correctly only once by workleave
 
Now the table calculates like this
 
Workleave.idPreviouschainedworkleave.idpathDurationTotal duration
111 11111
222111111 | 22212
333222111|222|33313
444 44411
555 55511

 

but the correct end result would be

Workleave.idPreviouschainedworkleave.idpathDurationTotal duration
111 11113
222111111 | 22210
333222111|222|33310
444 44411
555 55511
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)