Forum Discussion

brief001's avatar
brief001
Icon for Helper II rankHelper II
5 years ago
Solved

Create grouped table from date field

I want to create a table from another table. This table must group the records whose unique record must be preserved based on a date field. In the table you see John in double, my result should be that John of team Sweden is kept, because that date has the highest value.

 

NameTeamDate
JohnTeam Polen01-01-2019
JohnTeam Sweden01-01-2021
FredTeam Holland01-01-2020
JackTeam Belgium01-01-2020
SteveTeam Germany01-01-2021

 

The DAX formula for creating a new calculated table must return the result below. (The John from Team Sweden must stay, because the date field of John from Team Poland was before the date of John from Team Sweden).

 

NameTeamDate
JohnTeam Sweden01-01-2021
FredTeam Holland01-01-2020
JackTeam Belgium01-01-2020
SteveTeam Germany01-01-2021

 

Thanks in advance for the help!

  • Please use this table expression.

     

    NewTable =
    ADDCOLUMNS (
        DISTINCT ( Team[Name] ),
        "Date",
            CALCULATE (
                LASTNONBLANK (
                    Team[Date],
                    MIN ( Team[Date] )
                )
            ),
        "Team",
            CALCULATE (
                LASTNONBLANKVALUE (
                    Team[Date],
                    MIN ( Team[Team] )
                )
            )
    )

     

    Pat

  • Table=FILTER(SampleData,SampleData[Date]=CALCULATE(MAX(SampleData[Date]),ALLEXCEPT(SampleData,SampleData[Name])))

4 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    Please use this table expression.

     

    NewTable =
    ADDCOLUMNS (
        DISTINCT ( Team[Name] ),
        "Date",
            CALCULATE (
                LASTNONBLANK (
                    Team[Date],
                    MIN ( Team[Date] )
                )
            ),
        "Team",
            CALCULATE (
                LASTNONBLANKVALUE (
                    Team[Date],
                    MIN ( Team[Team] )
                )
            )
    )

     

    Pat

    • brief001's avatar
      brief001
      Icon for Helper II rankHelper II

      Thank you very much for your quick response. I've tested your formula and it works. And personally beautiful, I understand your formula too.

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

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

    • brief001's avatar
      brief001
      Icon for Helper II rankHelper II

      Thank you for also posting this answer. The formula works differently from the answer given earlier. But the result is the same. And I also understand this formula now that I read it.