Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

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")
))
 
anupam676_1-1648013656925.png

 

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.

anupam676_0-1648013590675.png

 

Note:- We have data for All of these.

anupam676_0-1648013868855.png

 

 
**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. 
1 ACCEPTED SOLUTION
SanketBhagwat
Solution Sage
Solution Sage

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.

View solution in original post

1 REPLY 1
SanketBhagwat
Solution Sage
Solution Sage

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.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.