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
memote1
Helper I
Helper I

Remove Duplicates and Sort Chronologically by row excluding specific columns

I have a table with columns for demographic information, vaccine date information and titer date/result information. By row, I need to remove duplicates and sort vaccine dates chronologically. I don't anticipate needing more than 4 columns for Vaccine Dates, but there is always the potential for more.

 

Raw Data

People Soft IDNameBirth DateDate of MMR vaccine 1Date of MMR vaccine 2Date of MMR vaccine 3Date of MMR vaccine 4Date of Measles vaccine 1Date of Measles vaccine 2RS.Date of MMR vaccine 1RS.Date of MMR vaccine 2RS.Date of MMR vaccine 3RS.Date of MMR vaccine 4Date of Measles IgG 1Result of Measles IgG 1Date of Measles IgG 2Result of Measles IgG 2RS.Date of Measles IgG 1RS.Result of Measles IgG 1
1Betty Boop 2/8/1999     2/8/19995/9/1999  1/1/2023Reactive    
2Darth Vader 6/10/20158/10/2012  5/10/2015           
3Chicken Little                 
4Donkey Kong 9/23/200610/23/2006    10/23/20065/1/20228/1/2022       

 

Desired Output

People Soft IDNameBirth DateDate of MMR vaccine 1Date of MMR vaccine 2Date of MMR vaccine 3Date of MMR vaccine 4Date of Measles IgG 1Result of Measles IgG 1Date of Measles IgG 2Result of Measles IgG 2RS.Date of Measles IgG 1RS.Result of Measles IgG 1
1Betty Boop 2/8/19995/9/1999  1/1/2023Reactive    
2Darth Vader 8/10/20125/10/20156/10/2015       
3Chicken Little           
4Donkey Kong 9/23/200610/23/20065/1/20228/1/2022      

 

My M Code

#"Reordered Columns" = Table.ReorderColumns(#"Expanded RS",{"People Soft ID", "Name", "Birth Date", "Date of MMR vaccine 1", "Date of MMR vaccine 2", "Date of MMR vaccine 3", "Date of MMR vaccine 4", "Date of Measles vaccine 1", "Date of Measles vaccine 2", "RS.Date of MMR vaccine 1", "RS.Date of MMR vaccine 2", "RS.Date of MMR vaccine 3", "RS.Date of MMR vaccine 4", "Date of Measles IgG 1", "Result of Measles IgG 1", "Date of Measles IgG 2", "Result of Measles IgG 2", "RS.Date of Measles IgG 1", "RS.Result of Measles IgG 1"}),
#"Extracted Date" = Table.TransformColumns(#"Reordered Columns",{}),
TableCombine = Table.CombineColumnsToRecord(#"Extracted Date","Vacc Dates", {"Date of MMR vaccine 1", "Date of MMR vaccine 2", "Date of MMR vaccine 3", "Date of MMR vaccine 4", "Date of Measles vaccine 1", "Date of Measles vaccine 2", "RS.Date of MMR vaccine 1", "RS.Date of MMR vaccine 2", "RS.Date of MMR vaccine 3", "RS.Date of MMR vaccine 4"}),
VaccList = Table.FromList(List.Sort(List.Distinct(List.RemoveNulls(List.Combine(Record.ToList([Vacc Dates]))))),Record.FieldValues, type table)
in
VaccList

 

I am getting this error message: 

memote1_1-1743788698071.png

 

Any help you can give me would be much appreciated!

 

Thank you!

 

1 ACCEPTED SOLUTION

@v-kpoloju-msft 

Thank you for your solution,

 

Unfortunately, I don't have access to DAX. However, I was able to come up with a very clunky and time consuming solution!

 

1. Reference the original table

2. Remove all the columns except "People Soft ID" and all the Vaccine date columns

3. Use the solution from this post from @dufoq3 

4. Remove empty columns found in this post

5. Merge this new table with the original. 

 

This is my resulting code:

memote1_0-1744128050695.png

 

 

 

View solution in original post

3 REPLIES 3
v-kpoloju-msft
Community Support
Community Support

Hi @memote1,
Thank you for reaching out to the Microsoft fabric community forum. Thank you @lbendlin, for your inputs on this issue.


After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used it as sample data on my end and successfully implemented it.  I have implemented the solution using DAX measures rather than Power Query (M code), as DAX offers a more transparent and manageable approach, especially for maintaining and enhancing the model over time.

vkpolojumsft_0-1744006503864.png

I am also including .pbix file for your better understanding, please have a look into it:

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

 

@v-kpoloju-msft 

Thank you for your solution,

 

Unfortunately, I don't have access to DAX. However, I was able to come up with a very clunky and time consuming solution!

 

1. Reference the original table

2. Remove all the columns except "People Soft ID" and all the Vaccine date columns

3. Use the solution from this post from @dufoq3 

4. Remove empty columns found in this post

5. Merge this new table with the original. 

 

This is my resulting code:

memote1_0-1744128050695.png

 

 

 

lbendlin
Super User
Super User

By row, I need to remove duplicates and sort vaccine dates chronologically. 

that is impossible unless they all take the same vaccinations in the same order.

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.