Forum Discussion

Datavizuserpbi's avatar
4 years ago
Solved

Selectedvalue always return defalut value in switch

Hi ,

 

I have a slicer with 3 values Choice= 1,2,3 when i use selectedvalue - >

Value=SELECTEDVALUE('Table 1'[Choice],1) and call it in my switch function it's always return 1  even if 2 is selected
SWITCH([Value]
,1,Table 2[Ouvert N-1]
,2, Table 2[Ouvert N-2]
,3, Table 2[Ouvert N-3]
).
I try to create a column to see the value of the selectedvalue and it's correct but in th switch function is always 1.
Thank you for your help!
  • Hi Datavizuserpbi ,

     

    As PaulDBrown said, you can't return an entire column of values, you have to summarize those columns, for example to find their maximum value.

     

    Measure = 
    SWITCH (
        SELECTEDVALUE ( Slicer[Val] ),
        1, MAX ( 'Table 2'[Ouvert N-1] ),
        2, MAX ( 'Table 2'[Ouvert N-2] ),
        3, MAX ( 'Table 2'[Ouvert N-3] )
    )


    If you want to return different columns, you need to use field parameters.

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

6 Replies

  • PaulDBrown's avatar
    PaulDBrown
    Icon for Community Champion rankCommunity Champion

    IF and SWICTH functions follow the order of the expressions: if the first expressions returns TRUE(), then that will be the result of the measure. If the first expression returns FALSE, then the second row is checked etc....

    What are you trying to achieve? If you need to list the selections you can try:

     

    List selection = 
    CONCATENATEX(VALUES(Slicer Table[Field]), Slicer Table [Field], ", ")

     

    • Datavizuserpbi's avatar
      Datavizuserpbi
      Icon for Helper I rankHelper I

      The problem is the value of the expression it should return either 1,2 or 3 but it doesn't return 2 or 3 even they are selected with the slicer. The value by default is 1 - > Value=SELECTEDVALUE('Table 1'[Choice],1) .

      The expression is always equal to the default value even if it's not selected

      • PaulDBrown's avatar
        PaulDBrown
        Icon for Community Champion rankCommunity Champion

        Sorry, I'm not sure I'm following.  It works in this example:

        Slicer Value = 
        SWITCH(
            SELECTEDVALUE(Slicer[Val]),
        1, "AAAA",
        2, "BBB",
        3, "CCC",
        4, "D",
        "Z")

         

         

         

  • v-kkf-msft's avatar
    v-kkf-msft
    Icon for Community Support rankCommunity Support

    Hi Datavizuserpbi ,

     

    As PaulDBrown said, you can't return an entire column of values, you have to summarize those columns, for example to find their maximum value.

     

    Measure = 
    SWITCH (
        SELECTEDVALUE ( Slicer[Val] ),
        1, MAX ( 'Table 2'[Ouvert N-1] ),
        2, MAX ( 'Table 2'[Ouvert N-2] ),
        3, MAX ( 'Table 2'[Ouvert N-3] )
    )


    If you want to return different columns, you need to use field parameters.

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.