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
mohsin-raza
Helper III
Helper III

removing row in power bi based on condition

Hi.

I need help solving this problem.

I have a dataset contain emplyee information . here is a sample 


 

 

snummerdateNamn adrsess Postnummer
934096null SmerabcGH784
9340962023-06-16 00:00SmerabcGH784


when i tried to remove duplicate rows  by  given Remove duplicate rows option in power query ,it delete row with job-end-date="2023-06-16 00:00" . while i want it will remove row having job-end-date=null. 

 

I also want  "null" to be remain in the dataset  as it will help for calulation for active employees.

 

regrads

 

@mohsin 

 

1 ACCEPTED SOLUTION
Omid_Motamedise
Super User
Super User

Hi,

You can use this code, or see the attached file

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjQ2MbA0U9JRAqLg3NQiIJWYlAwk3T3MLUyUYnWQlBgZGBnrGpjpGpopGBhYGRjg0BILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [snummer = _t, date = _t, Namn = _t, #" adrsess" = _t, #" Postnummer" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"snummer", Int64.Type}, {"date", type datetime}, {"Namn", type text}, {" adrsess", type text}, {" Postnummer", type text}}),
    #"Sorted Rows" = Table.Buffer(Table.Sort(#"Changed Type",{{"date", Order.Descending}})),
    #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"snummer", "Namn", " adrsess", " Postnummer"})
in
    #"Removed Duplicates"

 

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

5 REPLIES 5
dufoq3
Super User
Super User

Hi @mohsin-raza, alternatively you can group rows:

 

Output

dufoq3_0-1738847398003.png

 

let
    Source = [ a = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjQ2MbA0U9JRyivNyVEA0sG5qUVAKjEpGUi6e5hbmCjF6iCpMzIwMtY1MNM1NFMwMLAyMMChJRYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [snummer = _t, date = _t, Namn = _t, adrsess = _t, Postnummer = _t]),
    b = Table.TransformColumns(a, {}, each if _ = "null " then null else _)
  ][b],
    ChangedType = Table.TransformColumnTypes(Source,{{"date", type datetime}}),
    GroupedRows = Table.Group(ChangedType, {"snummer", "Namn", "adrsess", "Postnummer"}, {{"T", each Table.FirstN(Table.Sort(_, {{"date", 1}}), 1), type table}}),
    CombinedT = Table.Combine(GroupedRows[T])
in
    CombinedT

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Omid_Motamedise
Super User
Super User

Hi,

You can use this code, or see the attached file

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjQ2MbA0U9JRAqLg3NQiIJWYlAwk3T3MLUyUYnWQlBgZGBnrGpjpGpopGBhYGRjg0BILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [snummer = _t, date = _t, Namn = _t, #" adrsess" = _t, #" Postnummer" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"snummer", Int64.Type}, {"date", type datetime}, {"Namn", type text}, {" adrsess", type text}, {" Postnummer", type text}}),
    #"Sorted Rows" = Table.Buffer(Table.Sort(#"Changed Type",{{"date", Order.Descending}})),
    #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"snummer", "Namn", " adrsess", " Postnummer"})
in
    #"Removed Duplicates"

 

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

@Omid_Motamedise 

 Thanks alot.Make use of Table.Buffer() help me to solve my problem

 

regards

 

BA_Pete
Super User
Super User

Hi @mohsin-raza ,

 

In Power Query, select the table that you want to remove duplicates for. Press Ctrl+A (select all) to select all columns, then go to Remove Rows > Remove Duplicates. This will remove only rows where ALL column values are duplicated within the row.

Alternatively, you can multi-select (Ctrl+Click) columns to narrow down the columns you want to evaluate duplicates over, as @ZhangKun has alluded to previously.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




ZhangKun
Super User
Super User

Before you use the remove duplicate rows feature, you can select multiple columns(For example, "snummer" and "date").

Helpful resources

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

June 2025 community update carousel

Fabric Community Update - June 2025

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