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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Adham
Helper III
Helper III

Filter created table based on multiple conditions

Hello All,

 

I hope you are all well. I have got the following two tables:

 

Tasks (Table 1):

 

Employee ID | Project ID | Task Start Date | Task Due Date

 

different employees can work on different projects and different projects will have multiple people working on them.

 

Employee Weeks (Table 2):

 

Date | Employee ID | Project ID | Work Hours

 

Table 2 is created using Table 1. The code i used is:

 

 

 

Employee Weeks = 
    SELECTCOLUMNS(
        ADDCOLUMNS(
            GENERATE(
                FILTER(
                    ADDCOLUMNS(
                        GENERATE(
                            DISTINCT(Tasks[Task Assignee Id]),
                            CALENDAR(MIN(Tasks[Task Start Date]),MAX(Tasks[Task Due Date]))
                        ),
                        "__IsWeekDay",IF(WEEKDAY([Date],3) < 5,TRUE(),FALSE())
                    ),
                    [__IsWeekDay] = TRUE()
                ),
                DISTINCT(Tasks[Project Id])
            ),
            "__Work Hours",8
        ),
        "Employee Id",[Task Assignee Id],
        "Project Id", [Project Id],
        "Date",[Date],
        "Work Hours",[__Work Hours]
    )

 

 

 

I want to filter table 2 to only have values where:

 

if a row in table 1 has equal values of employee id and project id to a row in table 2 and also for the date of the row of table 2 to be between the start and due date of the row of table 1.

 

I would really appreciate if someone can help me on this!

1 ACCEPTED SOLUTION

Hello @Greg_Deckler  and @v-frfei-msft ,

 

Thank you very much for your help. I actually solved it by running a python script since i am more proficient in python than DAX. Its really cool how power BI enables the use of python!!

View solution in original post

8 REPLIES 8
v-frfei-msft
Community Support
Community Support

Hi @Adham ,

 

Please try to get the filtered table by the following formula. If it doesn't meet your requirement,  kindly share your sample data and excepted result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.

 

Employee Weeks =
VAR k =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATE (
                FILTER (
                    ADDCOLUMNS (
                        GENERATE (
                            DISTINCT ( Tasks[Task Assignee Id] ),
                            CALENDAR ( MIN ( Tasks[Task Start Date] ), MAX ( Tasks[Task Due Date] ) )
                        ),
                        "__IsWeekDay", IF ( WEEKDAY ( [Date], 3 ) < 5, TRUE (), FALSE () )
                    ),
                    [__IsWeekDay] = TRUE ()
                ),
                DISTINCT ( Tasks[Project Id] )
            ),
            "__Work Hours", 8
        ),
        "Employee Id", [Task Assignee Id],
        "Project Id", [Project Id],
        "Date", [Date],
        "Work Hours", [__Work Hours]
    )
VAR std =
    CALCULATE (
        MAX ( Tasks[Task Start Date] ),
        FILTER ( Tasks, [Employee ID] = [Employee Id] && [Project ID] = [Project Id] )
    )
VAR endd =
    CALCULATE (
        MAX ( Tasks[Task Due Date] ),
        FILTER ( Tasks, [Employee ID] = [Employee Id] && [Project ID] = [Project Id] )
    )
RETURN
    FILTER ( k, [Date] >= std && [Date] <= endd )

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

@Adham do you still need help with this, @v-frfei-msft 's solution looked pretty solid. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler  and @v-frfei-msft ,

 

Thank you very much for your help. I actually solved it by running a python script since i am more proficient in python than DAX. Its really cool how power BI enables the use of python!!

amitchandak
Super User
Super User

Refer to my HR blog https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

There us current employee calculation. Take the filter part of it and move it inside the calculate table.

On top of that put a summarize and get the data

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak ,

 

I am sorry i dont quite get you. Could you please provide an example?

 

Kind regards,

 

Adham

Try something like this. Not tested

summarize(
 CALCULATETABLE(Employee,filter(Employee,Employee[Start Date]<=max('Date'[Date]) && (ISBLANK(Employee[End Date]) || Employee[End Date]>max('Date'[Date]))),CROSSFILTER(Employee[Start Date],'Date'[Date],None)),Employee[ID],Employee[Project Id],'Date'[Date],"__Work Hours",8)

 

You might have to remove crosstable and date table join.

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I am actually more confused now

JirkaZ
Solution Specialist
Solution Specialist

@Adham You'll have to create a measure to calculate whatever you need to calculate from table 2. This cannot be done using relationships and modelling. 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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