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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
bathbath
Frequent Visitor

How to get latest record for appointment ID

bathbath_0-1692121080536.png

 

How do I get the latest record for the Appointment_ID. For e.g., in this situation, I should only see the last record based on the latest insert date time.

 

Basically something like: for an appointment ID, show me the row for latest insert date.

 

Thanks in advance,

RK

 

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @bathbath ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1692342105159.png

(2) We can create a measure. 

Flag = 
var _lasttime=CALCULATE(MAX('Table'[edwlnsert_DateTime]),FILTER(ALL('Table'),'Table'[Appoint_ID]=MAX('Table'[Appoint_ID])))
return IF(MAX('Table'[edwlnsert_DateTime])=_lasttime,1,0)

(3) Place measure [Flag]= 1 on the screening of visual objects.

vtangjiemsft_1-1692342712365.png

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

4 REPLIES 4
v-tangjie-msft
Community Support
Community Support

Hi @bathbath ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1692342105159.png

(2) We can create a measure. 

Flag = 
var _lasttime=CALCULATE(MAX('Table'[edwlnsert_DateTime]),FILTER(ALL('Table'),'Table'[Appoint_ID]=MAX('Table'[Appoint_ID])))
return IF(MAX('Table'[edwlnsert_DateTime])=_lasttime,1,0)

(3) Place measure [Flag]= 1 on the screening of visual objects.

vtangjiemsft_1-1692342712365.png

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

miTutorials
Super User
Super User

Alef_Ricardo_
Resolver II
Resolver II

You can use a subquery to get the latest record for each Appointment_ID based on the insert date time. Here’s an example of how you can do this:

 

SQL

SELECT t.Appointment_ID, t.insert_date_time, t.other_columns
FROM your_table t
INNER JOIN (
SELECT Appointment_ID, MAX(insert_date_time) AS latest_date
FROM your_table
GROUP BY Appointment_ID
) subq
ON t.Appointment_ID = subq.Appointment_ID AND t.insert_date_time = subq.latest_date
In this example, the subquery selects the maximum insert date time for each Appointment_ID and groups the results by Appointment_ID. The main query then joins the subquery with the original table on both the Appointment_ID and the insert date time to get the latest record for each Appointment_ID.

 

I hope this helps! Let me know if you have any further questions. 😊

Thanks Alef for the quick reply but I want to do it via a Power Query or with help of DAX as I don't have access to the SQL piece - The data is coming via dataflow. 

 

Thanks!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.