Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Dynamic measure by changing parameter slicer

Hi friends,

how can i change measure through slicer fields from parameter, i tried the normal way using switch() but it doesnt work

 

parameter slicer

 

card with switch() measure

 

error details

 

 

5 Replies

  • Anonymous,

     

    Try this measure:

     

     

    Switch Measure =
    VAR vSelectedParameter =
        SELECTCOLUMNS (
            SUMMARIZE ( 'Parameter', 'Parameter'[Parameter], 'Parameter'[Parameter Fields] ),
            "Parameter", 'Parameter'[Parameter]
        )
    VAR vResult =
        SWITCH (
            vSelectedParameter,
            "Aging GR>1-90 days", 1,
            "Aging GR>91 - 180 days", 2
        )
    RETURN
        vResult

     

    • DataInsights's avatar
      DataInsights
      Icon for Super User rankSuper User

      I had to add a space to each side of the hyphen between 91 and 180 due to the community requirement below:

       

       

      Natalie_iTalent do you know why this error occurred?

      • Natalie_iTalent's avatar
        Natalie_iTalent
        Icon for Administrator rankAdministrator

        Hello DataInsights,

        Thank you for bringing this to my attention.  It has been resolved and you shouldn't have any other issues.

         

        Best,

        Natalie H.

        Community Manager 

    • Anonymous's avatar
      Anonymous
      Not applicable

      DataInsights it work! but just a little more, i put this measure to y axis in combo visual and if user doesnt select any slicer it will error, could you let the measure just blank or something not make visual broke?

      selected one

       

      if not select anyone on slicer

       

       

      • DataInsights's avatar
        DataInsights
        Icon for Super User rankSuper User

        Anonymous,

         

        I would need to see your model or sample data. You can share a link to OneDrive, etc. One idea is to add an ELSE argument to the measure in case of no user selection:

         

        Switch Measure =
        VAR vSelectedParameter =
            SELECTCOLUMNS (
                SUMMARIZE ( 'Parameter', 'Parameter'[Parameter], 'Parameter'[Parameter Fields] ),
                "Parameter", 'Parameter'[Parameter]
            )
        VAR vResult =
            SWITCH (
                vSelectedParameter,
                "Aging GR>1-90 days", 1,
                "Aging GR>91-180 days", 2,
                "put ELSE argument here"
            )
        RETURN
            vResult