Showing results for 
Search instead for 
Did you mean: 
topkatt Frequent Visitor
Frequent Visitor

Dynamically Grouping by ID while Filtering by Date

So I promise I've done my best combing through these forums looking for an aswer to my question, but haven't been able to find a resolution that fits my data.


What I Have

I've got a table 'Table' with three relevant fields: [ID], [Type], and [Date]. There are other fields I'm interested in analyzing, but my problem can be solved just discussing these three. Example below.







In my report, I have a date slicer, though it is coming from a seperate table 'DateTable', which has a single column [JustDate] of distinct dates (not times) from 'Table'[Date]. Example below.




It's important to note that 'DateTable' is NOT linked to 'Table'


What I'm Trying To Do

I need to create several metrics based on the last row of each [ID] for which the [Date] is earlier than the currently selected 'DateTable'[JustDate]. I.e. I'd like to create a new table 'NewTable' that has gone through the following steps:


1. Filter 'Table' to only records for which 'Table'[Date] < 'DateTable'[JustDate]

2. Group by [ID], keeping the row with the latest [Date].


For example, if the slicer for 'DateTable'[JustDate] were set to 5/1/2018, 'NewTable' would look like this:






What I've Tried

Basically everything I've seen on these forums, save for what appears to be super-advanced work arounds (I'm fairly new to Power BI).


The method that makes the most sense intuituvely is to create 'NewTable' such that


'NewTable' = FILTER(ALL('Table'), 'Table'[Date} < SELECTEDVALUE('DateTable'[JustDate]))


and then proceed to Group By, but I haven't even been able to get the above to produce any data. I've tried several variations of the above approach, as well as a few others I've seen around these forums. Any help is appreciated.



Seward12533 New Contributor
New Contributor

Re: Dynamically Grouping by ID while Filtering by Date

Hi, can you post your sample data as a table or link to a demo workbook?  I'm thinking this should work


NewTable = VAR Just_Date = MAX(JustDate[Date])  RETURN



If you struggle with this approach you can create a table of the unique ID number and the MAX Date

NewTable = SUMMARIZE(fact[ID],"Date",CALCULATE(MAX(fact[Date]),Filter(fact,Fact[Date]<=MAX(JustDate[Date]))))

Then you could use LOOKUPVALUE to extract the value to TYPE, OTher, VARS etc based on ID and DATE .  While not very efficiecnt its easier conceptually. 


topkatt Frequent Visitor
Frequent Visitor

Re: Dynamically Grouping by ID while Filtering by Date

Sorry about the data, I've attempted to include it below.


I'm trying your propsed solutions now, will update shortly.






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