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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
diegomengue
Frequent Visitor

How to set a filter based on max value of each category

Hello.

I have a small sales dataset with date, salesman, quantity and customer, a related data table and another related table with my customers data (name, category - as in market, gas station, hotels, etc., location, etc.).

I want my end user to be able to select a date period (with a date slicer) and be able to find, for each category, which customer is the best buyer. For example: between 20 markets, 15 gas stations and 10 hotels, I need to know that the best ones aremarket A,  who sold 100 units, gas station B who sold 80 units and hotel C who sold 3 units in that time frame...

 

I also need to use those categories max values to evaluate if another same-category customer is doing good or not: in that same example, if market A has sold 100 units but market Y has sold 50 (some fixed parameter, like less than 70% max), then he is doing bad in that period.

Is it possible?

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@diegomengue , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

You can create a measure like

rankx(filter(allselected(Table[customer], table[category]), table[category] =max(table[category])), [sales])

 

and filter Rank =1

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

https://www.youtube.com/watch?v=DZb_6j6WuZ0
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Example:

Sales table:

DateCustomerQuantity
01/01/2021A12
01/01/2021B15
02/01/2021A5
02/01/2021C8
03/01/2021D4
04/01/2021B10
04/01/2021D6

 

Customer table:

ACategory 1
BCategory 1
CCategory 2
DCategory 2

 

So what I want to know is, for period 01/01/2021 - 04/01/2021

Category 1Customer B (25 units)
Category 2Customer D (10 units)

 

I want to know which customer is the most buying one for each category, and I also would like to filter with this number... so, for example: for Category 2, I would like to see which clients had Total Units Sold <= (0.7 * Customer D sum).

Thanks @amitchandak .

 

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

It worked, thank you!!!

I'd also like to use this "25" to rank the other customers on category 1.: if customer B is my best customer on Category 1, it equals 100%... I want to know the percentage of B my other customers represent.

So, if I have for category 1, for example:

Customer A - 10

Customer B - 25

Customer C - 15

 

I'd like to be able to see
Customer B - 100%
Customer C - 60%
Customer A - 40%

Is it possible?

You are welcome.  I do not understand your requirement.


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

@diegomenguecreate 3 measures

 

sales := SUMX(sales,sales[Quantity])
running total:= 
VAR _1 = MAX(sales[Date])
VAR _2 = CALCULATE([sales],ALL(sales[Date]),sales[Date]<=_1)
RETURN _2
Rank:= RANKX(ALLSELECTED(sales[Customer]),[running total],,DESC)

 

 

and use them like following

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@diegomenguedid you try the above ?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors