Forum Discussion

mur2za's avatar
mur2za
Frequent Visitor
10 years ago
Solved

Function 'DATEADD' only works with contiguous date selections - WoW sales calculation

Hello all,   Trying to calculate WoW Change for my sales for the most recent two weeks. This works fine when I have less than one year of data. However, the moment I add in prior year data for the ...
  • mur2za's avatar
    mur2za
    10 years ago

    Thanks guys!

     

    kcantor, I tried doing the custom column like you suggested, but it didn't work for me - I was probably making some rookie mistake. However, I figured it out by just creating a page level date filter that restricted all the visualizations and calculations on that page to the last 2 weeks, so no longer getting the contiguous dates error. Not the most elegant solution, but it worked!

     

    Thanks to Sean and GilesWalker for showing me this solution on a related issue, which I was able to apply to this problem... Here's what I did:

    First, create the following measures and columns in the Calendar file:

    1. Column - WeekEnding = ((7-DayInWeek) + DateKey)

    2. Measure - Today = DATE(YEAR(NOW()), MONTH(NOW()), DAY(NOW()))

    3. Column - Last14Days = IF(AND(Calendar[WeekEnding]>=Calendar[Today]-14, Calendar[WeekEnding]<=Calendar[Today]),1,0)

    Next, create the following measures in your data file:

    1. SalesToDate = SUM(SalesTable[Sales])

    2. SalesPreviousWeek = CALCULATE([SalesToDate], DATEADD(SalesTable[SaleDate], -7, DAY))

    3. SalesLastWeek = SalesTable[SalesToDate] - SalesTable[SalesPreviousWeek]

    4. WoWSalesChange = (SalesTable[SalesLastWeek]/SalesTable[SalesPreviousWeek])-1....... format this as percentage.

     

    Now, use Last14Days as a Visual (or if you need to apply to multiple elements, then Page level) Filter. Boom - no more contiguous date error!

     

    Thanks again!

     

    Mur2za.