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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
henkka
Helper II
Helper II

How to calculate chained worklleaves duration only once

Hi,
I have a calculated column which calcutes the total duration for the chained workleaves. Now I have a problem for example there is three one day work leaves that are continuing the previous one but how can I calculate the total duration so that only the firs workleave gets a total duration and the followign are null or zero.
 
ChainedWorkLeavesDuration =
VAR CurrentWorkLeaveId = FactWorkleaves[Workleave.id]
VAR ChainedWorkLeaves =
FILTER 
FactWorkleaves PATHCONTAINS FactWorkleaves[path] CurrentWorkLeaveId )
           )
RETURN  
SUMX ChainedWorkLeaves FactWorkleaves[Duration] )
 
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
1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @henkka,

I'd propose to solve you problem with a calculation column like this:

barritown_0-1684148000446.png

And in the text format for convenience:

Total duration = 
VAR CurrentWorkLeaveID = [Workleave.id]
RETURN SUMX ( 
            FILTER ( 
                ADDCOLUMNS ( ALL ( FactWorkleaves ), 
                             "Flag", 
                             FIND ( CurrentWorkLeaveID, [path], 1, BLANK () ) = 1 ), 
                [Flag] = TRUE () ), 
            [Duration] ) + 0

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

View solution in original post

1 REPLY 1
barritown
Super User
Super User

Hi @henkka,

I'd propose to solve you problem with a calculation column like this:

barritown_0-1684148000446.png

And in the text format for convenience:

Total duration = 
VAR CurrentWorkLeaveID = [Workleave.id]
RETURN SUMX ( 
            FILTER ( 
                ADDCOLUMNS ( ALL ( FactWorkleaves ), 
                             "Flag", 
                             FIND ( CurrentWorkLeaveID, [path], 1, BLANK () ) = 1 ), 
                [Flag] = TRUE () ), 
            [Duration] ) + 0

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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