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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
brief001
Helper II
Helper II

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!

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

wdx223_Daniel
Super User
Super User

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

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

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

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.

mahoneypat
Employee
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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors