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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
topkatt
Frequent Visitor

Dynamically Retrieve Last Observation per ID

Hi All,

 

I'm trying to create a table that has the last observation for each ID in my data, relative to the current value in a date slicer.

 

Sample data below, thanks for your help!

 

 

IDTypeDateOtherVars
23CREATED10/23/2017 7:39:30 AMFunData
23UPDATED12/28/2017 9:23:01 PMFunData
23DELIVERED5/18/2018 4:27:10 PMFunData
32CREATED10/31/2017 10:56:25 AMFunData
32UPDATED12/31/2017 9:10:58 PMFunData
32DELIVERED6/16/2018 4:26:31 PMFunData
71CREATED5/22/2018 4:14:09 PMFunData
71CANCELED5/22/2018 5:19:00 PMFunData
217CREATED11/29/2017 7:41:00 AMFunData
217UPDATED12/28/2017 9:23:01 PMFunData
217DELIVERED5/19/2018 4:27:45 PMFunData
227CREATED12/15/2017 8:02:19 AMFunData
227RESCHEDULED12/21/2017 8:42:59 PMFunData
227UPDATED12/28/2017 9:27:24 PMFunData
227RESCHEDULED1/16/2018 1:50:29 PMFunData
227UPDATED1/17/2018 1:36:26 PMFunData
227DELIVERED4/6/2018 2:03:02 PMFunData
227CREATED10/18/2017 8:16:00 AMFunData
227UPDATED12/28/2017 9:45:29 PMFunData
227RESCHEDULED1/1/2018 4:40:54 PMFunData
227UPDATED1/3/2018 6:05:40 AMFunData
227DELIVERED4/6/2018 1:57:48 PMFunData
11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi,

 

What result are you expecting?


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


@Ashish_Mathur wrote:

Hi,

 

What result are you expecting?


 

As an example, if I were to have the date slicer set to 5/15/2018, I would expect the data in my original post to look like this:

IDTypeDateOtherVars
23UPDATED12/28/2017 9:23:01 PMFunData
32UPDATED12/31/2017 9:10:58 PMFunData
217UPDATED12/28/2017 9:23:01 PMFunData
227DELIVERED4/6/2018 2:03:02 PMFunData

 

Hi,

 

I believe this is the result you want.  You may download the file from here.

 

Hope this helps.

 

Untitled.png


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


@Ashish_Mathur wrote:

Hi,

 

I believe this is the result you want.  You may download the file from here.

 

Hope this helps.

 

Untitled.png



Thank you! This is what I was looking for, though I have one final wrinkle:

 

Suppose that there are two rows with the same ID and matching Date, but have different Type. This creates an error when calculating [Type at datevalue]. I'd like to alter the formulas for [Type at datevalue], [Others at datevalue] and [Vars at datevalue] so that they return only a single value for each ID, preferably the value with the highest row number for a given combination of ID and Date.

 

I've reposted the data below, adding two lines for ID 32 that create the above conflict.

 

IDTypeDateOtherVars
23CREATED10/23/17 7:39 AMFunData
23UPDATED12/28/17 9:23 PMFunData
23DELIVERED5/18/18 4:27 PMFunData
32CREATED10/31/17 10:56 AMFunData
32CANCELED11/15/17 1:27 PMFunData
32CREATED12/31/17 9:10 PMFunData
32UPDATED12/31/17 9:10 PMFunData
32DELIVERED6/16/18 4:26 PMFunData
71CREATED5/22/18 4:14 PMFunData
71CANCELED5/22/18 5:19 PMFunData
217CREATED11/29/17 7:41 AMFunData
217UPDATED12/28/17 9:23 PMFunData
217DELIVERED5/19/18 4:27 PMFunData
227CREATED12/15/17 8:02 AMFunData
227RESCHEDULED12/21/17 8:42 PMFunData
227UPDATED12/28/17 9:27 PMFunData
227RESCHEDULED1/16/18 1:50 PMFunData
227UPDATED1/17/18 1:36 PMFunData
227DELIVERED4/6/18 2:03 PMFunData
227CREATED10/18/17 8:16 AMFunData
227UPDATED12/28/17 9:45 PMFunData
227RESCHEDULED1/1/18 4:40 PMFunData
227UPDATED1/3/18 6:05 AMFunData
227DELIVERED4/6/18 1:57 PMFunData

 

In this case, keeping the same cutoff date of 5/15/2018, my expected result would be:

 

IDTypeDateOtherVars
23UPDATED12/28/17 9:23 PMFunData
32UPDATED12/31/17 9:10 PMFunData
217UPDATED12/28/17 9:23 PMFunData
227DELIVERED4/6/18 2:03 PMFunData

 

Thanks for your help.

Hi,

 

You may download my PBI file from here.  i have changed some data there to verify.

 

Hope this helps.


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


@Ashish_Mathur wrote:

Hi,

 

You may download my PBI file from here.  i have changed some data there to verify.

 

Hope this helps.


 

Thank you so much for your help with this, though I have one additional question. Your solution is perfect for creating a visualization of the table I'm describing, but what If I want to make a visualization of the data in that table? I'm having trouble creating a table with this data that I can then use in other visualizations?

Hi,

 

I will not be able to help with that.


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


@Ashish_Mathur wrote:

Hi,

 

I will not be able to help with that.


 

Thanks for the feedback. Do you think this is something that isn't possible using Power BI? I'm wondering if my search for a solution is in vain.

For this you want a disconnected slicer to harvest the date value for the target date. You can due this by usins the VALUES function to create a table (NEW TABLE form the modeling tab) DateSelection = VALUES(date[date]) but don't relate it to other tables in you  model. thenuse SELECTEDVALUE in a measure to harvest the user choice or define a default (would recommend MAX date from your fact table.  SELECTEDDATE = SELECTEDVALIUE(DateSelection[DATE},MAX(table[Date])

 

Then  add a column to that compare the date of the row to the SELECTEDDATE and then use the Matrix/Table visual filters to only include the rows where the check column you  added is true.

Seward12533
Solution Sage
Solution Sage

If you search through the forums this question is asked repeatedly. you need to use a caluclated COLUMN with Earlier


@Seward12533 wrote:

If you search through the forums this question is asked repeatedly. you need to use a caluclated COLUMN with Earlier


 

I honestly have combed through these forums, and have found similar questions but none that seem to answer this specific issue. If you happen to know of one, do you mind pointing me to it?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.