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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
o59393
Post Prodigy
Post Prodigy

Duplicates on table due to relationship model

Hi all

 

I created a many to many relationship and in both directions. It's showing me duplicate vales for an item with different locations:

 

dup1.JPG

As seen on the left table, the first 3 rows have the same values eventhough the right table shows the real value per each.

 

Is there any way to correct the left table duplicate values by fixing the relationship model, without having to create a concatenation of the Site, item and location in the master table of the pbix attached?

 

 A concatanation of the 3 columns in each of the tables would add memory to my pbix, so wanted to know if there is an easier way to solve this.

 

Pbix: https://1drv.ms/u/s!ApgeWwGTKtFdhnU5C-gKj_H2iktt?e=HTsnWj

 

Thanks!

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

You really should fix your model.  Many:Many relationships with bi-directional filters is a bad way to start learning Power BI.  Making a Master Table is a good idea, and you should transform that to make it so it can be on the 1 side of relationships to the other two tables.  The concatentation is a good way to do that, and I expect the model simplicity would far outweigh the file size impact.

 

Ok.  Off my soapbox, here is an expression that gets your desired results.

 

New Measure =
CALCULATE (
    SUM ( Query1[Units] ),
    TREATAS ( VALUES ( 'Master Table'[Location] ), Query1[Location] ),
    TREATAS ( VALUES ( 'Master Table'[Site] ), Query1[Site] )
)

 

Note that this a work around for not having a proper relationship (back on my soapbox I guess).  The two TREATAS clauses pass the filters that a concatenated relationship would have done automatically (i.e., your measure would just be SUM(Query1[Units]).

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
AllisonKennedy
Super User
Super User

I would recommend creating a unique ID for this that can relate the data, even if that's not a pure concat of the three columns. Many to Many has special use cases, and is more suited for when you expect the same value for multiple items, as the article below tries to explain.
https://docs.microsoft.com/en-us/power-bi/transform-model/desktop-many-to-many-relationships

Can you explain what the Master Table purpose is and why you have it? Seems like you could just go directly from Query1 to Location to further reduce the size of your model?

You could get the answer you want using DAX, but it will be slow and not ideal for perforamnce, I would recommend getting the data model built properly instead.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy 

 

My bad, I forgot adding the month and year to the Query1 table. By doing so, we will have duplicates of Site&Location&Item

 

So the master table, basically contains the unique values for site, location & item, in order to have this:

 

llajdlasjdlajlsad.JPG

 

Where column 1 in each table is: Site & Location & Item.

 

If you thinks it's properly built let me know 🙂

 

https://1drv.ms/u/s!ApgeWwGTKtFdhnU5C-gKj_H2iktt?e=xrUJtj

 

Thanks!

 

mahoneypat
Microsoft Employee
Microsoft Employee

You really should fix your model.  Many:Many relationships with bi-directional filters is a bad way to start learning Power BI.  Making a Master Table is a good idea, and you should transform that to make it so it can be on the 1 side of relationships to the other two tables.  The concatentation is a good way to do that, and I expect the model simplicity would far outweigh the file size impact.

 

Ok.  Off my soapbox, here is an expression that gets your desired results.

 

New Measure =
CALCULATE (
    SUM ( Query1[Units] ),
    TREATAS ( VALUES ( 'Master Table'[Location] ), Query1[Location] ),
    TREATAS ( VALUES ( 'Master Table'[Site] ), Query1[Site] )
)

 

Note that this a work around for not having a proper relationship (back on my soapbox I guess).  The two TREATAS clauses pass the filters that a concatenated relationship would have done automatically (i.e., your measure would just be SUM(Query1[Units]).

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi @mahoneypat 

 

Agree, many to many could cause many problems.

 

I fixed my model and did it one to many:

 

llajdlasjdlajlsad.JPG

 

Being Column 1= a concatenation of Location & Site & item

 

I checked your measure and matched with the units fixing the model:

 

kjdslfsdlfjsdl.JPG

 

I take your point on simplicity outweighes the size of the file.

 

Here is my pbix with the model fixed and your measure.

 

https://1drv.ms/u/s!ApgeWwGTKtFdhnU5C-gKj_H2iktt?e=xrUJtj

 

Thanks

 

Glad you got it working and that you improved your model.  I always say when I teach Power BI - "Simple model, simple DAX".

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

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

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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