cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kmatveyko
Frequent Visitor

Table.Distinct with the condition in PowerQuery

Hi,

 

I have a problem with PowerQuery. So, I need to apply Distinct function in my table.

 

But with one condition: repeatable values should be deleted if their value is greater than 0.

 

Please help me to write a fuction on PowerQuery M. Maybe it's possible to use IF-expression?

 

Example, if 'ID'>0 then Table.Distinct(#"", {"ID"}) else 0.

 

Thanks!

 

1 ACCEPTED SOLUTION

this should work

Table.FromRows(List.Distinct(Table.ToRows(Source),each if _{0}=0 then Text.NewGuid() else _{0}))

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@kmatveyko , I think you need first filter the values and then take distinct

Not quite. For example, here is a column:

0
0
20155

20156

20157
20157
20157
0
20158
20159

 

Needs to delete duplicated values 20157 (two times). Nulls should stay in a column as they are.

 

Here is a required result:

0
0
20155
20156
20157
0
20158
20159

 

this should work

Table.FromRows(List.Distinct(Table.ToRows(Source),each if _{0}=0 then Text.NewGuid() else _{0}))

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

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!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors