Forum Discussion

vanessa's avatar
vanessa
Post Patron
8 years ago
Solved

Error with SAMEPERIODLASTYEAR: an invalid numeric representation of a date value was encountered

I have created a metric to calculate the sales for last year.

Below is the formula:

LastYear_Sales = CALCULATE(SUM('Fact_Sales'[SALES_AMT]),SAMEPERIODLASTYEAR('Dim_Day'[Date]))

 

when I create a table with: Date from Dim_Day and LastYear_Sales, I get the following error:

8 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Seems like it does not like your [Date] column. Is it flagged as a numeric field in the data model?

    • vanessa's avatar
      vanessa
      Post Patron

      I checked that. It is a date/time field.

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Hmm, reading the error more closely, it says MdxScript, is this a Live data source? (DirectQuery)

         

        That function is not supported in DirectQuery mode.

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

    vanessa,

     

    Based on my test, this can be caused by an invalid datetime value that exceeds the year 9999.

  • Stefan82's avatar
    Stefan82
    Regular Visitor

    I encountered the same issue when working with SAMEPERIODLASTYEAR. It seems like the date table needs to be Marked As Date Table. This did the trick for me.