March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi everyone,
I have a table with a list of projects. Each project is duplicated per the number of reporting periods. The reporting period is identified by a number column.
I am currently using Power Query to identify the latest record based on this number column. I am using the Group By function with List Max to do this. Is there a way to modify this to identify the 2nd largest? If not, is there an alternate method anyone could suggest?
let
Source = CommonDataService.Database(varDataverse),
dbo_cr37a_dataverse_confidence_app_project_entry = Source{[Schema="dbo",Item="cr37a_dataverse_confidence_app_project_entry"]}[Data],
#"Reordered Columns" = Table.ReorderColumns(dbo_cr37a_dataverse_confidence_app_project_entry,{"cr37a_dataverse_confidence_app_project_entryid","createdon", "modifiedon", "createdbyname", "modifiedbyname", "cr37a_projectname", "cr37a_project_code", "cr37a_programme_code", "cr37a_programme_name", "cr37a_responsible_owner_name", "cr37a_responsible_owner_email", "cr37a_project_health_score_previous", "cr37a_project_health_score", "cr37a_project_health_score_forecast", "cr37a_project_health_previous_forecast", "cr37a_plan_score", "cr37a_finance_score", "cr37a_risk_score", "cr37a_resource_score", "cr37a_team_wellbeing_score", "cr37a_overall_score", "cr37a_activities_this_period", "cr37a_activities_next_period", "cr37a_is_approved_by_board", "cr37a_sort_index", "cr37a_reporting_period", "cr37a_reporting_sub_period", "cr37a_plan_score_previous", "cr37a_finance_score_previous", "cr37a_risk_score_previous", "cr37a_resource_score_previous", "cr37a_team_wellbeing_score_previous", "cr37a_activities_previous_period", "cr37a_overall_score_previous"}),
#"Grouped Rows" = Table.Group(#"Reordered Columns", {"cr37a_project_code"}, {{"LatestRecord", each List.Max([cr37a_sort_index]), Int64.Type}, {"All", each _, type table [cr37a_dataverse_confidence_app_project_entryid=text, createdon=nullable datetime, modifiedon=nullable datetime, createdbyname=nullable text, modifiedbyname=nullable text, cr37a_projectname=nullable text, cr37a_project_code=nullable text, cr37a_programme_code=nullable text, cr37a_programme_name=nullable text, cr37a_responsible_owner_name=nullable text, cr37a_responsible_owner_email=nullable text, cr37a_project_health_score_previous=nullable number]}}),
#"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"cr37a_projectname", "cr37a_programme_code", "cr37a_programme_name"}, {"cr37a_projectname", "cr37a_programme_code", "cr37a_programme_name"})
in
#"Expanded All"
Could anyone point me into the right direction?
Best regards,
AmiK
Solved! Go to Solution.
Hi,
This M code works
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"Reporting Period", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Project Name"}, {{"2nd latest reporting period", each try List.Sort([Reporting Period],Order.Descending){1} otherwise 1, type nullable number}})
in
#"Grouped Rows"
Hope this helps.
As always thanks for the support @Ashish_Mathur.
@deevaker thanks for the suggestion but there is a specific reason I need an M-Query solution.
You are welcome.
You can use it in DAX, it depends if you would like to create a separate table out of it or just need a measure.
For a separate summary table you can use below DAX :
And if you only need a measure, than write this while creating measure:
Thanks,
Deevaker Goel
+919711975011
Deevaker@hotmail.com
Hi,
This M code works
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"Reporting Period", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Project Name"}, {{"2nd latest reporting period", each try List.Sort([Reporting Period],Order.Descending){1} otherwise 1, type nullable number}})
in
#"Grouped Rows"
Hope this helps.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
85 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |