Forum Discussion

walker4545's avatar
walker4545
Frequent Visitor
4 years ago
Solved

Cannot convert value of type Text to type Integer.

Hi PowerBI community, 
I'm attempting to use a Switch Statement in DAX to create customised column of categories using 'Proposed Start Date' dates (in date format) for travel bookings:
 
Proposed Travel Start Half Year =
VAR PropYear = YEAR('TravelBookings'[Proposed Start Date])
VAR PropMonth = MONTH('TravelBookings'[Proposed Start Date])
VAR PropHalfYear = SWITCH(PropMonth,
1, "First Half of Year", 2, "First Half of Year", 3, "First Half of Year", 4, "First Half of Year", 5, "First Half of Year", 6, "First Half of Year", 7, "Second Half of Year", 8, "Second Half of Year", 9, "Second Half of Year", 10, "Second Half of Year", 11, "Second Half of Year", 12, "Second Half of Year", "")
VAR PropHalfYearAndYear = PropHalfYear & " " & PropYear

RETURN PropHalfYearAndYear
 
The error message that I get returned is the following:
 
Cannot convert value 'First Half of Year 2023' of type Text to type Integer.
 
Can anyone assist me with this and let me know where I'm going wrong?
 
Thanks in advance!
  • Hi walker4545 ,

     

    It looks like this is because the column previously returned values of Whole number type, causing an error when the output is text. Please select the calculated column and change the format to text.

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

3 Replies

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi walker4545 ,

     

    It looks like this is because the column previously returned values of Whole number type, causing an error when the output is text. Please select the calculated column and change the format to text.

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

  • walker4545 ,  I did not see PropSemester

     

    Also PropSemester & " " & PropYear is string to general number will not apply

     

     

    VAR PropHalfYearAndYear = PropSemester & " " & FORMAT(PropYear, "General Number")

    • walker4545's avatar
      walker4545
      Frequent Visitor

      Thanks amitchandak and apologies, I had the wrong data label included in my sample above. It's been corrected now.