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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Banistas
Helper I
Helper I

Create measure excluding current selection

Hi,

 

I want to create a measure that will make a calculation excluding the current selection from it.

 

Easier to explain with a simple example, so here I go. 

 

Let's assume I have the following data table:

Persons

Number of Pets

Lucy

6

Gabi

2

Martin

3

 

And now, let say I want to create a measure named Number of Pets Excluding You that will sum the Number of Pets for all the Persons, excluding the one that is "currently" selected. So, I want o end up with a Simple Table that displays as follows: 

 

Persons

Number of Pets Excluding You

Lucy

5

Gabi

9

Martin

8

 

Where the Number of Pets Excluding You was 5 for Lucy (Gabi has 2 + Martin has 3), 9 for Gabi (Lucy has 6 + Martin has 3), and 8 for Martin (Lucy has 6 + Gabi has 2).  

 

How can this be achieved?

 

Thanks. 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello @Banistas

Something along these lines using the EXCEPT function should work, assuming you have a [Number of Pets] measure:

Number of Pets Excluding You =
CALCULATE (
    [Number of Pets],
    EXCEPT ( ALL ( YourTable[Persons] ), VALUES ( YourTable[Persons] ) )
)

Using ALL ( YourTable[Persons] ) ensures that you always get the total of all people other than filtered people. You can consider ALLSELECTED if there is an external filter on the people you want to use instead of everyone in the dataset.

Best regards

Owen

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Banistas , Create a measure like this and try

 

calculate(sum(Table[Number of Pets]), all(Table))- sum(Table[Number of Pets])

 

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

Anonymous
Not applicable

Hello @Banistas

Something along these lines using the EXCEPT function should work, assuming you have a [Number of Pets] measure:

Number of Pets Excluding You =
CALCULATE (
    [Number of Pets],
    EXCEPT ( ALL ( YourTable[Persons] ), VALUES ( YourTable[Persons] ) )
)

Using ALL ( YourTable[Persons] ) ensures that you always get the total of all people other than filtered people. You can consider ALLSELECTED if there is an external filter on the people you want to use instead of everyone in the dataset.

Best regards

Owen

Thanks @OwenAugerFon. This does exactly what I needed, and can be applied for cases where there are calculations other than SUM which is brilliant.

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.