Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

DATEADD "expects a contiguous selection when the date column is not unique, has gaps..."

I'm trying out some DAX functions on the following data:

I

I've set up this measure

Sales YTD = Calculate(TOTALYTD(SUM(Sales[Sale£]),Sales[OrderDate]))

and used it in the following table

Now I'd like to add in sales for the previous year, so I've created a new measure using DATEADD:

Sales LY = Calculate(SUM(Sales[Sale£]),DATEADD(Sales[OrderDate],-1,YEAR))

But when I try to add this to the above table, I get:

 

This doentn't make much sense to be.  What does it mean that "the date column is not unique" - does it expect unique date values? In the context of my example, this is nonsense as there are many orders on some days and none on many other days!

 

Please help!! 

 

 

  • Are you using the Date from the Date table in the visualisation?

  • Anonymous's avatar
    Anonymous
    7 years ago

    In the measure, yes, but not in the Table, where I use "Order Date", from the Sales table:::

     

    Sales SPLY = Calculate([Total Sales],SAMEPERIODLASTYEAR('Date Table'[Date]))

     

     

    So I've tried using the Date from "Dates Table" and it seems to work:

     

     

    I'm not entirely sure why one way works and another doesn't, I need to mug up on DAX date processing

     

9 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      This is the best solution I would say, no need to create date table.

  • HotChilli's avatar
    HotChilli
    Icon for Community Champion rankCommunity Champion

    Time intelligence works best when you have a Date table.

    Depending on your data, DATEADD won't play nicely if you don't use a Date table.  That's what the message is all about.

    In the visualisation that is complaining about the Sales LY measure, there isn't really a concept of current year and last year because there is no date field  in the table.

    You can see in the other visualisation that has 'Sales LY', and doesn't complain, that the results are patchy as there isn't  equivalent data from the day a year previous for many of the rows.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thnks for this HotChilli.

       

      I'm now trying to set up a Dates table, but am getting weird results at the first step - as you wan see from the amage below, I'm aiming to set up a dates table for all days between 2010 and 2035 but Power BI in starting my table on 23/6/1906(!) and ending  it on 16/016/1937 (!!)

       

       

      Any ideas?

       

      Thanks!

      • Anonymous's avatar
        Anonymous
        Not applicable

        Just worked out the answer to this, I've got the parameters in the wrong  order. 

         

        Duh!!