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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.