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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.