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
gkakun
Helper III
Helper III

Merge queries

Hi,

I have 2 tables. one with order ID and timestamp. the other table is the shift rotation, start date, end date and shift number. I want to add shift number to the relevant order ID in the first table.

any idea how can I do that? 

 

Capture.JPGCapture2.JPG 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hello @gkakun ,

You have published this as "Combine Queries". Definitely want to do this in Power Query? It is feasible by a three-way search, but it is quite advanced M code and is not very effective in very large datasets.

This can be better adapted to doing so as a DAX measure, something like:

_transShift =
VAR
tTimestamp = MAX(transTable[Trans Timestamp])
RETURN
CALCULATE(
  MAX(shiftTable([SHIFT]),
  FILTER(
    shiftTable,
    shiftTable[Start Time] <= tTimestamp
    && shiftTable[End Time] >= tTimestamp
  )
)



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

10 REPLIES 10
BA_Pete
Super User
Super User

Hello @gkakun ,

You have published this as "Combine Queries". Definitely want to do this in Power Query? It is feasible by a three-way search, but it is quite advanced M code and is not very effective in very large datasets.

This can be better adapted to doing so as a DAX measure, something like:

_transShift =
VAR
tTimestamp = MAX(transTable[Trans Timestamp])
RETURN
CALCULATE(
  MAX(shiftTable([SHIFT]),
  FILTER(
    shiftTable,
    shiftTable[Start Time] <= tTimestamp
    && shiftTable[End Time] >= tTimestamp
  )
)



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks. Not necesarly in power query. The dataset is not too large, so it shouldnt affect the performance. I will try the formula above. Thanks

amitchandak
Super User
Super User

@gkakun , Table showing shift has been considered as table 2. Create a new column in table 1

 

maxx(filter(Table2, table2[start time] <= Table1[Trans Timestamp] && table2[end time] >= Table1[Trans Timestamp] ), [Shift])

Thanks! Can I do that also if the tables dont have relashionshipd between them? I dont have a way to create one 

@gkakun 

 

I don't think you need a relationship for this.

Hope it works out ok for you.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi, thanks again. I have tried the measure above, but unfortunately it's not working. Im not getting an error, i just cant add it to the table- it's keep loading and nothing happened. 

@gkakun ,

 

If your tables are very large, this may not be very performant and may take a long time to load.

 

You can try adding it as a calculated column instead using @amitchandak 's answer above (which didn't appear on my screen originally). Otherwise, we could try the Power Query lookup and see how that works out for you.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Looks like your DAX measure is partially working, i have many blank rows, still to understand why some dates not captured 

Hi @gkakun 

If you want to build a calculated column like 

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

I have tried @amitchandak  solution, but it must have relationship between the tables to work. 

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.