Forum Discussion

yasbos's avatar
yasbos
Resolver II
3 years ago
Solved

Context Filter Help

Hi. I thought I had completely understood how this works, but now I'm doubting myself. You see, I have a calendar table and a service table. They are related 1-to-many on the date. There are certain calculations that require the latest service date, so, I thought I'd just create a measure in the calendar table:

Current_Date= max(service[date]).

 

Here is the problem. The Current_Date is currently the 9th of April. So, When I want to list all of the service reps in a table along with the count of their tickets for the current month, I should get a 0 counts for the reps who have no tickets for the current month, since the Current_Date should be set at April 9, 2023.

In the Service table, I have the following measures:
_Total_Requests=count(Service[Request_ID])

 

ticketsMTD=
      var
vMaxDate=[Current_Date]
      var vMTDRequests=calculate([_Total_Requests],filter(Service,month(Service[Created_Time])=month(vMaxDate) &&        year(Service[Created_Time])=year(vMaxDate)))

 

Now, the problem: I have no tickets for Mark in the current month. The last time Mark had any tickets, it was in October of 2022. His total tickets in October of 2022 were 236. The problem is that, when I create a table visual for the reps and their ticketsMTD, I get 236 for Mark, when I should be getting 0 or blank. Why is this happening? Thanks so much.

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi yasbos ,

    It seems that you are trying to get the maximum value of the [Date] column in the service table and ignore the filtering context on this column.

    Please try this.

    Current_Date =
    CALCULATE ( MAX ( service[date] ), ALL () )

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi yasbos ,

    It seems that you are trying to get the maximum value of the [Date] column in the service table and ignore the filtering context on this column.

    Please try this.

    Current_Date =
    CALCULATE ( MAX ( service[date] ), ALL () )

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

  • yasbos , You should use today for current month

     

    ticketsMTD=
          var
    vMaxDate=today()
          var vMTDRequests=calculate([_Total_Requests],filter(Service,month(Service[Created_Time])=month(vMaxDate) &&        year(Service[Created_Time])=year(vMaxDate)))
     
     
    also for last available month
     
    ticketsMTD=
          var
    vMaxDate=maxX(allselected(service), service[date])
          var vMTDRequests=calculate([_Total_Requests],filter(Service,month(Service[Created_Time])=month(vMaxDate) &&        year(Service[Created_Time])=year(vMaxDate)))
    • yasbos's avatar
      yasbos
      Resolver II

      Thanks. It's just that I need the current month to really be the last month in the data--not the current calendar month--hence my approach. I guess I'll have to change and make a compromise, to get it to work.