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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX/power query removing duplicates by pk column and max date

Hello,

 

I have the dataset as mentioned below and I want to remove duplicates based on a column and max date. 

input set:

order_id posted_date
12734 5/29/2019
12735 4/16/2019
12734 4/15/2019
12735 4/20/2019
12735 3/18/2019


desired output
order_id posted_date
12374 5/29/2019
12375 4/20/2019

 

Thanks in advance!

2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

Hi @Anonymous 

Create a new calculated table:

NewTable =
FILTER (
    Table1,
    Table1[posted_date]
        = CALCULATE (
            MAX ( Table1[posted_date] ),
            ALLEXCEPT ( Table1, Table1[order_id] )
        )
)

 

View solution in original post

Anonymous
Not applicable

I am using the following check calculated column in order to solve the problem and a page level filter which accepts only 1's.
 
Check =
VAR _DATEFILTER = MAX('table'[post_date])
VAR _LASTDATE = CALCULATE(
MAX('table'[post_date]),
ALLEXCEPT(
table,
'table'[order_id]
),
'table'[post_date] <= _DATEFILTER
)
RETURN IF(LASTNONBLANK('table'[post_date], 1) = _LASTDATE, 1, 0)

View solution in original post

4 REPLIES 4
AlB
Super User
Super User

Hi @Anonymous 

Create a new calculated table:

NewTable =
FILTER (
    Table1,
    Table1[posted_date]
        = CALCULATE (
            MAX ( Table1[posted_date] ),
            ALLEXCEPT ( Table1, Table1[order_id] )
        )
)

 

This fixed my issue I was having too! Thanks for this!


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up!
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

Proud to be a Super User!

Anonymous
Not applicable

@AlB ,

 

Thanks for the response.

There are other columns in the table. I want to filter the duplicates based on order_id and posted_date. Can't it be done from power query or from DAX on the same table?

 

Thanks

 

 

Anonymous
Not applicable

I am using the following check calculated column in order to solve the problem and a page level filter which accepts only 1's.
 
Check =
VAR _DATEFILTER = MAX('table'[post_date])
VAR _LASTDATE = CALCULATE(
MAX('table'[post_date]),
ALLEXCEPT(
table,
'table'[order_id]
),
'table'[post_date] <= _DATEFILTER
)
RETURN IF(LASTNONBLANK('table'[post_date], 1) = _LASTDATE, 1, 0)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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