# If selected year

Hey guys
How are you all doing? Safe and healthy? Hope so.
Is there a way of a measure do something like this:
VAR Measure 1 = 25000
VAR Measure 2 = 27500
VAR Measure 3 = 30000

RETURN
Switch ( True (),

Selected value (year) = “2018”, Measure 1,
Selected value (year) = “2019”, Measure 2,
Selected value (year) = “2020”, Measure 3,
Selected value (year) = “”, “”,) )

Don’t have to be like this, i just thought it should be.
The idea is to know what was the year value selected in the filter.

Thank you all
Pedro

P.S. one more thing: although my visual shows the numbers by month this one will show only once, maybe in the total…

``````  =
VAR SelectedYear =
SELECTEDVALUE ( Dates[Year] )
VAR Measure1 = 25000
VAR Measure2 = 27500
VAR Measure3 = 30000
VAR Result =
SWITCH (
TRUE (),
SelectedYear = 2018, Measure1,
SelectedYear = 2019, Measure2,
SelectedYear = 2020, Measure3
)
RETURN
Result``````
1 Like

Antriksh already gave answer faster than me. You can try below DAX too same as yours.

``````Test =
VAR Measure_1 = 25000
VAR Measure_2 = 27500
VAR Measure_3 = 30000
RETURN
SWITCH ( TRUE(),
SELECTEDVALUE('Date'[Year]) = "2018", Measure_1,
SELECTEDVALUE('Date'[Year]) = "2019", Measure_2,
SELECTEDVALUE('Date'[Year]) = "2020", Measure_3,
BLANK()
)``````
1 Like

Hello @pedroccamara,

Thank You for posting your query onto the Forum.

Just a minor change in the formula, instead of hard-coding the Year you can mention the Year column from the dates tables. And at the end you can just replace it with “BLANK()” function or simply write it as 0 if no year is selected. Or else you can also mention that if no year is selected show the default value as “Measure1”.

And another thing is you sure that you want to hard-code the figures because those are just the static numbers. Just few hours back I’ve posted the solution where our member hard-coded the numbers and was not able to slice and dice.

You can just check out the post. Providing the link below for the reference. Hoping your case is absolutely different than the one provided.

Thanks and Warm Regards,
Harsh

1 Like

Hey guys, you’re are the best and very fast!!! I almost did it on my own!!!
First, thank you so much for all your answers, and 2nd, this measure, is suppose to show only once, in my year visual (as i’ve asked in my P.S. text) I want to see all the numbers, from Jan to Aug, but this one (it’s a kind of a tax a company has for their business, you know @Harsh ) it will show once, or if it’s too hard, divided by the number of months selected, BUT ALWAYS the value chosen above.
Thank you all