Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

VALUES is not retuning correct result inside switch function.

I created a DAX in which I am use values of a slicer and based on that calcuations are happened. but the Values is not returning correct result.

 

PY_test =
IF(HASONEVALUE('Time Intelligence'[Period]),
SWITCH(
TRUE(),
VALUES('Time Intelligence'[Period]) = "W",CALCULATE([Value],'Prior Year'[Name] = "PY",'Time Intelligence'[Period] = "W"),
VALUES('Time Intelligence'[Period]) = "4W",CALCULATE([Value],'Prior Year'[Name] = "PY",'Time Intelligence'[Period] = "4W"),
VALUES('Time Intelligence'[Period]) = "12W",CALCULATE([Value],'Prior Year'[Name] = "PY",'Time Intelligence'[Period] = "12W"),
VALUES('Time Intelligence'[Period]) = "52W",CALCULATE([Value],'Prior Year'[Name] = "PY",'Time Intelligence'[Period] = "52W")
))
 

 

If I select "4W" from Slicer then I get blank result. Where as When I use VALUES('Time Intelligence'[Period]) in a different measure it returns correctly Whatever i selected in slicer.

 

Note:- We have data for All of these.

 

 
**In the above DAX neither "Values" nor "SelectedValues" give me result. 'Time Intelligence' is a calculation group.
Anyone can tell me how can I overcome this. 
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous .

    Use this DAX instead;

    PY_test =
    var a=SELECTEDVALUE(Time Intelligence'[Period]),
    SWITCH(
    TRUE(),
    a = "W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "W"),
    a = "4W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "4W"),
    a = "12W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "12W"),
    a = "52W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "52W")
    ))

    Let me know if that works.

    Thanks,
    Sanket


    If this post helps, then mark it as "Accept as Solution" and give it a thumbs up.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous .

    Use this DAX instead;

    PY_test =
    var a=SELECTEDVALUE(Time Intelligence'[Period]),
    SWITCH(
    TRUE(),
    a = "W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "W"),
    a = "4W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "4W"),
    a = "12W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "12W"),
    a = "52W",CALCULATE([Value],'Prior Year'[Name] = "PY",a = "52W")
    ))

    Let me know if that works.

    Thanks,
    Sanket


    If this post helps, then mark it as "Accept as Solution" and give it a thumbs up.