cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
aso_be
Helper I
Helper I

Duplicated rows in matrix table probably because of relationship and granularity

Hello,

 

I've got quite a small and simple model but when I mix fields from table A and table B in a (matrix table), as soon as I add a field from table B, there is duplicated rows with every possibility of unique value of the field from table B. I think it's because of the granularity of both tables which are different (table A = product | table B = distributor (which provided several products from table A)


Model

aso_be_0-1675873051774.png

 

Without fields from B (OK)

 

aso_be_1-1675873102888.png


With fields from table B (NOK)

 

aso_be_2-1675873160467.png

 

Could you please help to fix it? You would be my savior as I often meet this issue, and as the only solution to merge B into A to avoid it (without really understanding the issue, and by, therefore, increasing data size by doing so)

 

Thanks !

 

6 REPLIES 6
JirkaZ
Solution Specialist
Solution Specialist

It may indicate that the relationship is not working properly. 
In table A - does each item have only 1 distributor assigned?

Indeed, they have only one assigned, which is one of the distributor from table B. Any idea about that?

I think that's quite close to this thread (but not sure how to solve it) : https://community.powerbi.com/t5/Desktop/Duplicate-rows-when-bringing-data-from-multiple-tables/m-p/...

JirkaZ
Solution Specialist
Solution Specialist

Please see the examples below. This (below) is the correct behavior and I have the same relationship setup as you do. What you are seeing really seems like a relationship that is not working. Make sure that in Power Query you Trim and Clean the key columns in both tables. 

 

JirkaZ_0-1675951140197.pngJirkaZ_1-1675951162925.png

 

I actually noticed that I was getting this result when I added a ranking (measure) based on a column from the fact table which is quite simple 

 

daily_lost_sales_total_days_ranking =
    RANKX(
        ALLSELECTED('reports product_stock_class_daily'),
        CALCULATE(
            [lost_sales_since_no_stock]
        )


Therefore I found this thread https://stackoverflow.com/questions/57801524/rankx-function-gives-duplicates-across-all-values-it-is... which is actually very similar.

 

And by modifying my ranking in such a way there are no longer duplicated rows

 

daily_lost_sales_total_days_ranking =

 VAR ranking =
IF(
    HASONEVALUE('reports product_stock_class_daily'[nb_days_since_last_sales]),
    RANKX(
        ALLSELECTED('reports product_stock_class_daily'),
        CALCULATE(
            [lost_sales_since_no_stock]
        )
    )
)
 RETURN

 ranking
 
To be honest, I don't really understand why it was happening, and how it is solved with this modification.

If someone could provide with some further explanation I would be really grateful. 

Thanks in advance 🙂
JirkaZ
Solution Specialist
Solution Specialist

Well the HASONEVALUE is just a check of whether one or multiple items are in current context. 
What I see as an issue is actually using the CALCULATE in the ranking expression because CALCULATE changes context. And since you're then just using a measure, you should be good without using CALCULATE and thus changing context.


Hi @JirkaZ 

Unfortunately I tried to remove the CALCULATE in the ranking measure but the duplicated rows still appeared when I added the field from table B 😞 

aso_be_0-1676043083957.png


Were you able to reproduce this behaviour with your test report?

Thanks again for your time 🙂

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors