DAX: How to do ALLSELECTEDEXCEPT()?

gazpage

Active Member
Joined
Apr 17, 2015
Messages
393
Title says it all really. I'd like to combine the behaviours of ALLEXCEPT and ALLSELECTED. So remove the filters, other than external filters, from all the columns except a particular one. Is there a function or way to combine these functions?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi again,

A combination of ALLSELECTED & FILTERS should give you the ALLSELECTEDEXCEPT behaviour:

Code:
=
CALCULATE (
    [YourMeasure],
[COLOR=#ff0000][B]    ALLSELECTED ( YourTable ),[/B][/COLOR]
[COLOR=#ff0000][B]    FILTERS ( YourTable[ColumnToKeep] )[/B][/COLOR]
)

The logic is basically use ALLSELECTED on the entire table, then bring back the explicit filters on the column you want to keep.
And we know that FILTERS ( YourTable[ColumnToKeep] ) will be more restrictive than the values of ColumnToKeep that exist in ALLSELECTED ( YourTable ), so we can safely intersect these two filter arguments.

Note that I used FILTERS rather than VALUES. FILTERS returns a column of values explicitly filtered on a column, whereas VALUES would return values that exist in the current context as a result of both explicit filters and cross-filtering.

Does this give you the behaviour you were looking for?
 
Last edited:
Upvote 0
Yep, that does it. Thanks again.

I thought I was starting to have seen, if not be able to use, all the main DAX functions, but FILTERS is new to me. I think I understand your formula to be doing the intersect of the ALLSELECTED and FILTERS, but they are calculated independently before being applied.

I'm sure there are other things I will have struggled with before that FILTERS would have helped with.
 
Upvote 0
Hi again,

A combination of ALLSELECTED & FILTERS should give you the ALLSELECTEDEXCEPT behaviour:

Code:
=
CALCULATE (
    [YourMeasure],
[COLOR=#ff0000][B]    ALLSELECTED ( YourTable ),[/B][/COLOR]
[COLOR=#ff0000][B]    FILTERS ( YourTable[ColumnToKeep] )[/B][/COLOR]
)

The logic is basically use ALLSELECTED on the entire table, then bring back the explicit filters on the column you want to keep.
And we know that FILTERS ( YourTable[ColumnToKeep] ) will be more restrictive than the values of ColumnToKeep that exist in ALLSELECTED ( YourTable ), so we can safely intersect these two filter arguments.

Note that I used FILTERS rather than VALUES. FILTERS returns a column of values explicitly filtered on a column, whereas VALUES would return values that exist in the current context as a result of both explicit filters and cross-filtering.

Does this give you the behaviour you were looking for?

Just wanted to say thanks for the solution, and thanks to the OP for phrasing it in exactly the way I googled it! :)
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top