Forum Discussion
Select a value from minimum and maximum date by group
- 1 year ago
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" - Anonymous1 year ago
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:
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
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:
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