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

View all the Fabric Data Days sessions on demand. View schedule

Reply
lruijven
Regular Visitor

Retain filters from slicers with ALLEXCEPT()

Hi, hope someone can help me with the next problem. I want to make a graph in PowerBI desktop where the maximum room occupancy per date gets clear. The source I use is a Azure Analysis Services model. 

 

I have 4 tables: [Samples], [Dates], [Times], [Rooms]. The last tree tables have a relationship with the [Samples] table

 

Samples (for SensorOccupancy: 1 = occupied):

LocalDateLocalTImeRoomIdSensorOccupancy
1-May8:00a1
1-May8:00b1
1-May8:00c0
1-May8:15a1
1-May8:15b1
1-May8:15c1
1-May8:30a0
1-May8:30b0
1-May8:30c1
2-May8:00a0
2-May8:00b1
2-May8:00c0
2-May8:15a0
2-May8:15b1
2-May8:15c1
2-May8:30a0
2-May8:30b0
2-May8:30c0

LocalDate:

LocalDate

1-May
2-May

LocalTime:

LocalTime

8:00
8:15
8:30

RoomId:

RoomId

a
b
c

 

For every date in Samples, I want to know what the highest percentage of occupied rooms per time period was.
Everything is working fine with the next measure on the Samples table:

Max average occupancy per Date:= CALCULATE(MAXX(Samples,CALCULATE(AVERAGEX(Samples,Samples[SensorOccupancy])
,ALLEXCEPT(Samples,Samples[LocalDate],Samples[LocalTime])
)                                                ),
ALLEXCEPT(Samples, Samples[LocalDate], Samples[RoomId])
)

 And the next table would be my result:

OccupancyRoomTimeDateMax average occupancy per Date
1a8:001-May100%
1b8:001-May100%
0c8:001-May100%
1a8:151-May100%
1b8:151-May100%
1c8:151-May100%
0a8:301-May100%
0b8:301-May100%
1c8:301-May100%
0a8:002-May67%
1b8:002-May67%
0c8:002-May67%
0a8:152-May67%
1b8:152-May67%
1c8:152-May67%
0a8:302-May67%
0b8:302-May67%
0c8:302-May67%

 

the only problem is: when I use a slicer on one of the related tables, for example Room = {a,b} , the measure still uses the original data set for the calculations! (I want to apply slicers on all the related tables)
The ALLEXCEPT() does not retain the filters I apply with the slicers!

See next table for a example of what goes wrong:

 

OccupancyRoomTimeDateMax average occupancy per DateWanted result
1a8:001-May100%100%
1b8:001-May100%100%
1a8:151-May100%100%
1b8:151-May100%100%
0a8:301-May100%100%
0b8:301-May100%100%
0a8:002-May67%50%
1b8:002-May67%50%
0a8:152-May67%50%
1b8:152-May67%50%
0a8:302-May67%50%
0b8:302-May67%50%

 

I already tried some things with ALLSELECTED() and KEEPFILTERS(), but for so far without a result.

 

Thank you in advance!

1 ACCEPTED SOLUTION

HI @lruijven

 

You could try this calculated measure.  I have attached a PBIX file for you to play with.

 

Wanted Result = 
VAR x =
ADDCOLUMNS(
    SUMMARIZE(
        FILTER(
            ALLSELECTED('Samples') ,
             'Samples'[LocalDate]=MAX('Samples'[LocalDate]) 
            ) ,
        'Samples'[LocalDate] ,
        'Samples'[LocalTIme] ,
        "Available" , 
            CALCULATE(
                COUNTROWS('Samples'),
                FILTER(
                    ALLSELECTED('Samples'), 
                    'Samples'[LocalDate]=MAX('Samples'[LocalDate]) && 
                    'Samples'[LocalTIme] = MAX('Samples'[LocalTIme]) 
                    ) 
                ),
        "Occupied" , 
                    CALCULATE(
                COUNTROWS('Samples'),
                FILTER(
                    ALLSELECTED('Samples'), 
                    'Samples'[LocalDate]=MAX('Samples'[LocalDate]) && 
                    'Samples'[LocalTIme] = MAX('Samples'[LocalTIme]) && 'Samples'[SensorOccupancy] = 1
                    ) 
                )
            ),"Wanted Result" , DIVIDE([Occupied],[Available],0))



        
RETURN MAXX(x,[Wanted Result])
        

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

6 REPLIES 6
Stachu
Community Champion
Community Champion

does the measure work fine?
e.g. I would expect for room c at 8:00 on May 1st to show 0% rather than 100%.
or show 67% (2 rooms occupied out of 3) rather than 100% - is my interpretation of the requirement correct?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Hi!

 

Yes, the measure is working perfectly, when I am not applying any filters. 

My goal is to know the percentage of the most occupied quarter, per date. So the measure gives a percentage per date!

 

any ideas? 

HI @lruijven

 

You could try this calculated measure.  I have attached a PBIX file for you to play with.

 

Wanted Result = 
VAR x =
ADDCOLUMNS(
    SUMMARIZE(
        FILTER(
            ALLSELECTED('Samples') ,
             'Samples'[LocalDate]=MAX('Samples'[LocalDate]) 
            ) ,
        'Samples'[LocalDate] ,
        'Samples'[LocalTIme] ,
        "Available" , 
            CALCULATE(
                COUNTROWS('Samples'),
                FILTER(
                    ALLSELECTED('Samples'), 
                    'Samples'[LocalDate]=MAX('Samples'[LocalDate]) && 
                    'Samples'[LocalTIme] = MAX('Samples'[LocalTIme]) 
                    ) 
                ),
        "Occupied" , 
                    CALCULATE(
                COUNTROWS('Samples'),
                FILTER(
                    ALLSELECTED('Samples'), 
                    'Samples'[LocalDate]=MAX('Samples'[LocalDate]) && 
                    'Samples'[LocalTIme] = MAX('Samples'[LocalTIme]) && 'Samples'[SensorOccupancy] = 1
                    ) 
                )
            ),"Wanted Result" , DIVIDE([Occupied],[Available],0))



        
RETURN MAXX(x,[Wanted Result])
        

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Good day Phil,

 

I have a similar issue, which I'm also trying to address with ALLEXCEPT(), however mine has a little twist. 

I'm trying to figure out how much time the person spent in each room, so the logic I was trying to follow was to calculate the MIN and MAX of the DateTime for each room, from each location (there are more than one location in the data and then measuring the difference between the min and max times. This approach unfortunately doesn't take into account, the time spent when moving from one room to another.

 

When I use the calculation: Motion Sensor MIN = CALCULATE(MIN ( Motion[Time(no secs)]), ALLEXCEPT ( Motion, Motion[Date], Motion[Location], Motion[Room] )), it does not take into account when a person goes from a Living Room to a Bathroom back to the Living Room.

 

My data is as follows:

RoomLocationStatusDateDateTimeTimeTime(no secs)
Living RoomLocation 1active2018/05/162018/05/16 00:1400:14:3500:14
Living RoomLocation 1active2018/05/162018/05/16 00:3100:31:0900:31
Living RoomLocation 1inactive2018/05/162018/05/16 17:4317:43:0417:43
Living RoomLocation 1inactive2018/05/162018/05/16 18:5218:52:4718:52
Living RoomLocation 1active2018/05/162018/05/16 19:3819:38:5219:38
Living RoomLocation 1inactive2018/05/162018/05/16 20:5320:53:0720:53
Living RoomLocation 1active2018/05/162018/05/16 21:1921:19:3021:19
FL6 BathroomLocation 1inactive2018/05/162018/05/16 21:3321:33:3821:33
FL6 BathroomLocation 1inactive2018/05/162018/05/16 21:3721:37:5021:37
Living RoomLocation 1inactive2018/05/162018/05/16 23:4523:45:1523:45
Living RoomLocation 1inactive2018/05/172018/05/17 10:0010:00:2410:00
Living RoomLocation 1active2018/05/172018/05/17 10:3410:34:2810:34
Living RoomLocation 1inactive2018/05/172018/05/17 11:0211:02:0811:02
Living RoomLocation 1active2018/05/172018/05/17 11:0911:09:5511:09
Living RoomLocation 1active2018/05/172018/05/17 11:2611:26:2611:26
Living RoomLocation 1active2018/05/172018/05/17 12:1612:16:3912:16
Living RoomLocation 1active2018/05/172018/05/17 12:2312:23:1312:23
Living RoomLocation 1inactive2018/05/172018/05/17 14:4514:45:0614:45
Living RoomLocation 1inactive2018/05/172018/05/17 15:5915:59:2315:59
Living RoomLocation 1active2018/05/172018/05/17 16:2116:21:0116:21
Living RoomLocation 1inactive2018/05/172018/05/17 17:2917:29:2017:29
Living RoomLocation 1inactive2018/05/172018/05/17 18:0018:00:3418:00
Living RoomLocation 1active2018/05/172018/05/17 18:0018:00:1818:00
Living RoomLocation 1inactive2018/05/172018/05/17 19:2119:21:3819:21
Living RoomLocation 1inactive2018/05/172018/05/17 20:4320:43:4320:43
Living RoomLocation 1active2018/05/172018/05/17 21:4121:41:3621:41
Living RoomLocation 1active2018/05/172018/05/17 21:5721:57:5921:57
Living RoomLocation 1active2018/05/172018/05/17 22:1722:17:4722:17
Living RoomLocation 1active2018/05/182018/05/18 08:1108:11:0208:11
Living RoomLocation 1active2018/05/182018/05/18 08:4608:46:5308:46
Living RoomLocation 1inactive2018/05/182018/05/18 09:0809:08:5909:08
Living RoomLocation 1active2018/05/182018/05/18 10:0610:06:1810:06
Living RoomLocation 1active2018/05/182018/05/18 11:0011:00:0211:00
Living RoomLocation 1active2018/05/182018/05/18 11:5111:51:1811:51
Living RoomLocation 1inactive2018/05/182018/05/18 11:5811:58:2611:58
Living RoomLocation 1inactive2018/05/182018/05/18 16:2616:26:4916:26
Living RoomLocation 1active2018/05/182018/05/18 18:4418:44:4718:44
Living RoomLocation 1inactive2018/05/182018/05/18 18:5018:50:3718:50
Living RoomLocation 1inactive2018/05/182018/05/18 18:5718:57:2018:57
Living RoomLocation 1inactive2018/05/182018/05/18 19:0019:00:1719:00
Living RoomLocation 1inactive2018/05/182018/05/18 19:0419:04:1719:04
Living RoomLocation 1inactive2018/05/182018/05/18 19:0919:09:4619:09
FL6 BathroomLocation 1inactive2018/05/182018/05/18 21:1621:16:4521:16
FL6 BathroomLocation 1active2018/05/182018/05/18 21:2121:21:2321:21
Living RoomLocation 1inactive2018/05/192018/05/19 01:0901:09:4801:09
Living RoomLocation 1inactive2018/05/192018/05/19 01:1601:16:0501:16
Living RoomLocation 1inactive2018/05/192018/05/19 01:2201:22:1401:22
Living RoomLocation 1inactive2018/05/192018/05/19 10:0810:08:0710:08
Living RoomLocation 1inactive2018/05/192018/05/19 10:2810:28:3810:28
Living RoomLocation 1active2018/05/192018/05/19 10:2810:28:2610:28
Living RoomLocation 1inactive2018/05/192018/05/19 14:3714:37:3314:37
Living RoomLocation 1inactive2018/05/192018/05/19 14:5914:59:1314:59
Living RoomLocation 1inactive2018/05/192018/05/19 17:5917:59:0417:59
Living RoomLocation 1inactive2018/05/192018/05/19 18:2418:24:3918:24
Living RoomLocation 1inactive2018/05/192018/05/19 20:3920:39:3220:39
Living RoomLocation 1active2018/05/192018/05/19 22:0222:02:0322:02
Living RoomLocation 1active2018/05/192018/05/19 23:4523:45:2823:45

 

The questions I'm trying to answer is as follows: 

 

1 What room is the person in?

2 How long have they been in this room?

3. Are they active or idle within this room?

 

I thought that 1 may be solved with some timestamped calculated column that updates when a motion sensor triggers in a new room. For 2 Might be the DateDiff between first and last time the sensor triggered and 3 Might be a simple Count of motion sensor events during the period.

 

Any guidance you can give in this regard would be very much appreciated!!

 

Thank you and have a wonderful day.

 

Kind Regards,

LlewBear

Hi @phil

 

Thank you! The measure works perfect! 

 

lruijven
Regular Visitor

Hi, hope someone can help me with the next problem. I want to make a graph in PowerBI desktop where the maximum room occupancy per date gets clear. The source that I use is a Azure Analysis Services model. 

 

I have 4 tables: [Samples], [Dates], [Times], [Rooms]. The last tree tables have a relationship with the [Samples] table

 

Samples (for SensorOccupancy: 1 = occupied):

LocalDateLocalTImeRoomIdSensorOccupancy
1-May8:00a1
1-May8:00b1
1-May8:00c0
1-May8:15a1
1-May8:15b1
1-May8:15c1
1-May8:30a0
1-May8:30b0
1-May8:30c1
2-May8:00a0
2-May8:00b1
2-May8:00c0
2-May8:15a0
2-May8:15b1
2-May8:15c1
2-May8:30a0
2-May8:30b0
2-May8:30c0

LocalDate:

LocalDate

1-May
2-May

LocalTime:

LocalTime

8:00
8:15
8:30

RoomId:

RoomId

a
b
c

 

For every date in Samples, I want to know what the highest percentage of occupied rooms per time period was.
Everything is working fine with the next measure on the Samples table:

Max average occupancy per Date:= CALCULATE(MAXX(Samples,CALCULATE(AVERAGEX(Samples,Samples[SensorOccupancy])
,ALLEXCEPT(Samples,Samples[LocalDate],Samples[LocalTime])
)                                                ),
ALLEXCEPT(Samples, Samples[LocalDate], Samples[RoomId])
)

 And the next table would be my result:

OccupancyRoomTimeDateMax average occupancy per Date
1a8:001-May100%
1b8:001-May100%
0c8:001-May100%
1a8:151-May100%
1b8:151-May100%
1c8:151-May100%
0a8:301-May100%
0b8:301-May100%
1c8:301-May100%
0a8:002-May67%
1b8:002-May67%
0c8:002-May67%
0a8:152-May67%
1b8:152-May67%
1c8:152-May67%
0a8:302-May67%
0b8:302-May67%
0c8:302-May67%

 

Only problem is: when I use a slicer on one of the related tables, for example Room = {b,c} , the measure still uses the orignal data set for the calculations! (I want to apply slicers on all the related tables)
The ALLEXCEPT() does not retain the filters I apply with the slicers!

See next table for a example of what goes wrong:

 

OccupancyRoomTimeDateMax average occupancy per DateWanted result
1a8:001-May100%100%
1b8:001-May100%100%
1a8:151-May100%100%
1b8:151-May100%100%
0a8:301-May100%100%
0b8:301-May100%100%
0a8:002-May67%50%
1b8:002-May67%50%
0a8:152-May67%50%
1b8:152-May67%50%
0a8:302-May67%50%
0b8:302-May67%50%

 

I already tried some things with ALLSELECTED() and KEEPFILTERS(), but for so far without a result.

 

Thank you in advance!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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
Top Kudoed Authors