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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
bathbath
Regular 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.