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

Pick first value for each id based on date

Hi guys,

 

I am struggling to pick up the first value registered for a id based on the earliest date.

So for the customer below, a membership is first created on 01.01.2016 and the first activity on this membership is created on 01.02.2017. For this membership I only want the first activity created to show up instead of all the others below. Then for the second membership which is created on 13.02.2019 the first activity is on 15.02.2019. I want to filter the table to only show the first activity for this membership instead of all.

 

I basically want to pick the acitivity row with the date closest to the membership created date for each customer id.


How can I achieve this in dax?

 

Dax.PNG

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

Hi @bininja 

Create measures

Measure = DATEDIFF(MAX('Table'[created date]),MAX('Table'[activity date]),DAY)

Measure 2 =
RANKX (
    FILTER (
        ALL ( 'Table' ),
        'Table'[id] = MAX ( 'Table'[id] )
            && 'Table'[created date] = MAX ( 'Table'[created date] )
    ),
    [Measure],
    ,
    ASC,
    DENSE
)
Capture25.JPG
 
Best Regards
Maggie
Community Support Team _ Maggie Li
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-juanli-msft
Community Support
Community Support

Hi @bininja 

Create measures

Measure = DATEDIFF(MAX('Table'[created date]),MAX('Table'[activity date]),DAY)

Measure 2 =
RANKX (
    FILTER (
        ALL ( 'Table' ),
        'Table'[id] = MAX ( 'Table'[id] )
            && 'Table'[created date] = MAX ( 'Table'[created date] )
    ),
    [Measure],
    ,
    ASC,
    DENSE
)
Capture25.JPG
 
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur can this be done with a measure aswell? I see that you created a calculated column. I only have the possibility to create measures in the dataset as it is a live connection which limits alot of the options for me.

Hi,

I am not sure of how to solve this question with a measure.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @bininja 
Try this:
Latest Date =
CALCULATE ( MAX ( Table[Date] ), ALLEXCEPT ( Table, Table[ID] ) )
Cheers!
A

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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