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
oliverblane
Helper III
Helper III

Remove duplicate rows from a filtered table

I want to apply a date filter to a table and then calculate a table from this, removing all duplicates in this calculated table and keeping the duplicates that have the most recent Created_Date.

 

I have a table (InitialTable) like the following that is to be filtered by a date:

oliverblane_0-1636721082638.png

 

If my applied date filter was from 01/07/2021 to 02/10/2021, for example, then the desired output table (CalculatedTable) would be:

oliverblane_1-1636721388784.png

Notice how both entries for ID 2 were in the date range, but only the most recent entry remains.

 

I know that something similar can be done in Power Query, but the issue is that I would like this to change based on the date filter. For example, in Power Query, the first two rows would have been removed, whereas if this date filter is set to 01/06/2021 - 01/08/2021, then I would like to still have those first two rows.

 

Hopefully I have explained my issue well enough - I am really grateful for any help I can get on this!

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @oliverblane ,

 

Not quite sure what your logic is for remove duplicate rows. Based on ID or based on id+Establishment.

 

IF ID, you can add an index column and try this code to keep the recent date rows.

 

Create_date_m =
VAR _maxdate =
    CALCULATE( MAX( 'Table'[Create_Date] ), ALLEXCEPT( 'Table', 'Table'[ID] ) )
VAR _c_index =
    CALCULATE(
        MAX( 'Table'[Index] ),
        FILTER( ALLEXCEPT( 'Table', 'Table'[ID] ), [Create_Date] = _maxdate )
    )
RETURN
    IF( MAX( 'Table'[Index] ) = _c_index, _maxdate, BLANK() )

 

And in the vsiual table , replace create_date with above measure. Use the slicer to filter date range.

The result:

vchenwuzmsft_0-1637035344509.png

 

I put my pbix file in the end you can refer.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
v-chenwuz-msft
Community Support
Community Support

Hi @oliverblane ,

 

Not quite sure what your logic is for remove duplicate rows. Based on ID or based on id+Establishment.

 

IF ID, you can add an index column and try this code to keep the recent date rows.

 

Create_date_m =
VAR _maxdate =
    CALCULATE( MAX( 'Table'[Create_Date] ), ALLEXCEPT( 'Table', 'Table'[ID] ) )
VAR _c_index =
    CALCULATE(
        MAX( 'Table'[Index] ),
        FILTER( ALLEXCEPT( 'Table', 'Table'[ID] ), [Create_Date] = _maxdate )
    )
RETURN
    IF( MAX( 'Table'[Index] ) = _c_index, _maxdate, BLANK() )

 

And in the vsiual table , replace create_date with above measure. Use the slicer to filter date range.

The result:

vchenwuzmsft_0-1637035344509.png

 

I put my pbix file in the end you can refer.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you for this!

amitchandak
Super User
Super User

@oliverblane , First of all, slicer values will not filter calculated table or columns

 

Create a visual with ID , This measure

Measure =
VAR __id = MAX ('Table'[ID] )
VAR __date = CALCULATE ( MAX('Table'[Date] ), ALLSELECTED ('Table' ), 'Table'[ID] = __id )
CALCULATE ( MAX ('Table'[Establishment] ), VALUES ('Table'[ID] ),'Table'[ID] = __id,'Table'[Date] = __date )

 

 

and Date , if needed take max date 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Right, I see. So it is not possible to remove duplicates based on a date filter?

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.