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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Help with DAX

Hello,

 

I'm trying to create a measure that shows the following:

 

 

Rotulo_ano = 

VAR AnoMax = CALCULATE(MAX('dCalendário'[Ano]),ALL('dCalendário'[Ano]))

VAR AnoSelec = CALCULATE(MAX('dCalendário'[Ano]))

return IF(AnoMax = AnoSelec," até " & AnoSelec, " em " & AnoSelec)

 

 

If I don't select any year, it shows me "até" (until in Portuguese) the last year. If I select another year, like 2019, it shows me "em" ("in") that specific year. But if I select the last year, which is 2021, it shows me "até", and I want to show me "in" instead because I'm not selecting the whole period.

 

Nothing selected:

Nothing selectedNothing selected

2020 selected:

thaynanff_2-1630710294952.png

2021 selected:

thaynanff_3-1630710332316.png

 

Is there any way I can tell PBI that when I'm selecting a year, even if it's the latest one, it should show me "em"?

 

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @Anonymous 

 

Use HASONEVALUE or SELECTEDVALUE in your code.

Try this measure:

Rotulo_ano = 
VAR AnoSelec = CALCULATE(MAX('dCalendário'[Ano]))
return 
IF(HASONEVALUE('dCalendário'[Ano])," em " & AnoSelec," até " & AnoSelec,)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Appreciate your Kudos✌️!!

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hello, @VahidDM.

 

Thank you for your help. It worked as it should and expected. I'll search a little bit more about the functions you wrote.

VahidDM
Super User
Super User

Hi @Anonymous 

 

Use HASONEVALUE or SELECTEDVALUE in your code.

Try this measure:

Rotulo_ano = 
VAR AnoSelec = CALCULATE(MAX('dCalendário'[Ano]))
return 
IF(HASONEVALUE('dCalendário'[Ano])," em " & AnoSelec," até " & AnoSelec,)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Appreciate your Kudos✌️!!

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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