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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
luckygirl
Helper I
Helper I

Sort a table before calculate based on date

I have a table like below.

CodeCompletedDateProductDetail
11/01/2018A
11/04/2019B
123/05/2021C
29/02/2018D
25/05/2021C
26/05/2022A
31/01/2018K
310/05/2019B
330/06/2021C
31/01/2024L
46/06/2017B
49/03/2018J
45/05/2021C
43/03/2024D

 

I need to create a Target column based on CompletedDate for Each Code group. So the expected solution would be like below.

CodeCompletedDateProductDetailTarget
11/01/2018AB
11/04/2019BC
123/05/2021C 
29/02/2018DC
25/05/2021CA
26/05/2022A 
31/01/2018KB
310/05/2019BC
330/06/2021CL
31/01/2024L 
46/06/2017BJ
49/03/2018JC
45/05/2021CD
43/03/2024D 

 

I tried the below DAX code. It generates correct results for some but not all. Can someone please help me. Thanks.

Target =
CALCULATE (
    MIN ( Tbl[ProductDetail] ),
    FILTER (
        'Tbl',
        Tbl[ClientCode] = EARLIER ( Tbl[ClientCode] )
         && Tbl[CompletedDate] > EARLIER ( Tbl[CompletedDate] )
    )
)

The results by the above code. Incorrect ones are highlighted in red.
CodeCompletedDateProductDetailTarget
11/01/2018AB
11/04/2019BC
123/05/2021C 
29/02/2018DA
25/05/2021CA
26/05/2022A 
31/01/2018KB
310/05/2019BC
330/06/2021CL
31/01/2024L 
46/06/2017BC
49/03/2018JC
45/05/2021CD
43/03/2024D 


1 ACCEPTED SOLUTION
Irwan
Super User
Super User

hello @luckygirl 

 

please check if this accomodate your need.

Irwan_0-1737083796882.png

create a new calculated column with following DAX

Target = 
var _Min =
MINX(
    FILTER(
        'Table',
        'Table'[CompletedDate]>EARLIER('Table'[CompletedDate])&&
        'Table'[Code]=EARLIER('Table'[Code])
    ),
    'Table'[CompletedDate]
)
Return
MINX(
    FILTER(
        'Table',
        'Table'[CompletedDate]=_Min
    ),
    'Table'[ProductDetail]
)
 
Hope this will help.
Thank you.

View solution in original post

3 REPLIES 3
luckygirl
Helper I
Helper I

@Irwan Thanks a lot. Works well 🙂

Hello @luckygirl 

 

Glad to be a help.

Thank you.

Irwan
Super User
Super User

hello @luckygirl 

 

please check if this accomodate your need.

Irwan_0-1737083796882.png

create a new calculated column with following DAX

Target = 
var _Min =
MINX(
    FILTER(
        'Table',
        'Table'[CompletedDate]>EARLIER('Table'[CompletedDate])&&
        'Table'[Code]=EARLIER('Table'[Code])
    ),
    'Table'[CompletedDate]
)
Return
MINX(
    FILTER(
        'Table',
        'Table'[CompletedDate]=_Min
    ),
    'Table'[ProductDetail]
)
 
Hope this will help.
Thank you.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.