Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX to Format a Slicer

Hello, I have a FundingDate column in my table. 

 

I wanted to add a year slicer from that date column like below

 

 

I wanted to display current year as YTD ie (2022 as YTD)

 

I wrote 3 calculated columns

 

Cal_Year = Year(FundingDate)

CurrentYear =  Year(Today())

FormattedYear =  if( cal_year = currentYear, "YTD", cal_year) -- this calculated column throws an error saying expressions that yield variant data type cannot be used to define calculated columns.

 

How do i resolve this issue?

 

Please Help

Ashish_Mathur 

 

Thanks,

Dharani

 

  • Try this formule:

    FormattedYear = if([CurrentYear]=[Cal_Year_],"YTD", LEFT('Table'[Cal_Year_],4))

3 Replies

  • Hi Anonymous , the reason is because in the column you are throwing text and date, the solution can be this:

    FormattedYear = if([CurrentYear]=[Cal_Year_],"YTD",format('Table'[Cal_Year_],"YYYY"))

    Best regards

    • Anonymous's avatar
      Anonymous
      Not applicable

      If i use this, for 2022 its showing YTD and for the rest of the years its showing 1905

      • Bifinity_75's avatar
        Bifinity_75
        Icon for Solution Sage rankSolution Sage

        Try this formule:

        FormattedYear = if([CurrentYear]=[Cal_Year_],"YTD", LEFT('Table'[Cal_Year_],4))