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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
user35131
Helper III
Helper III

Identify group with 3 or more rows and filter the one with the latest date.

I have a datatset that looks like this

 

IDLast NameFirst NameDate
101AndrewsJohn02/05/2022
101Andrews John 04/20/2022
101AndrewsJohn 12/04/2020
101 Andrews John 11/30/2020
102HarperLuke09/11/2021
102Harper Luke7/05/2021
103ClarkMark10/02/2021
103ClarkMark12/01/2021
103Clark Mark12/05/2021
104Le FleurJack09/03/2020
105JohnsonJim02/08/2021

 

I would like to set a filter that would leave me with this dataset

 

IDLast NameFirst NameDate
101AndrewsJohn04/20/2022
103ClarkMark12/05/2021

 

I' am grouping by ID, Last Name, and First Name but selecting the latest Date.

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @user35131 

 

You can try the following methods.

Measure:

latest date = 
IF (
    SELECTEDVALUE ( 'Table'[Date] )
        = IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER ( ALL ( 'Table' ), [ID] = SELECTEDVALUE ( 'Table'[ID] ) )
            ) >= 3,
            CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER ( ALL ( 'Table' ), [ID] = SELECTEDVALUE ( 'Table'[ID] ) )
            ),
            BLANK ()
        ),
    1,
    0
)

Drag Measure into the view of the original table and set it equal to 1.

vzhangti_0-1653643916861.png

vzhangti_1-1653643942123.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

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

5 REPLIES 5
v-zhangti
Community Support
Community Support

Hi, @user35131 

 

You can try the following methods.

Measure:

latest date = 
IF (
    SELECTEDVALUE ( 'Table'[Date] )
        = IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER ( ALL ( 'Table' ), [ID] = SELECTEDVALUE ( 'Table'[ID] ) )
            ) >= 3,
            CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER ( ALL ( 'Table' ), [ID] = SELECTEDVALUE ( 'Table'[ID] ) )
            ),
            BLANK ()
        ),
    1,
    0
)

Drag Measure into the view of the original table and set it equal to 1.

vzhangti_0-1653643916861.png

vzhangti_1-1653643942123.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

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

mahenkj2
Solution Sage
Solution Sage

Hi @user35131 ,

 

I can suggest you a possible solution in power query as below:

 

Group rows as below:

mahenkj2_0-1653408128401.png

 

This will create a column with all the rows of combined groups, just to get the number of records in that, and later we filter >=3 as below:

 

mahenkj2_1-1653408207971.png

 

mahenkj2_2-1653408234263.png

 

Final solution should be as intended:

mahenkj2_3-1653408279258.png

 

Removed unwanted columns.

 

Hope it helps.

 

 

user35131
Helper III
Helper III

I want to only select only the ones with 3 or more rows. That would include IF(ROWCOUNT?

PC2790
Community Champion
Community Champion

Ahh Ok!

I have implemented both the solution in the sample file attached, you can choose as per your convenience.

1) Using Power Query - It utilises the concept of grouping, expanding, extracting the max date and removing duplicates.

2) Using Dax-It uses the Summaize dax function to do the grouping and then filtering out  the columns having rowcount>2

 

PC2790
Community Champion
Community Champion

Hey @user35131 ,

 

If you are looking to summarize based on ID,First Name and Last Name then you can use dax as below:

NewTable = ADDCOLUMNS(
    SUMMARIZE( SampleTable, SampleTable[ID],SampleTable[First Name],SampleTable[Last Name] ),
    "Max", CALCULATE(MAX(SampleTable[Date] ) )
)

It will give you the outcome as below:

PC2790_1-1653403204090.png

As per your given expected output, I don't understand the logic behind having only two selected columns as grouping using ID, FName and LName, Max Date against all IDs will be returned.

 

See if the above proposed solution caters to your requirement

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.