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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
fedeleu
Frequent Visitor

Problems with Table.Distinct

Hi!

I have the following code

let

    Origen = Table.Combine({Unico2020, Unico2021}),

    #"Filas filtradas" = Table.SelectRows(Origen, each ([Titolare] = "Empresa")),

    #"Tipo cambiado" = Table.TransformColumnTypes(#"Filas filtradas",{{"Inizio Coll", type date}}),

    #"Columna condicional agregada" = Table.AddColumn(#"Tipo cambiado", "orden_estado", each if [Stato] = "CONSUNTIVATO" then 1 else if [Stato] = "VERIFICA DOCUMENTALE" then 2 else 3),

    #"Filas ordenadas" = Table.Sort(#"Columna condicional agregada",{{"Inizio Coll", Order.Ascending}, {"orden_estado", Order.Ascending}, {"Avviso", Order.Ascending}}),

    #"Duplicados quitados" = Table.Distinct(#"Filas ordenadas", {"Fornitore"})

in

    #"Duplicados quitados"

 

I expected to keep the first unique value of the column "Fornitore", since I previously ordered by "Inizio Coll", "orden_estado" and "Avviso", which are the fields that give me a priority in the data to keep.

However I have come across records that do not meet that criteria.

 

Can someone tell me that I am doing wrong that I do not have the first record that meets my order criteria?

 

Thanks,

Federico

1 ACCEPTED SOLUTION
KNP
Super User
Super User

Hi @fedeleu,

 

Can you try adding Table.Buffer(PreviousStep), immediately before the Table.Distinct step?

Let me know if this improves the results for you.

 

Regards,

Kim 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

View solution in original post

3 REPLIES 3
KNP
Super User
Super User

Hi @fedeleu,

 

Can you try adding Table.Buffer(PreviousStep), immediately before the Table.Distinct step?

Let me know if this improves the results for you.

 

Regards,

Kim 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!
fedeleu
Frequent Visitor

That worked!

Thank you very much!!!

 

Can you explain me what Table.Buffer does?

It stores the table in memory preventing that step from being evaluated again. Typically used for performance improvements.

 

I think the reason this is needed in the sorting/distinct scenario is best explained in this post...

https://exceleratorbi.com.au/remove-duplicates-keep-last-record-power-query/

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors