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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
HB13
Helper I
Helper I

Merging queries with a many to many relationship

Hello PBI People!


I am struggling with a merge task and I'm hoping for some clarity and assistance on the issue.

I have two tables, Policies and Risks
Policies records the policyId every single day that a policy remains active
Risks contains info about different risk vehicles linked to a policy (one policy can have many vehicles)

I have included a screenshot of an example of the two tables as well as the merged table I am trying to create. I basically want to map each riskvehicleid to every instance of the policyid in the policies table.
I am not too sure how to go about it Power BI, my last attempt only pulled one row into the merged table. 

HB13_0-1659601975826.png

 

 


Please advise!
Thank you in advance






1 ACCEPTED SOLUTION
Bubble4502
Resolver III
Resolver III

Hi @HB13 ,

 

You can achieve this goal in power query:

First, choos merge queries as new:

Bubble4502_0-1660124445172.png

Then select table and choose inner join:

Bubble4502_1-1660124508547.png

 

Expand risk and remove useless column:

Bubble4502_2-1660124568929.png

Final output:

Bubble4502_3-1660124602254.png

Here is the M code:

let
    Source = Table.NestedJoin(Policies, {"policyid"}, Risk, {"policyid"}, "Risk", JoinKind.Inner),
    #"Expanded Risk" = Table.ExpandTableColumn(Source, "Risk", {"policyid", "riskvehicleid", "vehiclemanufactureyear"}, {"Risk.policyid", "Risk.riskvehicleid", "Risk.vehiclemanufactureyear"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Risk",{"Risk.policyid"})
in
    #"Removed Columns"

 

Kind Regards,

Bubble

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

View solution in original post

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @HB13 ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

 

Bubble4502
Resolver III
Resolver III

Hi @HB13 ,

 

You can achieve this goal in power query:

First, choos merge queries as new:

Bubble4502_0-1660124445172.png

Then select table and choose inner join:

Bubble4502_1-1660124508547.png

 

Expand risk and remove useless column:

Bubble4502_2-1660124568929.png

Final output:

Bubble4502_3-1660124602254.png

Here is the M code:

let
    Source = Table.NestedJoin(Policies, {"policyid"}, Risk, {"policyid"}, "Risk", JoinKind.Inner),
    #"Expanded Risk" = Table.ExpandTableColumn(Source, "Risk", {"policyid", "riskvehicleid", "vehiclemanufactureyear"}, {"Risk.policyid", "Risk.riskvehicleid", "Risk.vehiclemanufactureyear"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Risk",{"Risk.policyid"})
in
    #"Removed Columns"

 

Kind Regards,

Bubble

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

amitchandak
Super User
Super User

@HB13 , Based on what I got. Create a combine column or policy and date in both tables and use that in merge

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Are you saying combine date and policyid in a column? There isn't a date column in the Risks table to do so

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.