Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

DateValue in combination with Selectedvalue

Hi guys I need to do a calculation for a specific month e.g. april but the year is based on the selected year. I get an error : "Cannot convert value '01/04/' of type Text to type Date" My DAX: CALCULATE( [Revenue act]; DATESINPERIOD('Date'[Date]; DATEVALUE( "01/04"&"/"&selectedvalue('Date'[Year]) );1;MONTH)) If I instead of the selected Value put in the following it works fine: CALCULATE([Revenue act]; DATESINPERIOD('Date'[Date]; DATEVALUE("01/04/2019"); 1;MONTH)) What am I doing wrong?
  • Hi Anonymous 

    In your formula,"01/04" is text format,but selectedvalue('Date'[Year]) is number format.They are different types.

     

    DATEVALUE( "01/04"&"/"&selectedvalue('Date'[Year]) )

    You may change the above to below formula.They should be in same number format.

     

    DATE( selectedvalue('Date'[Year]);4;1 )

    Regards,

1 Reply

  • v-cherch-msft's avatar
    v-cherch-msft
    Microsoft Employee

    Hi Anonymous 

    In your formula,"01/04" is text format,but selectedvalue('Date'[Year]) is number format.They are different types.

     

    DATEVALUE( "01/04"&"/"&selectedvalue('Date'[Year]) )

    You may change the above to below formula.They should be in same number format.

     

    DATE( selectedvalue('Date'[Year]);4;1 )

    Regards,