Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to workaround Calculate function ignoring filter context

Hello,

 

I have 2 measures. The first one simply counts all orders and the 2nd one does the same thing but for a specific date.

 

This works fine however if I want to group the second measure by sales agent I get the same value for each agent, which is of course wrong. I need the number filtered by sales agent. I've googled and searched these forums but I cant find anything specific to working around this issue. My measure uses calculate so I'm hoping it is a simple substituion for another function but I can't find one that works. Here are my measures.

 

Measure 1:
AllOrders =
COUNTROWS('Orders')

Measure 2:
OrdersPrevDay =
VAR PDate = LASTDATE('Calendar'[Date])

RETURN
CALCULATE ( [AllOrders],
FILTER ( ALL ( 'Calendar' ),
'Calendar'[Date] > PDate - 1 &&

'Calendar'[Date] <= PDate )) + 0

 

What I'm looking for is 

 

OrdersPrevDay SalesAgent

6                       Name 1

5                       Name 2

8                       Name 3

7                       Name 4

8                       Name 5

 

Does anyone have any suggestions? thanks.

  • Hi Anonymous 

    If I understand you correct try to use ALLEXCEPT() like

    OrdersPrevDay =
    VAR PDate = LASTDATE('Calendar'[Date])
    
    RETURN
    CALCULATE ( [AllOrders],
    ALLEXCEPT('Orders', 'Orders'[SalesAgent]),
    FILTER ( ALL ( 'Calendar' ),
    'Calendar'[Date] > PDate - 1 &&
    
    'Calendar'[Date] <= PDate )) + 0

5 Replies