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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
Community Champion
Community Champion

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.