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
Saadahmedqu
Regular Visitor

DAX not giving any errors but not getting the result either

My data has years 2018 to 2021. I am comparing sales with the previous years and have created different DAX for that but for dynamic header based on selection of year, I am using below mentioned DAX but not getting the required result;

Selected value =  Calendar Year (filter)

 

IF(HASONEVALUE('Calendar'[Year]) && SELECTEDVALUE('Calendar'[Year]) > 2018, "Selected Year = " & SELECTEDVALUE('Calendar'[Year]) & " and Previous Year = " &      SELECTEDVALUE('Calendar'[Year]) -1,
IF(HASONEVALUE('Calendar'[Year]) && SELECTEDVALUE('Calendar'[Year]) = 2018,  "Selected Year = 2018 and Previous Year Not present in data",
 
1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Saadahmedqu 

Thanks for reaching out to us.

please use the sample file attached below

vxiaotang_0-1667295569883.png

vxiaotang_1-1667295611447.png

vxiaotang_2-1667295619468.png

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

3 REPLIES 3
v-xiaotang
Community Support
Community Support

Hi @Saadahmedqu 

Thanks for reaching out to us.

please use the sample file attached below

vxiaotang_0-1667295569883.png

vxiaotang_1-1667295611447.png

vxiaotang_2-1667295619468.png

 

Best Regards,

Community Support Team _Tang

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

ValtteriN
Super User
Super User

Hi,

Based on my test your measure seems to be working. Here is an improved dax using variables:

Measure 20 =

var _syear = SELECTEDVALUE('Calendar'[Year])
 var _ftest = HASONEVALUE('Calendar'[Year])
 return

IF( _ftest && _syear > 2018, "Selected Year = " & _syear & " and Previous Year = " &   _syear -1,
IF(_ftest && _syear  = 2018,  "Selected Year = 2018 and Previous Year Not present in data"))



End result:
ValtteriN_0-1666079619447.png

 

If this still doesn't work I recommend cheking what filters affect your visuals. The issue might be there.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/






Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you so much for your reply. I have used your solution also but even then it is not displaying result in card

Dynamic Header.png

The card displayed above based on selection is DAX used by me and the second card displaying cross sign is the query you provided. I think the problem is with multiple conditions based on the selection with hasvalue. There are no filters applied on visuals or page.

Below is the solution provided by you;

Selected_Year_New =
Var syear = SELECTEDVALUE('Calendar'[Year])
Var ftest = HASONEVALUE('Calendar'[Year])

Return
IF(ftest > 2018 && syear > 2018, "Selected Year = " & syear & " and Previous Year = " &   syear -1,
IF(ftest = 2018 && syear = 2018,"Selected Year = 2018 and Previous Year Not present in data"))


Can this issue be solved by fixing it to min year criteria?
  

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.

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.