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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Lucian
Responsive Resident
Responsive Resident

What are active tasks in a period

Hello,

 

I have a simple problem but I cannot get to the desired result.

The simplified model consists in a Date table and a Task table:

 

TaskStartEnd
A01.03.202315.03.2023
B20.03.202302.04.2023
C25.03.202325.06.2023
D01.04.202315.04.2023
E12.04.202319.04.2023

 

I need a report having a Gannt visual to display the tasks that fall into a specific period:

 

Report.jpg

 

Basically I need to see the tasks that will "intersect" the selected period created by the Year/Month/Week slicers. Because will be tasks that will start or end in the selected period the Date table could not be related (I guess) to the Tasks table.

 

I have tried the approach in the other thread: Filter activities in a period but the formula does not return proper values.

 

 

filtermeasure = 
var _start=MINX(ALLSELECTED('Date'),[Date])
var _end= MAXX(ALLSELECTED('Date'),[Date])
return IF(MIN(Tasks[Start])>=_start && MIN(Tasks[End]) <=_end,1,0)

 

 

For example selecting the month APR and week W14 resulting the period of 01.04.2023 - 02.04.2023 it should display tasks B, C  and D.

For APR / W17 period is 17.04.2023 - 23.04.2023 the displayed tasks should be C, D and E.

And when selecting only the month without any week the period would be 01.04.2023 - 30.04.2023 wich should display the B, C, D and E tasks.

 

For convenience, I have attached the PBIX file: Filter-Gantt.pbix

 

Kind Regards,

Lucian

1 ACCEPTED SOLUTION
Lucian
Responsive Resident
Responsive Resident

Hi @amitchandak ,

 

Thank you for your suggestion. I have tried to replicate your measure for "Current Employees" as follows:

 

Current v1 = 
CALCULATE (
    COUNTX (
        FILTER (
            Tasks,
            Tasks[Start] <= MAX ( 'Date'[Date] )
                && (
                    ISBLANK ( Tasks[End] )
                        || Tasks[End] > MAX ( 'Date'[Date] )
                )
        ),
        ( Tasks[Task] )
    )
)

 

Still the formula does not return expected values/tasks. However, reviewing my post, and using your base idea, I have tried to play more with the "intersect", so I came up with this formula that it seems to cover all the cases:

 

Current v3 = 
//Set Watch Period
VAR PeriodMin=MIN('Date'[Date])
VAR PeriodMax=MAX('Date'[Date])
VAR tblPeriod=GENERATESERIES(PeriodMin,PeriodMax)

//Set Task Window
VAR TaskMin=COALESCE(MIN(Tasks[Start]),PeriodMin)
VAR TaskMax=COALESCE(MAX(Tasks[End]),PeriodMax)
VAR tblTask=GENERATESERIES(TaskMin,TaskMax)

//Get Intersection
VAR tblIntersect=INTERSECT(tblPeriod,tblTask)
VAR noIntersect=COUNTROWS(tblIntersect)

//Is Task in Period
VAR IsInPeriod=IF(noIntersect>0,1)

RETURN
    IsInPeriod

 

So thank you for your time.

 

Kind Regards,

Lucian

View solution in original post

2 REPLIES 2
Lucian
Responsive Resident
Responsive Resident

Hi @amitchandak ,

 

Thank you for your suggestion. I have tried to replicate your measure for "Current Employees" as follows:

 

Current v1 = 
CALCULATE (
    COUNTX (
        FILTER (
            Tasks,
            Tasks[Start] <= MAX ( 'Date'[Date] )
                && (
                    ISBLANK ( Tasks[End] )
                        || Tasks[End] > MAX ( 'Date'[Date] )
                )
        ),
        ( Tasks[Task] )
    )
)

 

Still the formula does not return expected values/tasks. However, reviewing my post, and using your base idea, I have tried to play more with the "intersect", so I came up with this formula that it seems to cover all the cases:

 

Current v3 = 
//Set Watch Period
VAR PeriodMin=MIN('Date'[Date])
VAR PeriodMax=MAX('Date'[Date])
VAR tblPeriod=GENERATESERIES(PeriodMin,PeriodMax)

//Set Task Window
VAR TaskMin=COALESCE(MIN(Tasks[Start]),PeriodMin)
VAR TaskMax=COALESCE(MAX(Tasks[End]),PeriodMax)
VAR tblTask=GENERATESERIES(TaskMin,TaskMax)

//Get Intersection
VAR tblIntersect=INTERSECT(tblPeriod,tblTask)
VAR noIntersect=COUNTROWS(tblIntersect)

//Is Task in Period
VAR IsInPeriod=IF(noIntersect>0,1)

RETURN
    IsInPeriod

 

So thank you for your time.

 

Kind Regards,

Lucian

amitchandak
Super User
Super User

@Lucian , refer this approach or attached file can help

 

Power BI: HR Analytics - Employees as on Date: https://youtu.be/e6Y-l_JtCq4
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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