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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
henkka
Helper II
Helper II

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

Hi here is a table with expected end result Workleaves table 

Access is denied.

Hi here it is another try Table 

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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.