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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
mrutherford83
Frequent Visitor

Count of Most Recent entries per case

CasecodeaddeddatePC LevelPC Level Most Recent
Casecode18 May 201911
Casecode 28 May 2019 13
Casecode 23 Oct 201923
Casecode 25 May 202033
Casecode 36 Nov 201712
Casecode 35 May 202022
Casecode 45 May 202011
Casecode 42 Feb 202021
Casecode 415 Dec 201911
Casecode 44 Nov 201911

 

I have the above table and I have tried numerous different methods but I cannot figure out how to do this in Power BI. 

 

I have figured out how to calculate the most recent entry in the "PC Level Most Recent" but the frist part of what I would like to do is add two further columns which will calculate the second and third most recent entries. 

 

Then what I want to do is provide a summary and outline how many 'cases' are in 1, 2 and 3 currently, and then what level they were at and the entry prior and then the third prior entry so something like this: -

 

PC LevelCurrentPriorThird Prior
1258
2134
3123

 

Please note the data in this table does not relate to the above but basically what I want to see if the movement between the count entry on entry.

 

Hopefully that makes sense, any help is greatly appreciated

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @mrutherford83 

I'm not clear how to calculate the "PC Level Most Recent".

Is it the last date "PC Level" based on every casecode?

Could you give a sample with corresponding result?

 

Best Regards

Maggie

 

Hi @v-juanli-msft 

 

Thanks for your reply.

 

Here is an extract from the actual table itself: -

 

casecodeadddatePC LevelPC Level Most Recent
Casecode 108-May-1911
Casecode 208-May-1911
Casecode 203-Oct-1911
Casecode 305-May-2011
casecode 405-May-2011
casecode 406-Nov-1711
Casecode 512-Dec-1812
Casecode 519-Dec-1822
Casecode 613-May-2011
Casecode 606-Dec-1711
Casecode 720-May-2022
Casecode 824-Feb-2022
Casecode 827-Mar-1912
Casecode 813-Mar-1922
Casecode 810-Apr-1922
Casecode 917-Oct-1922
Casecode 907-Oct-1912

 

and this is the code I used to create the PC Level Most Recent colmun that I added:-

 

PC Level Most Recent = CALCULATE( MAX( Notes[PC Level]), FILTER( Notes,Notes[casecode]=EARLIER(Notes[casecode])))
 
Does that help at all?

So your current column is just getting the maxium level within a casecode, it's not looking at the addeddate at all. If I understand what you want to do I think you need to lookup the max date for a given casecode, then find the score for that and do this for the 2 prior addeddate values within a given casecode. If this is correct then I think the following measure might work. It's maybe a little more complex than it needs to be, but I've set it up so you just need to change the value of the _priorNumber to go back 2,3,4 etc dates

 

Prior 1 = 
var _priorNumber = 1
// store the casecode for the current row
var _currentCase = 'Table'[Casecode]
// get all the dates for this casecode
var _allDates = SELECTCOLUMNS(filter(ALL('Table'), 'Table'[Casecode] = _currentCase),"addeddate",[addeddate])
// Get the min date within the topN
var _recentDate = MINX(TOPN(_priorNumber,_allDates,[addeddate],DESC),[addeddate])
// lookup the level for this date and cosecode
var _result = LOOKUPVALUE('Table'[PC Level],'Table'[addeddate],_recentDate,'Table'[Casecode],_currentCase)
return if(countrows(_allDates) >= _priorNumber, _result)

 

You can see this working in the screenshot below (note I added some data to your example so I could see in casecode2 that it was not just grabbing the levels in numeric order)

 

2020-05 prior levels.png

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.