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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ant_lah
Frequent Visitor

Aggregating values based on slicer selection

Hello,

 

Been banging my head on an issue for a while now, and I'm new enough that I struggle to put it concisely (and hence search effectively).

I am trying to build a dashboard where a user can select multiple agriculture-related datapoints, input cut-off ranges, and see a map of states/districts in India that satisfy the chosen conditions. The simplest way to do that would be to have a dataset with 1 row per district, and one column per data point (e.g., number of wholly owned farms). But that radically flattens the origin data, where the number of farms owned is broken down by the size of farms:

 

State        District        Farm size       number of farms owned
state 1  district 1 small30
state 1  district 1medium 50
state 1district 1large

20

state 1district 2small

11

state 1district 2medium

24

state 1district 2large

70

 

(in reality, I have 5 size categories and 8 datapoints of interest for just this part of the data).

 

What I want to get, based on slicer selection:

When "small" and "medium" are selected, I need the new column to sum just the small and medium farm numbers:

State    District    Farm size    number of farms owned    Sum by size
state 1  district 1 small3080
state 1  district 1medium 5080
state 1district 1large

20

80
state 1district 2small

11

35
state 1district 2medium

24

35
state 1district 2large

70

35

 

When large is selected, I'll need just the large values summed:

State    District    Farm size    number of farms owned    Sum by size
state 1  district 1 small3020
state 1  district 1medium 5020
state 1district 1large

20

20
state 1district 2small

11

70
state 1district 2medium

24

70
state 1district 2large

70

70

 

If I use the 'number of farms owned' column directly, then a slicer that filters values in the 'number of famrs owned' columns based on farm size works fine with a single selection, but on a multiple selection it will use one of the separate values rather than combining the values. I know how to do a groupby/summarize statement that will get me a sum per district over all farm sizes, but I have not been able to make that responsive to a slicer selection of farm sizes: I want to be able to specify, say, small + medium farm sizes and get a per-district sum of just those.

 

The closest I've got is a measure

 

number owned sum selected categories = 
CALCULATE(
    SUM(C_Farms[number owned]),
    ALLSELECTED(C_Farms[O_Farms_Farm size categories]))

 

That does what I want to get within a table visual, but I can't drop it onto a slicer, and if I create a column in the table with the same statement, it stops responding to the slicer selection.

 

Is there a way to do this?

 

Link to my dashboard:

shared.pbix

 

Thank you all so much!

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

Based on the table that you have shared, show the expected result very clearly.


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

Good point--edited the original post with examples. Thanks!

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1739144372810.png

 


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

Hi,

The measure does exactly what I want within the table visual (as does the measure I listed in the post), but I can't find a way to use it outside the table visual--specifically, I need to use the dynamically calculated number of farms owned in a "between" slicer that will control which districts are higlighted on a filled map (that is, districts where the sum of farms owned falls between the minimum-maximum numbers specified in the slicer).

 

If I understand correctly, to make that work, the dynamic sum needs to be a table column rather than a measure--or can a measure be used independently in a slicer?

 

Thank you so much for your help!

Anton

You are welcome.  It loks like your ultimate objective is to create a slicer of the "Sum by size" column.  Do you want the slicer to have individual figures or buckets i.e. 0-20, 21-40 etc?  If you want buckets, then please specify what those buckets should be?


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

Hi Ashish Mathur,

I am looking for a slicer on individual figures, pretty much what I have on the screenshot below, but with the option to specify which size category farms should be considered for selection.

ant_lah_0-1739365451818.png

Thanks again,

Anton

danextian
Super User
Super User

Hi @ant_lah 

Try the following:

farms by district and state = 
CALCULATE (
    SUM ( 'Table'[number of farms owned] ),
    ALLEXCEPT ( 'Table', 'Table'[District], 'Table'[state] )
)

 

danextian_0-1738941918434.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian ,

Your proposal correctly sums the values over state and district, but it sums all of the size categories regardless of which of them I have selected in a slicer. Am I missing something?

 

Thanks!

Anton

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.