Search code examples
filterconditional-statementsdaxmeasure

Adding condition into existing DAX measure


I have the following measure written in DAX, its name - [Undup Active Clients KPI]:

(This is just a version written in DAX Studio for testing purposes)

      MEASURE 'KPI Measures'[Undup Active Clients KPI] =
               VAR undupClientsServed =
                  TREATAS (
                 SUMMARIZE (
                     FILTER (
                        'Client Services',
                        'Client Services'[ClientWHID] > 0
                        && 'Client Services'[Is No-show] = FALSE ()
                        && 'Client Services'[Is Cancellation] = FALSE ()
                        && 'Client Services'[Is Non-claimable] = FALSE ()
                      ),
                       'Client Services'[ClientWHID]
                      ),
                       'Client Episode Metrics'[ClientWHID]

                      )
           VAR result =
              CALCULATE ( [Undup Active Clients], undupClientsServed )
             RETURN
                result 

In order for this measure to work correctly, I need to add the following condition in 'Client Episode Metrics':

      FILTER('Client Episode Metrics',
             'Client Episode Metrics'[AdmissionDate] <= 'Client Services'[Service Month])

I am relatively new to DAX and having difficulties adding this condition correctly in the code above (code for [Undup Active Clients KPI] measure)

Please advice or help how would I add the condition

Not sure if FILTER will work for my goal


Solution

  • Can you try the following and see if it gives you the desired outcome. In case it does not please provide sample data and expected outcome here.

    MEASURE 'KPI Measures'[Undup Active Clients KPI]-------
    -------------------------------------------------------
    VAR result = CALCULATE ( [Undup Active Clients], undupClientsServed )
    VAR _filterdResult = CALCULATE ([result],FILTER('Client Episode Metrics','Client Episode Metrics'[AdmissionDate] <= max('Client Services'[Service Month]))
    RETURN _filterdResult