Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Make the measures dynamic with date range selection.

I am working on a Dahsboard and I have created 3 measues that calcuate the  inactive clients within 2 years, in active client beyond 2 years, and cross service clients (meaning the number of client ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous 

     

    For your question, in your dax I see that you used "ALL" for filtering. 

     

    In fact, "ALL" removes the effect of the slicer. You can modify "ALL" to "ALLSELECTED". 

     

    "ALLSELECTED" retains the slicer filter and removes the other filters.

     

    Your code should look like this:

    InactiveClients_Beyond2Years =
    CALCULATE(
        COUNTROWS(
            FILTER(
                VALUES(SQL_Database_Website[NTID]),
                CALCULATE(MAX(SQL_Database_Website[SubmitDate])) <= MAX(SQL_Database_Website[SubmitDate]) - 730
            )
        ),
        ALLSELECTED(SQL_Database_Website[SubmitDate]) -- modify "ALL" to "ALLSELECTED" 
    )
     
    
    InactiveClients_Within2Years =
    CALCULATE(
        COUNTROWS(
            FILTER(
                VALUES(SQL_Database_Website[NTID]),
                CALCULATE(MAX(SQL_Database_Website[SubmitDate])) > MAX(SQL_Database_Website[SubmitDate]) - 730 &&
                CALCULATE(MAX(SQL_Database_Website[SubmitDate])) <= MAX(SQL_Database_Website[SubmitDate])
            )
        ),
        ALLSELECTED(SQL_Database_Website[SubmitDate])
    )
    
    CrossServiceClients =
    CALCULATE(
        COUNTROWS(
            FILTER(
                VALUES(SQL_Database_Website[NTID]),
                CALCULATE(DISTINCTCOUNT(SQL_Database_Website[Type])) > 1
            )
        ),
        ALLSELECTED(SQL_Database_Website[SubmitDate])
    )

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.