Forum Discussion

TimPowerBi2's avatar
TimPowerBi2
Frequent Visitor
3 years ago
Solved

Get the first date for a name over multiple rows

Hello Power BI Community!

 

I am trying to get the earliest and latest date for every name in a timeseries table. I want to do this through a calculated column so I can run further analysis on the results. It would be greatly appreciated to get some help!

 

Below are to examples:

Current situation

NameDate
Michael23-7-2023
Michael24-7-2023
Michael12-6-2023
Charles5-5-2023
Charles26-7-2023
Henk2-2-2023
Henk4-6-2023
Henk15-7-2023
Henk7-1-2023

 

Desired result

 

NameDateEarliest Latest
Michael23-7-202312-6-202324-7-2023
Michael24-7-202312-6-202324-7-2023
Michael12-6-202312-6-202324-7-2023
Charles5-5-20235-5-202326-7-2023
Charles26-7-20235-5-202326-7-2023
Henk2-2-20237-1-202315-7-2023
Henk4-6-20237-1-202315-7-2023
Henk15-7-20237-1-202315-7-2023
Henk7-1-20237-1-202315-7-2023
  • Hello!!

     

    I hope that I can help you. I have created a calculated table. 

    Desired result = 
    SUMMARIZE(Tabla,  
    Tabla[Name],
    Tabla[Date],
    "Earliest", CALCULATE(MIN(Tabla[Date]), ALLEXCEPT(Tabla,Tabla[Name])),
    "Latest", CALCULATE(MAX(Tabla[Date]), ALLEXCEPT(Tabla,Tabla[Name]))
    )

     

    This is the result

     

     

    I hope that I have helped you.

     

8 Replies

  • MBernalBI's avatar
    MBernalBI
    Frequent Visitor

    Hello!!

     

    I hope that I can help you. I have created a calculated table. 

    Desired result = 
    SUMMARIZE(Tabla,  
    Tabla[Name],
    Tabla[Date],
    "Earliest", CALCULATE(MIN(Tabla[Date]), ALLEXCEPT(Tabla,Tabla[Name])),
    "Latest", CALCULATE(MAX(Tabla[Date]), ALLEXCEPT(Tabla,Tabla[Name]))
    )

     

    This is the result

     

     

    I hope that I have helped you.

     

    • TimPowerBi2's avatar
      TimPowerBi2
      Frequent Visitor

      Thank you so much for the quick solution!

       

      It works really well thank you. The only thing that is bugging me is that despite the name field having only unique values in the new custom table I can only create a many-to-many relationship between it and the original table.

       

      Do you know why this is? 

  • Anonymous's avatar
    Anonymous
    Not applicable

    you can create two column 

    Latest =CALCULATE(MAX(Table[Date]),ALLEXCEPT(Table, Table[Name]))


    Earliest =CALCULATE(MIN(Table[Date]),ALLEXCEPT(Table, Table[Name]))

    you can get the required table