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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
charleshale
Continued Contributor
Continued Contributor

Totalling selected values

Let's say I have a table named FRUIT that looks like this:

 

TYPE    QUANTITY

Bananas   2

Oranges   3

Kiwi          4

 

My goal is to Sum only Bananas and Oranges and have those sums show only when they are selected in a visual filter.   No problem!   All I have to do is write the following measure:

 

FruitSum =
VAR _Sum =
    CALCULATE ( SUM ( Fruit[Quantity] ) )
RETURN
    IF ( SELECTEDVALUE ( Fruit[Type] IN { "Bananas", "Oranges" } ), _Sum, BLANK () )

 

This works....but there is a catch:    I can't get the Total to show in a matrix visual (or any other way).

 

In other words, if I have a filter on the visual that shows only Bananas and Oranges, I get 

 

Bananas   2

Oranges   3

Total      

 

However what I would like is to show the total....

Bananas   2

Oranges   3

Total      5

 

Note - this outcome would be acceptable too

Bananas   2

Oranges   3
Kiwis       4 

Total      5

 

Thoughts on how to code?   Thank you!

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Jihwan_Kim_0-1666759386023.png

 

 

expected measure one: = 
CALCULATE (
    SUM ( Fruit[Quantity] ),
    KEEPFILTERS ( Fruit[Type] IN { "Bananas", "Oranges" } )
)

 

expected measure two: = 
IF (
    HASONEVALUE ( Fruit[Type] ),
    SUM ( Fruit[Quantity] ),
    CALCULATE (
        SUM ( Fruit[Quantity] ),
        KEEPFILTERS ( Fruit[Type] IN { "Bananas", "Oranges" } )
    )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Jihwan_Kim_0-1666759386023.png

 

 

expected measure one: = 
CALCULATE (
    SUM ( Fruit[Quantity] ),
    KEEPFILTERS ( Fruit[Type] IN { "Bananas", "Oranges" } )
)

 

expected measure two: = 
IF (
    HASONEVALUE ( Fruit[Type] ),
    SUM ( Fruit[Quantity] ),
    CALCULATE (
        SUM ( Fruit[Quantity] ),
        KEEPFILTERS ( Fruit[Type] IN { "Bananas", "Oranges" } )
    )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

@jiwhan_Kim

Perfect - you are a dax genius!  Kudos!

raimon
Resolver II
Resolver II

Hi @charleshale

 

Not sure if I understood properly. Since if you are selecting values in the visual filter, that should automatically filter down the sum of values. 

 

However try this - 

1. Create a list that will return all values selected - 

List = CONCATENATEX(values('Fruit'[TYPE]),'Fruit'[TYPE],",")
 
2. Create a measure for the totals- 
Total = CALCULATE(SUM('Fruit'[QUANTITY]),FILTER('Fruit','Fruit'[TYPE] in {[List]}))
 
Let me know if this is what you are after. 

 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.