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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.