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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Most recent calculation

Dear all,

I am looking for a calculation which does the following:

If the STACK is the same and the TYPE is the same and the DATE is the same, calculate the MOST_RECENT_TIME_STAMP.

In below example the outcome is is 23-10-2020 08:00.

Thanks!

John

 

stackpositiontypedatetime_stampmost_recent_time_Stamp
WP2WP2.12Waiting Estimate23-10-202023-10-2020 08:0023-10-2020 08:00
WP2WP2.11Waiting Estimate23-10-202023-10-2020 08:0023-10-2020 08:00
WP2WP2.10Waiting Estimate23-10-202023-10-2020 07:5923-10-2020 08:00
WP2WP2.09Waiting Estimate23-10-202023-10-2020 07:5923-10-2020 08:00
WP2WP2.08Waiting Estimate23-10-202023-10-2020 07:5923-10-2020 08:00
WP2WP2.07Waiting Estimate23-10-202023-10-2020 07:5823-10-2020 08:00
WP2WP2.06Waiting Estimate23-10-202023-10-2020 07:5823-10-2020 08:00
WP2WP2.05Waiting Estimate23-10-202023-10-2020 07:5823-10-2020 08:00
WP2WP2.04Waiting Estimate23-10-202023-10-2020 07:5723-10-2020 08:00
WP2WP2.03Waiting Estimate23-10-202023-10-2020 07:5723-10-2020 08:00
WP2WP2.02Waiting Estimate23-10-202023-10-2020 07:5723-10-2020 08:00
WP2WP2.01Waiting Estimate23-10-202023-10-2020 07:5623-10-2020 08:00
WP2WP2.12Waiting Estimate23-10-202023-10-2020 07:2823-10-2020 08:00
WP2WP2.13Waiting Estimate23-10-202023-10-2020 07:2723-10-2020 08:00
WP2WP2.14Waiting Estimate23-10-202023-10-2020 07:2723-10-2020 08:00
1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

@Anonymous ,

 

In Power Query, go to New Source>Blank Query then in Advanced Editor paste my code over the default code. You can then follow the steps I took to complete this.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg8wUtIBkXqGYEZiZklmXrqCa3FJZm5iSSpQyMhY19BA18jAyACFo2BgYWWAVShWB8VYQ9oYa0CiseZWppaEjTWwpI2xFrQx1px0Yy2IMNaMNsaa0sZYE9KNNSfCWGPaGEtqLiPSWFJzGdBYMyJyGemuNSIiygxJD1sjIgLBkPSUgMPYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [stack = _t, position = _t, #"type" = _t, date = _t, time_stamp = _t, most_recent_time_Stamp = _t]),
    chgSourceTypes = Table.TransformColumnTypes(Source,{{"stack", type text}, {"position", type text}, {"type", type text}, {"date", type date}, {"time_stamp", type datetime}, {"most_recent_time_Stamp", type datetime}}),
    groupWithData = Table.Group(chgSourceTypes, {"stack", "type", "date"}, {{"data", each _, type table [stack=nullable text, position=nullable text, type=nullable text, date=nullable date, time_stamp=nullable datetime, most_recent_time_Stamp=nullable datetime]}, {"calcMostRecent", each List.Max([time_stamp]), type nullable datetime}}),
    expandDataCol = Table.ExpandTableColumn(groupWithData, "data", {"position", "time_stamp", "most_recent_time_Stamp"}, {"position", "time_stamp", "most_recent_time_Stamp"})
in
    expandDataCol

 

This will need to be tested on a more diverse dataset as the example data provided only seemed to include one relevant grouping, but it should work fine.

 

Let me know if you have any trouble applying this solution to your actual data.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

@Anonymous ,

 

In Power Query, go to New Source>Blank Query then in Advanced Editor paste my code over the default code. You can then follow the steps I took to complete this.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg8wUtIBkXqGYEZiZklmXrqCa3FJZm5iSSpQyMhY19BA18jAyACFo2BgYWWAVShWB8VYQ9oYa0CiseZWppaEjTWwpI2xFrQx1px0Yy2IMNaMNsaa0sZYE9KNNSfCWGPaGEtqLiPSWFJzGdBYMyJyGemuNSIiygxJD1sjIgLBkPSUgMPYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [stack = _t, position = _t, #"type" = _t, date = _t, time_stamp = _t, most_recent_time_Stamp = _t]),
    chgSourceTypes = Table.TransformColumnTypes(Source,{{"stack", type text}, {"position", type text}, {"type", type text}, {"date", type date}, {"time_stamp", type datetime}, {"most_recent_time_Stamp", type datetime}}),
    groupWithData = Table.Group(chgSourceTypes, {"stack", "type", "date"}, {{"data", each _, type table [stack=nullable text, position=nullable text, type=nullable text, date=nullable date, time_stamp=nullable datetime, most_recent_time_Stamp=nullable datetime]}, {"calcMostRecent", each List.Max([time_stamp]), type nullable datetime}}),
    expandDataCol = Table.ExpandTableColumn(groupWithData, "data", {"position", "time_stamp", "most_recent_time_Stamp"}, {"position", "time_stamp", "most_recent_time_Stamp"})
in
    expandDataCol

 

This will need to be tested on a more diverse dataset as the example data provided only seemed to include one relevant grouping, but it should work fine.

 

Let me know if you have any trouble applying this solution to your actual data.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

@BA_Pete ,

 

Thanks, is working fine!

 

John

BA_Pete
Super User
Super User

Hi @Anonymous ,

 

You said you need a calculation to do this. Do you specifically need this done in DAX, or would a Power Query/M solution suit?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

HI @BA_Pete ,

Well, I am not an expert, but lets give it a try in Power Query/ M 😀

Thanks upfront for your help!

John

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.