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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
CornelisV
Advocate II
Advocate II

Select a value from minimum and maximum date by group

Dear Power BI user,

 

I have this kind of table where I would like to get scores based on minimum and maximum date and by group.

DateGroupScore
01-Jan-24A678
02-Feb-24A345
03-Oct-24A129
05-Jan-24B500
18-Mar-24B400
11-Nov-24B300

 

The result should be:

Date minDate maxGroupScore minScore max
01-Jan-2403-Oct-24A678129
05-Jan-2411-Nov-24B500300

 

Could you please demonstrate how to create a new table?

 

Best regards,

Cornelis

2 ACCEPTED SOLUTIONS

Ah so you need the score at each of the dates?  What if there are multiple rows for each group and date? I would also use different column names (like "Score at Date min"  for example) to reduce the potential for misinterpretation.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDU9UrM0zUyUdJRcgRiM3MLpVgdoLiRrltqEkLc2MQUIm6s659cghA3NLKEiJsizHECYlMDA7C4oYWub2IRQtwEJm6o65dfhhA3BonHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Group = _t, Score = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Score", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {{"Date min", each List.Min([Date]), type nullable date}, {"Date max", each List.Max([Date]), type nullable date}, {"Rows", each _, type table [Date=nullable date, Group=nullable text, Score=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Score min", each Table.SelectRows([Rows], (k)=> k[Date]=[Date min])[Score]{0},Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Score max", each Table.SelectRows([Rows], (k)=> k[Date]=[Date max])[Score]{0},Int64.Type)
in
    #"Added Custom1"

 

View solution in original post

Anonymous
Not applicable

Thanks for the reply from lbendlin , please allow me to provide another insight:
Hi  @CornelisV ,

Here are the steps you can follow:

1. Create calculated table.

Test_Table =
var _table1=
ADDCOLUMNS(
    'Table',
    "Date min",
    MINX(FILTER('Table',[Group]=EARLIER([Group])),[Date]),
    "Date max",
    MAXX(FILTER('Table',[Group]=EARLIER([Group])),[Date]))
return
SUMMARIZE(
    _table1,[Date min],[Date max],[Group],
    "Score min",SUMX(FILTER(_table1,[Date]=EARLIER([Date min])),[Score]),
    "Score max",SUMX(FILTER(_table1,[Date]=EARLIER([Date max])),[Score]))

2. Result:

vyangliumsft_0-1735522773663.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Thanks for the reply from lbendlin , please allow me to provide another insight:
Hi  @CornelisV ,

Here are the steps you can follow:

1. Create calculated table.

Test_Table =
var _table1=
ADDCOLUMNS(
    'Table',
    "Date min",
    MINX(FILTER('Table',[Group]=EARLIER([Group])),[Date]),
    "Date max",
    MAXX(FILTER('Table',[Group]=EARLIER([Group])),[Date]))
return
SUMMARIZE(
    _table1,[Date min],[Date max],[Group],
    "Score min",SUMX(FILTER(_table1,[Date]=EARLIER([Date min])),[Score]),
    "Score max",SUMX(FILTER(_table1,[Date]=EARLIER([Date max])),[Score]))

2. Result:

vyangliumsft_0-1735522773663.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hello @Anonymous 

 

That is an alternative approach in comparison to @lbendlin and both providing the same solution.

Great and a good learning point for me 😊

 

Best regards,

 

Cornelis

 

lbendlin
Super User
Super User

You can use the standard "Group By" transform. Switch it to Advanced mode to allow for multiple aggregations.

lbendlin_0-1735399414423.png

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDU9UrM0zUyUdJRcgRiM3MLpVgdoLiRrltqEkLc2MQUIm6s659cghA3NLKEiJsizHECYlMDA7C4oYWub2IRQtwEJm6o65dfhhA3BonHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Group = _t, Score = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Score", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {{"Date min", each List.Min([Date]), type nullable date}, {"Date max", each List.Max([Date]), type nullable date}, {"Score min", each List.Min([Score]), type nullable number}, {"Score max", each List.Max([Score]), type nullable number}})
in
    #"Grouped Rows"

 

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

Dear @lbendlin , thank you for your swift reply. 

 

I'm afraid that this is not the result that I have hoped for. Not so strange because "Score min" and "Score max" correspondent to the score that belong to "Date min" and "Date max", respectively.

So, this is the desired output:

Score min max.png

Initially, the "Group by" transform provides the solution but does not account for the score that must link with the minimum and maximum date.

 

Hope that this is clear and can you give me a clue how to solve this question?

 

Best regards,

 

Cornelis

Ah so you need the score at each of the dates?  What if there are multiple rows for each group and date? I would also use different column names (like "Score at Date min"  for example) to reduce the potential for misinterpretation.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDU9UrM0zUyUdJRcgRiM3MLpVgdoLiRrltqEkLc2MQUIm6s659cghA3NLKEiJsizHECYlMDA7C4oYWub2IRQtwEJm6o65dfhhA3BonHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Group = _t, Score = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Score", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {{"Date min", each List.Min([Date]), type nullable date}, {"Date max", each List.Max([Date]), type nullable date}, {"Rows", each _, type table [Date=nullable date, Group=nullable text, Score=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Score min", each Table.SelectRows([Rows], (k)=> k[Date]=[Date min])[Score]{0},Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Score max", each Table.SelectRows([Rows], (k)=> k[Date]=[Date max])[Score]{0},Int64.Type)
in
    #"Added Custom1"

 

Hi @lbendlin ,

 

Thank you for the solution. Yes, it causes a bit confusion about this question.

Your solution:

 

Table.SelectRows([Rows], (k)=> k[Date]=[Date min])[Score]{0}

 

Is something that I'm looking for.

Thank you for your support and a happy new year!

 

Regards,

 

Cornelis

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.