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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Roym
Helper IV
Helper IV

Show/Count highest ID if

I have an Excel table like the one show below. Per name you have different ID's, Status, and Month. In my PowerBI table I need to show/count the highest ID, but only if the previous one is either Effective or Ineffective. So in the below example the highest ID that is not Effective or Ineffective is ID#2 from February as it is Overdue. So that one should be shows/counted in my table. Hopefully someone can help me a bit in the right direction that I need to look for to achieve this.

 

IDNameStatusMonth
4Issue1OpenJuly
3Issue1OpenMarch
2Issue1OverdueFebruary
1Issue1EffectiveJanuary
3 ACCEPTED SOLUTIONS

@Roym

pls try this

Column = 
VAR _id=maxx(FILTER('Table',('Table'[Status]="Effectvie"||'Table'[Status]="Ineffective")&&'Table'[ID]<>CALCULATE(max('Table'[ID]),ALLEXCEPT('Table','Table'[Name]))),'Table'[ID])
return if('Table'[ID]=_id+1,"highest value")

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

@Roym 

one thing want to be mentioned. if you have other issues, you need to modify the DAX

 

Column = 
VAR _id=maxx(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&('Table'[Status]="Effective"||'Table'[Status]="Ineffective")&&'Table'[ID]<>CALCULATE(max('Table'[ID]),ALLEXCEPT('Table','Table'[Name]))),'Table'[ID])
return if('Table'[ID]=_id+1,"highest value")

 

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

@Roym 

pls try this

Column = 
VAR _id=MAXX(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&('Table'[Status]="Effective"||'Table'[Status]="Ineffective")),'Table'[ID])
VAR _status=maxx(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[ID]=_id+1),'Table'[Status])
VAR _status2=maxx(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[ID]=_id),'Table'[Status])
return if(ISBLANK(_id),if('Table'[ID]=CALCULATE(max('Table'[ID]),ALLEXCEPT('Table','Table'[Name])),"Highest ID"),if(_status=""&&_id='Table'[ID],"Highest ID",if((_status="Overdue"||_status="Open")&&_id='Table'[ID]&&'Table'[Status]="Ineffective","Highest ID",if(_status2<>"Ineffective"&&'Table'[ID]=_id+1,"Highest ID"))))

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

13 REPLIES 13
ryan_mayu
Super User
Super User

@Roym 

here is a workaround for you

Column = 
var staus=maxx(FILTER('Table (2)','Table (2)'[Name]=EARLIER('Table (2)'[Name])&&'Table (2)'[ID]=EARLIER('Table (2)'[ID])-1),'Table (2)'[Status])
return if(staus="Effective"||staus="Ineffective","Highest ID")

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




First of all, thanks for the help/effort!!! 

 

I tried it and with the data example as I posted, it works. But once I added some additional data it is not fully working. It shows two rows that match the criteria, but it should only show per issue one result. Is that possible to do?

 

Capture.PNG

@Roym

pls try this

Column = 
VAR _id=maxx(FILTER('Table',('Table'[Status]="Effectvie"||'Table'[Status]="Ineffective")&&'Table'[ID]<>CALCULATE(max('Table'[ID]),ALLEXCEPT('Table','Table'[Name]))),'Table'[ID])
return if('Table'[ID]=_id+1,"highest value")

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




When working with the calculation I found out I have one question remaining. Hopefully someone can assist me with this last item. So the code from Ryan is working perfectly. Only I have one exception. If an issue (in the example below issue1) has ineffective, and then open/overdue it should mark the ineffective as highest value. What I tried is adjusting the code by removing '||'Table'[Status]="Ineffective"'.  This works for issue1, but then for issue2 in the example it doesn't give a highest value, they are all empty. Any idea how I can get this working?

 

Issue16OverdueHighest value
Issue15Ineffective 
Issue14Effective 
Issue23IneffectiveHighest value
Issue22Ineffective 
Issue21Ineffective 

 

@Roym 

pls try this

Column = 
VAR _id=maxx(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&('Table'[Status]="Effective"||'Table'[Status]="Ineffective")&&'Table'[ID]<>CALCULATE(max('Table'[ID]),ALLEXCEPT('Table','Table'[Name]))),'Table'[ID])
VAR _staus=maxx(FILTER('Table','Table'[ID]=_id),'Table'[Status])
return if((_staus="Ineffective"&&'Table'[ID]=_id)||(_staus="Effective"&&'Table'[ID]=_id+1),"Highest ID")

2.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




thanks again for the support! I tried it and it not fully working correctly yet. The old code was working correcly, except that in this case of the below 'issue0' it would mark the 'overdue' one instead of the 'ineffective'. The rest worked perfectly. Any idea how I can get to that?

 

 

Capture.PNG

@Roym 

pls try this

Column = 
VAR _id=MAXX(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&('Table'[Status]="Effective"||'Table'[Status]="Ineffective")),'Table'[ID])
VAR _status=maxx(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[ID]=_id+1),'Table'[Status])
VAR _status2=maxx(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&'Table'[ID]=_id),'Table'[Status])
return if(ISBLANK(_id),if('Table'[ID]=CALCULATE(max('Table'[ID]),ALLEXCEPT('Table','Table'[Name])),"Highest ID"),if(_status=""&&_id='Table'[ID],"Highest ID",if((_status="Overdue"||_status="Open")&&_id='Table'[ID]&&'Table'[Status]="Ineffective","Highest ID",if(_status2<>"Ineffective"&&'Table'[ID]=_id+1,"Highest ID"))))

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Awesome! This works perfectly! Thanks again for all the help!!!!

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Awesome! you are the man. Thanks for the help!!!

@Roym 

one thing want to be mentioned. if you have other issues, you need to modify the DAX

 

Column = 
VAR _id=maxx(FILTER('Table','Table'[Name]=EARLIER('Table'[Name])&&('Table'[Status]="Effective"||'Table'[Status]="Ineffective")&&'Table'[ID]<>CALCULATE(max('Table'[ID]),ALLEXCEPT('Table','Table'[Name]))),'Table'[ID])
return if('Table'[ID]=_id+1,"highest value")

 

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I was just trying to that 🙂 Again, really appreciate the help!!

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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