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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kiwicam
Helper I
Helper I

Count and Rank by Specific Time Period when Filtering Certain Data

Hi,

 

I am hoping someone can please help me solve the following issue.

I am trying to count and rank the shops (Shops 1 to 😎 that sell a specific product (Product1) over a specific period (daily, weekly, monthly, etc.).

In addition, I have a limitation on what data I can share with each shop.

I can share the shop's own total sales, own rank, and the total count of shops, but I cannot share the total sales of other shops.

Initially I will be sharing the report via PDF, so I am using the slicer to filter by shop.

Please see the following sample.

kiwicam_0-1612352679198.png

I am using the following measures and initially the result looks fine.

  • Total Sales = SUM(sample_data[Sales])
  • Shop Count = CALCULATE(DISTINCTCOUNTNOBLANK(sample_data[Shop]), ALLEXCEPT(sample_data, sample_data[Product]))
  • Shop Rank = RANKX(ALL(sample_data[Shop]), [Total Sales])
However, some shops do not sell the product in some periods and they are being erroneously included in the count/rank for that period.
Please see the following example where on 11-Jan, only 7 shops sold the product.
sample.png

 

How should I update my measures to get the correct result?

 

Thank you in advance for your help!

1 ACCEPTED SOLUTION

Ok, so this was solved by changing "ALLSELECTED" to "ALL".

 

Before

Shop Count = CALCULATE(DISTINCTCOUNTNOBLANK(sample_data[Shop]), ALLSELECTED(sample_data[Shop]))

 

After

Shop Count = CALCULATE(DISTINCTCOUNTNOBLANK(sample_data[Shop]), ALL(sample_data[Shop]))
 
solution.jpg
 
Thank you everyone for your help!

View solution in original post

6 REPLIES 6
mahoneypat
Microsoft Employee
Microsoft Employee

Please try these expressions instead

 

Shop Count = CALCULATE(DISTINCTCOUNTNOBLANK(sample_data[Shop]), ALLSELECTED(sample_data[Shop]))

 

Shop Rank = RANKX(ALLNOBLANKROW(sample_data[Shop]), [Total Sales])

or

Shop Rank = var v1 = RANKX(ALL(sample_data[Shop]), [Total Sales])
return IF(ISBLANK([Total Sales]), BLANK(), v1)

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat,

Thanks for the super quick response!!

Shop Count is perfect.

On shop rank the first suggestion produces a rank of 8 when there are only 7 shops.

I could work with this, but your second suggestion works a charm so I will use that.

Thank you again for your help!

Hi Pat,

Sorry, I spoke too soon.

The shop count solution works when I don't apply the Shop Slicer.

For example the shop count is 7 and 8 respectively in the image below.

image1.png

However, when I apply the shop slicer so the shop can only see their own volume, the shop count becomes 1 (see below).

I need this to remain as 7 and 8 respectively.

image2.png

I don't suppose you have any further thoughts on how I can solve this?

Thank you in advance!

 

Ok, so this was solved by changing "ALLSELECTED" to "ALL".

 

Before

Shop Count = CALCULATE(DISTINCTCOUNTNOBLANK(sample_data[Shop]), ALLSELECTED(sample_data[Shop]))

 

After

Shop Count = CALCULATE(DISTINCTCOUNTNOBLANK(sample_data[Shop]), ALL(sample_data[Shop]))
 
solution.jpg
 
Thank you everyone for your help!
amitchandak
Super User
Super User

@kiwicam , Try like

Shop Rank = RANKX(filter(ALLselected(sample_data[Shop],sample_data[Date]),sample_data[Date] =max(sample_data[Date])) , [Total Sales])

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

Thanks amitchandak!

I really appreciate the help and quick response!

Unfortunately, your suggestion also ranks shops with no volume as "1"  (alongside the top ranked shop).

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.