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
Anonymous
Not applicable

Count Max Sale by User

Hey There Community!

I realize this is probably not a complex calculation but the solution is escaping me. I need to count the rows/records by user_id that contain the max id. So in the image below I would want to return a count of the 3 highlighted rows. I've tried various filter and max combinations on the user_id but can't seem to get it right. 

 

2020-01-23_6-14-59.png

1 ACCEPTED SOLUTION

Ah ok I didn't understood that you wanted to have more information than just the counts of max ID's per User_id in your visual. In that case, add a calculated column to your table like this:

 

IsMaxIDforUserID = 
VAR _curID = 'User Group Sales'[id]
VAR _curUserID = 'User Group Sales'[user_id]
RETURN IF(MAXX(FILTER('User Group Sales', 'User Group Sales'[user_id] = _curUserID), [id]) = _curID, TRUE, FALSE) 

 

Then, add that column to the visual filter and filter for True. The column indicates if the current row contains the maximum id for the current userID. 

Result is this:

image.png

Your PBIX updated is here:

https://1drv.ms/u/s!Ancq8HFZYL_aiIw3_VDuajJWrCu52w?e=qNrx0g

 

Please don't forget to like posts that helped you and mark it as the solution if it answered your question. This will help others to find the answers quikcly as well if searching for similar problems 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

 

Fun question. Please note that in order for us to help you quickly, don't post pictures of tables but rather the tables (or files) them selves. If you post pictures, we need to recreate the data.

For this I created a very simple mock up data set:

image.png

The outcome of the above woulde be

A2
B1

A = 2 because we have 2 times the id of 2 (row 3 and 4). B=1 because we have one time ID 4 (row 8). This is the logic i draw from your post, that is correct?

This measure makes that happening (when used in a table visual!):

Measure = 
VAR _curUserID = SELECTEDVALUE(Table3[user_id])
VAR _curUserIdMaxID = MAXX(FILTER(Table3, Table3[user_id] = _curUserID), [id])
RETURN
COUNTROWS(FILTER(Table3, Table3[user_id] = _curUserID && Table3[id] = _curUserIdMaxID))

The result is this:

image.png

The PBIX might be downloaded here (table3, page2, ignore the rest in the file as it answers other questions :))

https://1drv.ms/u/s!Ancq8HFZYL_aiItDUonqIklYNkn7Nw?e=lKuyLA

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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

Proud to be a Super User!




Anonymous
Not applicable

@JarroVGIT - that was a nice solution. I'd considered a calculated column but for the same reason just couldn't get the syntax right. Thank you!

Anonymous
Not applicable

Hi @JarroVGIT thanks for the advice. I don't normally post so it never occured to me to supply a PBIX. I updated the one you sent with a sample from my actual table. 

What I'm actually looking for in the measure results is for 1 to be returned for user_id A, which would be the row with the highest id. 

 

So below, the measure New Contracts would return a total of 3. The rows for each user with lower id's would be filtered out. 

 

2020-01-23_12-46-44.png

https://1drv.ms/u/s!Aiu-grSaGsWrbjkRftSCDdvkUfc?e=EYSfpo 

Ah ok I didn't understood that you wanted to have more information than just the counts of max ID's per User_id in your visual. In that case, add a calculated column to your table like this:

 

IsMaxIDforUserID = 
VAR _curID = 'User Group Sales'[id]
VAR _curUserID = 'User Group Sales'[user_id]
RETURN IF(MAXX(FILTER('User Group Sales', 'User Group Sales'[user_id] = _curUserID), [id]) = _curID, TRUE, FALSE) 

 

Then, add that column to the visual filter and filter for True. The column indicates if the current row contains the maximum id for the current userID. 

Result is this:

image.png

Your PBIX updated is here:

https://1drv.ms/u/s!Ancq8HFZYL_aiIw3_VDuajJWrCu52w?e=qNrx0g

 

Please don't forget to like posts that helped you and mark it as the solution if it answered your question. This will help others to find the answers quikcly as well if searching for similar problems 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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.