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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
pbi_user_47
New Member

minimum distance of a customer then aggregated to show how many customers fall in each bucket

first timer. I am trying to do what feels like a simple aggregation. I have a list of customers and their distance to candy stores. I want to summarize the number of customers by their distance to the closest store. 

 

pbi_user_47_0-1757096736769.png

 

in SQL it looks like this: 

select
  closest_store
  ,COUNT(DISTINCT customerID) AS customers
from (select
        customerID,
        min(dist_miles_bins) as closest_store
      from table1
      where
        store_item_type = 'CANDY'
        and store_name IN ('candystore','sugarrush')
      group by all
    ) a
 group by all
 order by closest_store
 
My problem is that when I go to plot this in a clustered bar graph I cannot get the axis to show the closest_store on the x-axis and the distinct count of customers on the Y-axis. please help and show me how I am missing a simple one line solution. thank you.
1 ACCEPTED SOLUTION
MarkLaf
Super User
Super User

A measure solution.

 

Cust Count by Min Miles = 
VAR _milesInFilterContext = VALUES( Table1[Miles Away] )
RETURN
COUNTX( 
    VALUES( Table1[customerID] ), 
    VAR _minMileByCust = CALCULATE( MIN( Table1[Miles Away] ), ALL( Table1[Miles Away] ) )
    RETURN
    IF( _minMileByCust IN _milesInFilterContext, 0 )
)

 

MarkLaf_3-1757107637887.png

 

Formatting: continuous x-axis with title/value labels off + custom format data labels

 

 

View solution in original post

2 REPLIES 2
MarkLaf
Super User
Super User

A measure solution.

 

Cust Count by Min Miles = 
VAR _milesInFilterContext = VALUES( Table1[Miles Away] )
RETURN
COUNTX( 
    VALUES( Table1[customerID] ), 
    VAR _minMileByCust = CALCULATE( MIN( Table1[Miles Away] ), ALL( Table1[Miles Away] ) )
    RETURN
    IF( _minMileByCust IN _milesInFilterContext, 0 )
)

 

MarkLaf_3-1757107637887.png

 

Formatting: continuous x-axis with title/value labels off + custom format data labels

 

 

YEP. SAVED MY WEEKEND. TYFYS MARK.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

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.