Reply
armandprr92
Frequent Visitor

DAX Calculation find max value until certain date per employee (many-to-many)

Hello guys, 

i have a problem that is driving me nuts and I am coming to you for help.

 

I have two tables:

  • The first one details the working schedules per employee. It shows the schedule and the date it was submitted.

armandprr92_2-1738603182572.png

 

  • The second one is an order table and it contains working orders, a date and the employee.

armandprr92_3-1738603205401.png

 

I would like to get two new columns in the second table specifying the employee schedule. I specify columns as I need to do further calculations and I need to visualize the date without the employee field displayed. Even though any idea is welcome.

Notice that both tables can have multiple times the same employee and the dates are not comparable!

 

Example: 

armandprr92_4-1738603477661.png

 

 

Any recommendations? Thank you so much

 

2 ACCEPTED SOLUTIONS
Syk
Super User
Super User

We can do this in Power Query.
Starting with your 2 tables, go to your Order table and hit merge queries

Syk_0-1738613213915.png

Select your employee shift table to merge. Then select your keys (which will be Employee and date). Click Employee then hold ctrl and click date. It should put numbers next to your columns to show what order they're matching like this.

Syk_2-1738613336674.png

 

Hit okay and expand the shift table

Syk_3-1738613421736.png

Syk_4-1738613433274.png

 

View solution in original post

armandprr92
Frequent Visitor

as a dax column can also be solved this way:

testcol =
    MAXX(
        FILTER(
            Employee_Schedule,
            Employee_Schedule[Employee] = Orders[Employee] &&
            Orders[Date] >= Employee_Schedule[Date]
        ),
        Employee_Schedule[Schedule Start]
    )

View solution in original post

3 REPLIES 3
armandprr92
Frequent Visitor

as a dax column can also be solved this way:

testcol =
    MAXX(
        FILTER(
            Employee_Schedule,
            Employee_Schedule[Employee] = Orders[Employee] &&
            Orders[Date] >= Employee_Schedule[Date]
        ),
        Employee_Schedule[Schedule Start]
    )
Syk
Super User
Super User

We can do this in Power Query.
Starting with your 2 tables, go to your Order table and hit merge queries

Syk_0-1738613213915.png

Select your employee shift table to merge. Then select your keys (which will be Employee and date). Click Employee then hold ctrl and click date. It should put numbers next to your columns to show what order they're matching like this.

Syk_2-1738613336674.png

 

Hit okay and expand the shift table

Syk_3-1738613421736.png

Syk_4-1738613433274.png

 

armandprr92
Frequent Visitor

So far I've been able to find this thread but unsuccessfully implemented it as it doesn't filter by two conditions. Plus I would like to have it in columns rather than measures.

 

https://community.fabric.microsoft.com/t5/Desktop/Mapping-between-2-table-with-Many-to-many-relation...

avatar user

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)