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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
adhossain
Regular Visitor

Dynamically filter duplicates

I ran into a strange situation where I have an excel table like below;

 

ActivityUnique ID of Activity# AchievedReporting MonthStatus
Training 1ID01202023-01Ongoing
Orientation 1ID02262023-01Ongoing
Distribution 1ID03252023-01Ongoing
Training 1ID01212023-02Ongoing
Orientation 1ID02692023-02Ongoing
Distribution 1ID03302023-02Ongoing
Training 1ID01332023-03Completed
Orientation 1ID02832023-03Ongoing
Distribution 1ID03742023-03Ongoing
Training 2ID04392023-04Ongoing
Orientation 1ID02252023-04Completed
Distribution 1ID03962023-04Ongoing
Training 2ID04332023-05Ongoing
Orientation 2ID05412023-05Ongoing
Distribution 1ID03822023-05Completed
Training 2ID04722023-06Ongoing
Orientation 2ID05362023-06Completed
Distribution 2ID06852023-06Ongoing

 

I am able to remove duplicates based on "Unique ID of Activity" column where I want to keep the items which are "Completed" only but remove the "Ongoing" duplicate entries. I used "Table.Buffer" method. My query M code is below;

 

 

 

 

 

 

let
    Source = Excel.Workbook(File.Contents("C:\test\Activity_Tracker.xlsx"), null, true),
    Acticity_Table_Table = Source{[Item="Acticity_Table",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Acticity_Table_Table,{{"Activity", type text}, {"Unique ID of Activity", type text}, {"# Achieved", Int64.Type}, {"Reporting Month", type date}, {"Status", type text}}),
    #"Sorted Rows" = Table.Buffer(Table.Sort(#"Changed Type",{{"Status", Order.Ascending}})),
    #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"Unique ID of Activity"})
in
    #"Removed Duplicates"

 

 

 

 

 

 

This all works fine and returns a similar table like below which is very obvious to happen.

Capture.PNG

 

But I want a differnt result. As you can see, though my dataset starts from 2023-01 (or January 2023 in reporting Month column), I am not able to see what happened during that time as "Remove Duplicates" command removed those rows. How can I be able to see what happened in first 1 month, or first two months or first three months.

 

What could be a solution to this scenario?

1 ACCEPTED SOLUTION
Payeras_BI
Solution Sage
Solution Sage

Hi @adhossain ,

I don't think you want to remove duplicates in Power Query if later you want to be able to visualize those rows in your matrix.

I would load everything instead and control what is shown, through measures, like this:

Payeras_BI_0-1686733487367.png

Measures:

_# Achieved = 
VAR
maxReportingMonth = CALCULATE(MAX('Table'[Reporting Month]),ALLSELECTED('Table'[Reporting Month]))
RETURN
CALCULATE(SELECTEDVALUE('Table'[# Achieved]),'Table'[Reporting Month]= maxReportingMonth)
--------------------
_# Reporting Month = 
VAR
maxReportingMonth = CALCULATE(MAX('Table'[Reporting Month]),ALLSELECTED('Table'[Reporting Month]))
RETURN
maxReportingMonth
--------------------
_Status = 
VAR
maxReportingMonth = CALCULATE(MAX('Table'[Reporting Month]),ALLSELECTED('Table'[Reporting Month]))
RETURN
CALCULATE(SELECTEDVALUE('Table'[Status]),'Table'[Reporting Month]= maxReportingMonth)

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

View solution in original post

5 REPLIES 5
Payeras_BI
Solution Sage
Solution Sage

Hi @adhossain ,

I don't think you want to remove duplicates in Power Query if later you want to be able to visualize those rows in your matrix.

I would load everything instead and control what is shown, through measures, like this:

Payeras_BI_0-1686733487367.png

Measures:

_# Achieved = 
VAR
maxReportingMonth = CALCULATE(MAX('Table'[Reporting Month]),ALLSELECTED('Table'[Reporting Month]))
RETURN
CALCULATE(SELECTEDVALUE('Table'[# Achieved]),'Table'[Reporting Month]= maxReportingMonth)
--------------------
_# Reporting Month = 
VAR
maxReportingMonth = CALCULATE(MAX('Table'[Reporting Month]),ALLSELECTED('Table'[Reporting Month]))
RETURN
maxReportingMonth
--------------------
_Status = 
VAR
maxReportingMonth = CALCULATE(MAX('Table'[Reporting Month]),ALLSELECTED('Table'[Reporting Month]))
RETURN
CALCULATE(SELECTEDVALUE('Table'[Status]),'Table'[Reporting Month]= maxReportingMonth)

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

Hi @Payeras_BI 

At first thank you for your suggestions. But this returns entries of duplicate items. I only want to return the values from recent dates only fro the same Unique IDs. Kindly see below HIGHLIGHTED rows which I only want to retrieve.

 

  • For first three months

3.PNG

 

  • For first four months

4.PNG

 

  • For first 5 months

5.PNG

  • For first six months

all.PNG

 

Thanks in advanced.

 

Attaching the sample files if you want to exercise.

Excel data sheet 

Power Bi report

Hi @adhossain ,

I have checked your file and seen that you have written the measures but you failed to drag on of them to the table visualization.

Please substitute the Status field by the status measure and come back to me with the result.

Payeras_BI_1-1686751436591.png

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

Thank you very much. Yes, that is exactly what I was looking for. I forgot to drag Status (measure) on the table.

 

Thank you again

I'm glad I could assist you. 🙂

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors