Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Sum last week by time

Hi guys,

 

I'm trying calculate the sales from last week by time and Week Day,

If today is Sunday on 10AM, I need know how much we sell on last Sunday on 10AM.

Example:

 

TIME     TODAY     LAST WEEK ON THIS DAY WEEK

12PM     1000         2000

13PM     1350         1000

 

TOTAL:  2350          3000

 

To calulate time, I created an calculate columm like this TIME = HOUR(dDate)

To calulate sales from today, I created:

 

TODAY = CALCULATE(SUM(dBase[SALES]),dBase[DATE] = TODAY())
 
To calculate sales from last week is the problem. I use a dax function like this:
 
LAST WEEK  = CALCULATE(SUM(dBase[SALES]),
FILTER(ALL(dBase),
[Week Number] = SELECTEDVALUE(dBase[WEEK NUMBER])-1 &&
[Week day] = SELECTEDVALUE(dBase[WEEK DAY])&&
[TIME] = SELECTEDVALUE(dBase[TIME])))
 
This works perfectly, but, I need defined an filter to Today.
Because, without this filter Today, I always will need filter the date.
I need this function to be like the function "Today", when I don't need defined the day, it always today vs last week on this day week.
 
To solve this, I tried filter my function adding an Filter function on DATE = TODAY() like this:
 
LAST WEEK  = CALCULATE(SUM(dBase[SALES]),
FILTER(ALL(dBase),
[Week Number] = SELECTEDVALUE(dBase[WEEK NUMBER])-1 &&
[Week day] = SELECTEDVALUE(dBase[WEEK DAY])&&
[TIME] = SELECTEDVALUE(dBase[TIME])), FILTER(dBase, dBase[DATE] = TODAY()))
 
But, this function dosen't work.
 
Can you help me?
 
Thank you.
 
 
This don't work correctly, becau
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Anonymous ,

     

    Try to modify your measure as below :

     

    LAST WEEK  = CALCULATE(SUM(dBase[SALES]),
    FILTER(ALL(dBase),
    [Week Number] = SELECTEDVALUE(dBase[WEEK NUMBER])-1 &&
    [Week day] = SELECTEDVALUE(dBase[WEEK DAY])&&
    [TIME] = SELECTEDVALUE(dBase[TIME])), FILTER(ALL(dBase), dBase[DATE] = TODAY()-7))
     

     

     


     
    Best Regards,
    Kelly
    Did I answer your question? Mark my post as a solution!

3 Replies