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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Sylvain74
Helper III
Helper III

Creating a relationship between two queries refering the same database view

Hi,

 

The title of my request could seem a bit strange so, please find here below more details about it.

Let's say I have a database view with several columns and amongst them there are these columns "item_type", "amount" and "quantity". The column "item_type" can have 5 different values.

First I have created a pivoted query in PBI and used "quantity" column to aggregate.

Secondly I have created another pivoted query and used "amount" column to aggregate.

Now in my report, I would like to add a table including data coming from both queries, but I do not see how to create a relationship between the two queries as I was not able to find a column with unique value in both.

Could you please help me ?

Thanks

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Merge query might get you there, however another technique is to simply create a third query and call it "Whatever". Point it to the same data source but remove all other columns other than whatever you wish to link on, like DestinationCountry it looks like from your data. Click on the remaining column and remove duplicates. Import.

 

Now you have a unique list of item types that you can wire to both of your other tables. In your table, select the single column from your third import and the fields you want from your first and second tables.

 

That should get you what you want.

 

 

 



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Merge query might get you there, however another technique is to simply create a third query and call it "Whatever". Point it to the same data source but remove all other columns other than whatever you wish to link on, like DestinationCountry it looks like from your data. Click on the remaining column and remove duplicates. Import.

 

Now you have a unique list of item types that you can wire to both of your other tables. In your table, select the single column from your third import and the fields you want from your first and second tables.

 

That should get you what you want.

 

 

 



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
HarrisMalik
Continued Contributor
Continued Contributor

Can you provide the snapshot of your views? if it is just aggregation based on item_type why don't you use a single table?

 

Regards

Harris

Hi Harris,

Please find below the printscreen. In this query I pivoted the field "item_type" into columns and aggregated on field "quantity"

The pivoted columns are "01.Contract", "02.Elements",...

PivotedAndAggregatedView.PNG

 

I did as well the same thing in a second view but I aggregated on "Amount" column and now I would like to "combine" these two queries in order to use columns from both in the report.

Hi

 

To me it doesn't look like a good design. Why you want to use item_type as measure? This way every time you have a new item_type you will get a new measure. Why don't you keep item_type as dimension and Quantity and Amount as two measures. This way you can simplify the design and have everything in one table rather than merging them. Secondly in future if you get new item_types they will be added as new dimension members and will not effect the overall model.

 

Regards

Harris

Anonymous
Not applicable

have you tried "Merge Queries" option?

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.