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
MarkD1722
Resolver I
Resolver I

Trying to convert a year to a string for use with the SEARCH function

I am trying to take the selected value from a year slicer and use it in a SEARCH function.  I cannot seem to get the DAX right to make the data types match for the comparison.  I have tried the CONVERT function also, but I still get the same error (below).  Anyone who can show me where I am going wrong with this?  Thanks.

Also, which is the better option for searching for that year?  SEARCH or CONTAINSTRING?

MarkD1722_0-1716472574246.png

 

MarkD1722_1-1716472590132.png

 



1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@MarkD1722 , Instead of General change the formula with number like

 

SelectedYearString = FORMAT(SelectedYear, "0")




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

4 REPLIES 4
bhanu_gautam
Super User
Super User

@MarkD1722 , Instead of General change the formula with number like

 

SelectedYearString = FORMAT(SelectedYear, "0")




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






This worked, but I would never have known to use that.

Separately, I used CONTAINSSTRING for my logical test instead of SEARCH after looking more closely at both.

Thanks for the suggestion.

DataNinja777
Super User
Super User

Hi @MarkD1722 ,

What about swapping "General Number" with "yyyy" so that it will be regarded as a string (text format) in your dax formula? 

Best regards,

I did try that, but it did not produce the same results as using the "0".  I would have expected your suggestion to make more sense.  Not sure why that didn't work the same way.  Thank you for the suggestion.

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.

Top Solution Authors