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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Tom_G
Helper II
Helper II

Sum by Category Measure in a visual with no Category

Hello 

Say I have a table with three columns - Shop Name, City Name and Fruit Sold.

 

Shop Name      City Name      Fruit Sold 

Fruit Galore         Antwerp          137

Fruit Fest             London          245

Fresh Fruit            London           567

Fruit n Veg           Paris                231

Fruit House          Antwerp          668

 

I want to display the sum of Fruit Sold per City Name in a measure within a visual that also has the Shop Name in it (but NOT the City Name). There is also no City Name slicer on the tab.

 

So the visual would look like

Shop Name    Fruit Sold

Fruit Galore    805

Fruit Fest       812

Fresh Fruit      812

Fruit n Veg      231

Fruit House     805

 

This is simple if City Name is included in the visual or is slicing the visual from outside.

But what I can't work out is how to have Fruit Sold by City Name in a measure WITHOUT City Name also being in the visual or slicing the visual from outside.

 

Any help much appreciated.

2 ACCEPTED SOLUTIONS

Hi @amitchandak The below based on what you sent seems to be working, I will check in details and confirm.

Fruit Sold per City = A
verageX(Values('Table'[City]),
calculate(sum('Table'[Fruit by Shop]),
ALLEXCEPT('Table,'Table'[City],'Table'[Shop Status])))

View solution in original post

sathya_s
Frequent Visitor

Hi @Tom_G ,

 

The chief issue is that there is a row level filter on 'Shop Name'. Once we remove that, we would be able to aggregate based on 'City'. 

Give this a try!

 

FruitSoldMeasure = 
VAR city = SELECTEDVALUE(FruitSales[City Name])
RETURN CALCULATE(
                 SUM(FruitSales[Fruit Sold]), 
                 REMOVEFILTERS(FruitSales[Shop Name]), 
                 FruitSales[City Name] = city
                 )

 

sathya_s_0-1657907703630.png

 

View solution in original post

7 REPLIES 7
sathya_s
Frequent Visitor

Hi @Tom_G ,

 

The chief issue is that there is a row level filter on 'Shop Name'. Once we remove that, we would be able to aggregate based on 'City'. 

Give this a try!

 

FruitSoldMeasure = 
VAR city = SELECTEDVALUE(FruitSales[City Name])
RETURN CALCULATE(
                 SUM(FruitSales[Fruit Sold]), 
                 REMOVEFILTERS(FruitSales[Shop Name]), 
                 FruitSales[City Name] = city
                 )

 

sathya_s_0-1657907703630.png

 

Hi @sathya_s - thanks for the measure! It seems to work well. I notice there are slight changes in the behaviour of this measure vs the ALLEXCEPT one below, which relates to responsiveness of the measure to other slicers on the tab, which I didn't mention. ALLSELECTED is more responsive to those other slicers than ALLEXCEPT. I will check this in detail and let you know the result. Thanks again!

Sure @Tom_G 👍

Hi @sathya_s  I checked and in fact both the ALLSELECTED and ALLEXCEPT versions work for the problem specified. ALLSELECTED works better to have responsiveness to any other slicers on the tab, ALLEXCEPT works better if you don't want that responsiveness. So I marked both as solutions. Thanks to you and @amitchandak for the help.

amitchandak
Super User
Super User

@Tom_G , If that is sum, how is different from a visual having only shop name

 

If that avg it can make diff

 

averageX(Values(Table[City]), calculate(sum(Table[Fruit Sold])) )

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

Hi @amitchandak The below based on what you sent seems to be working, I will check in details and confirm.

Fruit Sold per City = A
verageX(Values('Table'[City]),
calculate(sum('Table'[Fruit by Shop]),
ALLEXCEPT('Table,'Table'[City],'Table'[Shop Status])))

Hi @amitchandak thanks for the response.

The measure you provided gives me the fruit sold per shop name, not the fruit sold per city on each shop line. 

This is the closest I have below, (as you can see there are a couple of other columns explained below that also feature). The below is not working correctly in some specific cases and i'm not sure why exactly. Maybe you know?

Fruit sold per city = VAR _CITY = MAX('Table'[City])

RETURN
CALCULATE(
SUM('Table'[Fruit by Shop]), /// this is a calculated column which is the sum of fruits per shop as in some cases the shops are split out into two or three lines ///
'Table'[City] = _CITY,'Table'[Shop Status] = "Open", /// a column that states whether a shop is open or not ///
REMOVEFILTERS('Table'[Shop Name])

)

 

Thanks 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors