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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
LadyPeshet
Regular Visitor

Create End Date using Start Dates

Hello,

 

I have a table in Power BI like this:

 

ID  START_DATE 
1   06/24/2016
1   06/24/2017
1   06/24/2018
2   08/08/2017
2   08/08/2016
3   12/12/2015

 

I would like to create a calculated column using DAX, in which I have to calculate the End Date for each record and leave blank if it is MAX Start Date. Output should look as in the example below:

 

ID  START_DATE  END_DATE
1   06/24/2016  06/23/2017
1   06/24/2017  06/23/2018
1   06/24/2018  
2   08/08/2017  
2   08/08/2016  08/07/2017
3   12/12/2015  

 

 

Currently I'm stuck with this solution where I can have MAX End Date for all of the historical records but it's not what I need: 

 

 

End Date = 
VAR TableKey = 'Table1'[ItemKey]
VAR CountDuplicates =
    CALCULATE (
        COUNTROWS ( 'Table1' ),
        ALL ( 'Table1' ),
        'Table1'[ItemKey] = TableKey
    )
VAR GetEndDate =
    CALCULATE (
        MAX ( 'Table1'[Start_Date] ),
        FILTER (
            'Table1',
            'Table1'[ItemKey] = EARLIER ( 'Table1'[ItemKey] )
        )
    )
RETURN
    IF (
        AND (
            CountDuplicates > 1,
            GetEndDate <> 'Table1'[Start_Date]
        ),
        GetEndDate - 1,
        BLANK ()
    )

 

 

Could you please support how to get desired result?

 

Thank you in advance!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @LadyPeshet 
Please try

END_DATE =
MINX (
    FILTER (
        CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
        'Table'[START_DATE] > EARLIER ( 'Table'[START_DATE] )
    ),
    'Table'[START_DATE]
) - 1

 

 

 

 

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @LadyPeshet 
Please try

END_DATE =
MINX (
    FILTER (
        CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
        'Table'[START_DATE] > EARLIER ( 'Table'[START_DATE] )
    ),
    'Table'[START_DATE]
) - 1

 

 

 

 

amitchandak
Super User
Super User

@LadyPeshet , Create a new column like

 

end date =

Var _min = Minx(filter( table, [ID] = earlier([ID]) && [Start Date] > earlier([Start Date]) ), [Start Date])

return

if(isblank(_min), blank(), _min-1)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.