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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Apollo71
New Member

Group By Query

Hi,

 

I am trying to create a Power BI form with the following data, but group by serial number and showing the latest service date and corresponding name of the engineer.

 

Serial number    Service Date       Service Engineer

1234                     1/1/24                 Bill

1234                     1/2/24                 Fred

1234                     1/3/24                 Joe

 

If I group by serial number and use MAX of service date I get the right grouping but cannot figure out a way to show the engineer name?

 

Any guidance would be much appreciated

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

here is a workaround for you

try to create a rank column

= Table.AddColumn(#"Changed Type","Rank",each Table.RowCount(Table.Distinct(Table.SelectRows(#"Changed Type",(x)=>x[SD]>[SD] and x[SN]=[SN]),"SD"))+1)

11.png

 

then filter rank =1

 

12.PNG

 

at last you can delete rank column

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Serial number", Int64.Type}, {"Service Date", type date}, {"Service Engineer", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Serial number"}, {{"Count", each Table.Max(_,"Service Date")}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Service Date", "Service Engineer"}, {"Service Date", "Service Engineer"})
in
    #"Expanded Count"

Ashish_Mathur_0-1710817290229.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Apollo71 ,

@ryan_mayu Good answer!
And if you must want to use Group by, you can try this way:
First, Duplicate the Table:

vjunyantmsft_0-1710813785030.png

In the new table Table(2), use Group by:

vjunyantmsft_1-1710813825555.png

Then in the Table(2), click Merge Queries as New:

vjunyantmsft_2-1710813870253.png

Configure as shown in the following figure:

vjunyantmsft_3-1710814000528.png

Match the Serial number column of the two tables, and have the Max and Service Date columns match.
The output is as below:

vjunyantmsft_4-1710814086794.png

Click here to expand the Table column:

vjunyantmsft_5-1710814115672.png

vjunyantmsft_6-1710814126871.png

And the final output is as below:

vjunyantmsft_7-1710814154822.png


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

ryan_mayu
Super User
Super User

here is a workaround for you

try to create a rank column

= Table.AddColumn(#"Changed Type","Rank",each Table.RowCount(Table.Distinct(Table.SelectRows(#"Changed Type",(x)=>x[SD]>[SD] and x[SN]=[SN]),"SD"))+1)

11.png

 

then filter rank =1

 

12.PNG

 

at last you can delete rank column

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




kpost
Super User
Super User

What is your data source?  Is it all coming from a single place or no?

 

If it is coming from multiple places then you may have to look at the connections between your data tables.

Can you upload a sample .pbix file with some bogus data (if the data is confidential) that simulates the problem? 

It's working fine for me, assuming all of the data is coming from a single document:

 

https://files.catbox.moe/m03b75.pbix

//Mediocre Power BI Advice,  but it's free//

Thanks,

 

Managed to do what I needed by creating a rank column and grouping by the highest date

Helpful resources

Announcements
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!

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.

Top Solution Authors