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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors