cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills 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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors