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
Anonymous
Not applicable

How to join two tables in direct query

Hello,

I have two tables: The first tables shows my orders and products which were ordered with a quantity and the second table shows all my available products without quantity field. 

So I want to calculate based on a specific date which products were ordered and which not. 

Problem: How can I merge a table with quantity and the table without quantity. All products without quantity should get the value zero.

I can do that with an join using import modus but how to do the merge in direct query? Just need some ideas 🙂

 

Thank you in advance. Best regards.

 

filterorders.png

 

1 ACCEPTED SOLUTION

Try this:

VAR __Table =
NATURALINNERJOIN(
'Products',
SELECTCOLUMNS(
'Orders',
"SKU",[SKU],
"Quantity",[Quantity]
)
)

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

I am assuming product here is product dimension, Same way you have date dimension,

When you create sum of qty measure add +0

 

Qty Total = Sum(Table[Qty]) +0

 

Also, explore this option

ShowItemwithoutdata.JPG

Greg_Deckler
Super User
Super User

You can't merge in Direct Query, you would need to edit the source system.

 

You could theoretically merge them in DAX using things like NATURALINNERJOIN, etc. but that will be part of a measure calculation.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

newtable.png

 

@Greg_Deckler  Thank you for your fast reply. So I tried to do a join but I get the error message "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."  On the picture I tried to describe what I want to create but is this even possible since the tables have different columns?

Hi,

Try this

  1. Create a relationship from the SKU field of Table1 to the SKU field of the Products Table
  2. To your visual, drag SKU and Product from the Products Table
  3. Write this measure: Total Quantity = SUM(Table1[Quantity])+0

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Try this:

VAR __Table =
NATURALINNERJOIN(
'Products',
SELECTCOLUMNS(
'Orders',
"SKU",[SKU],
"Quantity",[Quantity]
)
)

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Can't you just submit your sql with this join ?

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



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.