问题
I am extremely new to Power BI so please bear with me. So assume I have 3 XML sheets (my initial data sources for Power BI) and 2 of them are as simple tables as follows:
The tables b
and c
represents two of my XML files as stated above. File
a
is as follows:
Software
+
|
| Microsoft
| +
| +--->Windows 10
+-->+
| +--->Windows 7
|
| Google
| +
| +-->Chrome
+-->+
+-->Mail
Or in XML as follows:
<?xml version="1.0"?>
<Software Name = "Company Software">
<HeadProduct Name = "Google">
<Product>Chrome</Product>
<Product>Mail</Product>
</HeadProduct>
<HeadProduct Name = "Microsoft">
<Product>Windows 10</Product>
<Product>Windows 7</Product>
</HeadProduct>
</Software>
Now here is my problem: In my datasets, I have just one Table a
with the nested information and several Tables b, c, d etc.
with mappings back to elements in Table a
Like
Microsoft ----> Table b
Chrome ----> Table c
Windows 10 ----> Table d
...
How do I handle and realize the relationships this in BI? I am okay to change structure of File a
if that helps.
Thanks.
回答1:
I think this is more of a 'two stage' join rather than one-to-many.
The files that you've referred to as "b", "c", etc... all seem to have the same schema. My approach would be to union these datasets (append), adding a column to each that will tag the record as needing to be joined to any particular 'Head Product'
Once the 'room' files have been append into a single 'room' table, then do a merge between your software table and your room table.
It does seem to me that this represents a many to many join, which is concerning unless a Cartesian join is what you are really after.
Ok, you requested some examples. So, I typed your tables above into PowerBI.
The first step is to take table B and add a column that will help it relate to Head Product in Table A. So I edit the query, go to the add column ribbon, add a custom column like so:
Do this for all your 'Room' files. It would be ideal if you didn't have to add this field manually. It may be that you can leverage filenames from the folder connector, or if you own the process that generates these files you might be able to add it to the column set. That's all up to you.
Look at the Queries region and right click under the last query. Mouse over menu items to traverse "New Query" > "Combine" > "Append Queries as New" -- you get this result:
Now go back to table A. Do 'Merge Queries' from the Home ribbon.
Expand the merged column.
And the result:
来源:https://stackoverflow.com/questions/55472870/one-to-many-table-relationship