cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Conditional Join on "Line Name" and Data Range

Hello:

 I am trying to join two tables by "Line Name" with table one filtering the data in table two by date range such that table table two to only show data WHERE "timestamp" falls within the "SHIFT PERIOD START" AND "SHIFT PERIOD END" and WHERE "LINE NAME = "LINE NAME". Tried the community but I am not able to get it. Any help would be greatly appreciated. Thanks 

Table one: Shift Filter from Teams: Shifts

LINE NAMESHIFT IS ACTIVESHIFT START DATE AND TIMESHIFT END DATE AND TIMESHIFT PERIOD IS SCHEDULED ACVTIVESHIFT PERIOD STARTSHIFT PERIOD ENDSHIFT PERIOD ID CODESHIFT PERIOD NAME
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 8:15:00 AM4/20/2020 9:00:00 AMFwFIrst Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 9:15:00 AM4/20/2020 12:00:00 PMSwSecond Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 9:15:00 AM4/20/2020 12:00:00 PMSwSecond Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 9:15:00 AM4/20/2020 12:00:00 PMSwSecond Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 9:15:00 AM4/20/2020 12:00:00 PMSwSecond Work Period
CX482 MAIN LINE SANDBOXTRUE4/20/2020 8:00:00 AM4/20/2020 5:00:00 PMTRUE4/20/2020 9:15:00 AM4/20/2020 12:00:00 PMSwSecond Work Period

 

 

 

 

Table Two: Machine State data

error textcategory numcategory texttimestamptime no millisIndexshort nameLine Name
S040 MACHINE IS BLOCKED5MACHINE BLOCKED3/6/2020 12:313/6/2020 12:311CX482 S040CX482 MAIN LINE SANDBOX
+S040 RC2 ROBOT GRIPPER PART PRESENT LH MISSING1MACHINE ERRORS3/6/2020 12:313/6/2020 12:312CX482 S040CX482 MAIN LINE SANDBOX
+S040_ROBOT ARM RC1_R2 EXECUTION ERROR1MACHINE ERRORS3/6/2020 12:313/6/2020 12:313CX482 S040CX482 MAIN LINE SANDBOX
+S040 RC2 ROBOT GRIPPER PART PRESENT LH MISSING1MACHINE ERRORS3/6/2020 12:313/6/2020 12:314CX482 S040CX482 MAIN LINE SANDBOX
+S040_ROBOT ARM RC1_R2 EXECUTION ERROR1MACHINE ERRORS3/6/2020 12:313/6/2020 12:315CX482 S040CX482 MAIN LINE SANDBOX
+S040 RC2 ROBOT GRIPPER PART PRESENT LH MISSING1MACHINE ERRORS3/6/2020 12:313/6/2020 12:316CX482 S040CX482 MAIN LINE SANDBOX
+S040_ROBOT ARM RC1_R2 EXECUTION ERROR1MACHINE ERRORS3/6/2020 12:313/6/2020 12:317CX482 S040CX482 MAIN LINE SANDBOX
+S040 RC2 ROBOT GRIPPER PART PRESENT LH MISSING1MACHINE ERRORS3/6/2020 12:313/6/2020 12:318CX482 S040CX482 MAIN LINE SANDBOX
+S040_ROBOT ARM RC1_R2 EXECUTION ERROR1MACHINE ERRORS3/6/2020 12:313/6/2020 12:319CX482 S040CX482 MAIN LINE SANDBOX
+S040 RC2 ROBOT GRIPPER PART PRESENT LH MISSING1MACHINE ERRORS3/6/2020 12:313/6/2020 12:3110CX482 S040CX482 MAIN LINE SANDBOX
+S040_ROBOT ARM RC1_R2 EXECUTION ERROR1MACHINE ERRORS3/6/2020 12:313/6/2020 12:3111CX482 S040CX482 MAIN LINE SANDBOX
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Conditional Join on "Line Name" and Data Range

Hi @MOOREJEFF ,

 

We can merge tables based on Line name and filter the table based on the new custom column 

 

let
    Source = Table.NestedJoin(Shifts, {"LINE NAME"}, #"Machine State data", {"Line Name"}, "Machine State data", JoinKind.LeftOuter),
    #"Expanded Machine State data" = Table.ExpandTableColumn(Source, "Machine State data", {"timestamp"}, {"Machine State data.timestamp"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Machine State data", "Custom", each [Machine State data.timestamp]>=[SHIFT PERIOD START] and[Machine State data.timestamp]<=[SHIFT PERIOD END]),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] <> false))
in
    #"Filtered Rows"

 

 Pbix as attached.

 

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

View solution in original post

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: Conditional Join on "Line Name" and Data Range

Hi @MOOREJEFF ,

 

We can merge tables based on Line name and filter the table based on the new custom column 

 

let
    Source = Table.NestedJoin(Shifts, {"LINE NAME"}, #"Machine State data", {"Line Name"}, "Machine State data", JoinKind.LeftOuter),
    #"Expanded Machine State data" = Table.ExpandTableColumn(Source, "Machine State data", {"timestamp"}, {"Machine State data.timestamp"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Machine State data", "Custom", each [Machine State data.timestamp]>=[SHIFT PERIOD START] and[Machine State data.timestamp]<=[SHIFT PERIOD END]),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] <> false))
in
    #"Filtered Rows"

 

 Pbix as attached.

 

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

View solution in original post

Highlighted
Frequent Visitor

Re: Conditional Join on "Line Name" and Data Range

Frank:

 Super Thanks for the DAX. THe .pbix file really helped as well so thank you for your time to make that. Now that i can see the method I understand it. Your help has allowed us to use the Teams shift schedule to filter machine state data. This should improve my report data accuracy significantly. Thank you again for your help.

Helpful resources

Announcements
Meet the 2020 Season 2 Power BI Super Users!

Meet the 2020 Season 2 Power BI Super Users!

Find out who's part of the program this season, and welcome the new Super Users.

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Featured Data Story of The Month

Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

Power BI Dev Camp - Developing with .NET Core

Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Top Solution Authors
Top Kudoed Authors