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
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.

 

 

 


@ 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

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.

 

 

 


@ 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...
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
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.