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
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
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.