Forum Discussion

saivina2920's avatar
saivina2920
Post Prodigy
5 years ago
Solved

How do we call variables in DAX measure

I am using below measure and i just want to call the variables.

 

variables ==> need to get from slicer/dropdown or any selected controls/chart values.

 

How do we assign controls/chart values in variable ($$$variables), and use those variables in measures.

 

EMPSTATUS = CALCULATE (DISTINCTCOUNT ( 'EMP QUERY'[EMP_NUMBER] ),
( 'EMP QUERY'[EMP_REMARKS], "GOOD" ),( 'EMP QUERY'[EMP_COUNTRY], "INDIA" ),( 'EMP QUERY'[EMP_PLACE], $$$variables )
)

  • Hi saivina2920 ,

     

    Please try this.

    EMPSTATUS = 
    VAR variables = SELECTEDVALUE('EMP QUERY'[EMP_PLACE])
    RETURN
    CALCULATE(
        DISTINCTCOUNT ( 'EMP QUERY'[EMP_NUMBER] ),
        FILTER(
            ALL('EMP QUERY'),
            'EMP QUERY'[EMP_REMARKS] in { "GOOD", "EXCELLENT"} &&
            'EMP QUERY'[EMP_COUNTRY] = "INDIA" &&
            'EMP QUERY'[EMP_PLACE] = variables
        )
    )

     

    Best regards,
    Lionel Chen

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

     

18 Replies

  • Conditional Formatting =
    var SelectedGroupNm =SELECTEDVALUE(Budget[Budget])
    var Result= IF([Cost]<= SelectedGroupNm || ISBLANK(SelectedGroupNm),0,1)
    Return Result

    In the above example, there is slicer called Budget and based on the one which is selected I am deriving a measure.

    • saivina2920's avatar
      saivina2920
      Post Prodigy

      Sorry. i don't understand what you given.

      my data available in slicer control. i am going to select only one at a time. Ex : 'EMP QUERY'[EMP_PLACE] 

      what ever i am selecting the slicer option control, that should pass as a variable in my expression as mentioned above.

      can you pls. give us the below mentioned expression measure.

      EMPSTATUS = CALCULATE (DISTINCTCOUNT ( 'EMP QUERY'[EMP_NUMBER] ),
      ( 'EMP QUERY'[EMP_REMARKS], "GOOD" ),( 'EMP QUERY'[EMP_COUNTRY], "INDIA" ),( 'EMP QUERY'[EMP_PLACE], $$$variables )
      )

       

      • NandanHegde's avatar
        NandanHegde
        Super User

        Hey, I have updated my answer with a simple DAX measure. Hope that would help you in utilizing the variables for selectedvalues within measures

  • v-lionel-msft's avatar
    v-lionel-msft
    Community Support

    Hi saivina2920 ,

     

    Please try the formula.

    EMPSTATUS = 
    VAR variables = SELECTEDVALUE('EMP QUERY'[EMP_PLACE])
    RETURN
    CALCULATE(
        DISTINCTCOUNT ( 'EMP QUERY'[EMP_NUMBER] ),
        FILTER(
            ALL('EMP QUERY'),
            'EMP QUERY'[EMP_REMARKS] = "GOOD" &&
            'EMP QUERY'[EMP_COUNTRY] = "INDIA" &&
            'EMP QUERY'[EMP_PLACE] = variables
        )
    )

     

    Best regards,
    Lionel Chen

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

    • saivina2920's avatar
      saivina2920
      Post Prodigy

      Thanks again for your great help.

      Shall i use the below condition if more than two values.

      'EMP QUERY'[EMP_REMARKS] in ("GOOD","EXCELLENT")

       

      • v-lionel-msft's avatar
        v-lionel-msft
        Community Support

        Hi saivina2920 ,

         

        Please try this.

        EMPSTATUS = 
        VAR variables = SELECTEDVALUE('EMP QUERY'[EMP_PLACE])
        RETURN
        CALCULATE(
            DISTINCTCOUNT ( 'EMP QUERY'[EMP_NUMBER] ),
            FILTER(
                ALL('EMP QUERY'),
                'EMP QUERY'[EMP_REMARKS] in { "GOOD", "EXCELLENT"} &&
                'EMP QUERY'[EMP_COUNTRY] = "INDIA" &&
                'EMP QUERY'[EMP_PLACE] = variables
            )
        )

         

        Best regards,
        Lionel Chen

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