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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Mat42
Resolver I
Resolver I

Max/Min Calculated Column

This is either going to be easy or horribly complicated.

 

Let's say I ave a simple table of data:

 

NameDate
Dave01/01/2021
Dave01/01/2021
Dave02/02/2019
Dave01/01/2021
Steve12/10/2020
Steve13/10/2020
Steve14/10/2020
Steve15/10/2020

 

All I want to be able to do is add in 2 columns that will show me the earliest date and latest date for each person, so it would look like this:

 

NameDateMinDateMaxDate
Dave01/01/202102/02/201901/01/2021
Dave01/01/202102/02/201901/01/2021
Dave02/02/201902/02/201901/01/2021
Dave01/01/202102/02/201901/01/2021
Steve12/10/202012/10/202015/10/2020
Steve13/10/202012/10/202015/10/2020
Steve14/10/202012/10/202015/10/2020
Steve15/10/202012/10/2020

15/10/2020

 

Am I missing something obvious? Because I can't work this out.

1 ACCEPTED SOLUTION
bcdobbs
Community Champion
Community Champion

Your calculated column needs to look like:

Min Date = 
    CALCULATE (
        MIN ( Person[Date] ),
        ALLEXCEPT( Person, Person[Name] )
    )


If you just did MIN on it's own it would find the minimum date in the whole column.

CALCULATE forces a context transition that moves all the columns in the current row into the filter context.

However CALCULATE ( MIN ( Person[Date] ) ) will just return the date of the current row because CALCULATE has included the date column in the filter.

 

The solution above tells calculate to remove the filters from everything apart from Person[Name].



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

5 REPLIES 5
v-jingzhang
Community Support
Community Support

Hi @Mat42 

 

Use the Group by feature under Transform tab and set up three aggregation columns like in the following image. 

21122007.jpg

 

After grouping, expand "All" column and select only Date column to expand. 

21122008.jpg

let
  Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksS1XSUTIw1AciIwMjQ6VYHUKiRvpAZGRgaIlHbXBJKljY0Ejf0AAkbIAqbIxd2AS7sClCOBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t]),
  #"Changed Type" = Table.TransformColumnTypes(Source, {{"Name", type text}, {"Date", type date}}, "en-GB"),
  #"Grouped Rows" = Table.Group(#"Changed Type", {"Name"}, {{"All", each _, type table[Name = nullable text, Date = nullable text]}, {"MinDate", each List.Min([Date]), type nullable text}, {"MaxDate", each List.Max([Date]), type nullable text}}),
  #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Date"}, {"Date"})
in
  #"Expanded All"

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Mat42
Resolver I
Resolver I

Thanks for the replies, guys, that's really helpful.

 

I should have said that it needs to be created in Power Query as this is for a dataflow. Can this be replicated in M?

bcdobbs
Community Champion
Community Champion

I think you'd have to make use of the group by feature in PowerQuery. Will have a play!



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
bcdobbs
Community Champion
Community Champion

Your calculated column needs to look like:

Min Date = 
    CALCULATE (
        MIN ( Person[Date] ),
        ALLEXCEPT( Person, Person[Name] )
    )


If you just did MIN on it's own it would find the minimum date in the whole column.

CALCULATE forces a context transition that moves all the columns in the current row into the filter context.

However CALCULATE ( MIN ( Person[Date] ) ) will just return the date of the current row because CALCULATE has included the date column in the filter.

 

The solution above tells calculate to remove the filters from everything apart from Person[Name].



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
amitchandak
Super User
Super User

@Mat42 , Based on what I got

 

new columns

 

Min date = minx(filter(Table, [Name] =earlier([Name]) ), [Date])

 

Max date = maxx(filter(Table, [Name] =earlier([Name]) ), [Date])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.