Forum Discussion

Amerivike's avatar
Amerivike
Icon for Advocate II rankAdvocate II
6 years ago
Solved

Average Sales Per Account Per Week With TImeline

My data set looks like this except I have all states, 60,000 accounts and dozens of products:

StateAccountDateProductVolume
TexasAcct A1/1/2020Prod 16
TexasAcct A1/7/2020Prod 25
TexasAcct A1/7/2020Prod 14
TexasAcct A1/14/2020Prod 18
TexasAcct A1/14/2020Prod 38
TexasAcct A1/14/2020Prod 29
TexasAcct A1/21/2020Prod 312
TexasAcct A1/21/2020Prod 216
TexasAcct A1/28/2020Prod 114
TexasAcct B1/1/2020Prod 215
TexasAcct B1/1/2020Prod 112
TexasAcct B1/7/2020Prod 36
TexasAcct B1/14/2020Prod 311
TexasAcct B1/14/2020Prod 13
TexasAcct B1/21/2020Prod 315
TexasAcct B1/21/2020Prod 28
TexasAcct B1/21/2020Prod 16
TexasAcct B1/20/2020Prod 24
TexasAcct B1/28/2020Prod 13

 

The output I am looking for is the average volume per week for a product in a state with a timeline slicer. The basic math is:
volume/accounts/total weeks.

 

I can calculate the volume and number of stores just fine. The difficulty is that only the weeks after the product is shipped to an account counts. If I were looking for this information for product 3, Account A would be 20 (volume)/3 (weeks) and Account B would be 32/4 (got the product 1 week before account A) so Texas would be 52 (volume)/7 (weeks)/2 (accounts). All weeks after the first week would count. 

I tried using a summarize function to calculate the weeks with datediff and it works, but I loose the functionality of the timeline slicer that way:

 

Number of Weeks Distribution =

SUMMARIZE('Data','Data'[ID],"Total Weeks",
DATEDIFF(CALCULATE(FIRSTDATE('Data'[WeekEndDate]),
'Product Hierarchy'[Major_Manufacturer]="Product A",
'Data'[Shipment_Volume]>0),
MAX('Data'[WeekEndDate]),WEEK)+1))

 

Any help is appreciated!

  • I think I'm getting close, but I'm not clear on when To or Not To include Accounts in the Math?  I think the 'KEY' to fixing this is to create a NEW Measure of 'Weeks' ahead of time that looks at the MIN and MAX Dates (whether by Slicer or by Product / Account if in a Final Table / View?

         Weeks = WEEKNUM( MAX( 'Table'[Date] ), 2) - WEEKNUM( MIN ( 'Table'[Date] ), 2 ) + 1
     
    This will help to 'limit' the Weeks by Product (or Whatever Slicer you use?)  Then you can use the 'Weeks' Measure in your Final calcuation to take
     
    Measure = CALCULATE( SUM( 'Table'[Volume]) / [Weeks] / DISTINCTCOUNT('Table'[Product]))
     

     

    Let me know if this is on the right path, and what else you need to finish off the code?

     

    Thank You,

    Forrest

5 Replies

  • fhill's avatar
    fhill
    Icon for Resident Rockstar rankResident Rockstar

    I think I'm getting close, but I'm not clear on when To or Not To include Accounts in the Math?  I think the 'KEY' to fixing this is to create a NEW Measure of 'Weeks' ahead of time that looks at the MIN and MAX Dates (whether by Slicer or by Product / Account if in a Final Table / View?

         Weeks = WEEKNUM( MAX( 'Table'[Date] ), 2) - WEEKNUM( MIN ( 'Table'[Date] ), 2 ) + 1
     
    This will help to 'limit' the Weeks by Product (or Whatever Slicer you use?)  Then you can use the 'Weeks' Measure in your Final calcuation to take
     
    Measure = CALCULATE( SUM( 'Table'[Volume]) / [Weeks] / DISTINCTCOUNT('Table'[Product]))
     

     

    Let me know if this is on the right path, and what else you need to finish off the code?

     

    Thank You,

    Forrest

    • Amerivike's avatar
      Amerivike
      Icon for Advocate II rankAdvocate II

      Hey Forest...this is super close. There is one problem. It is only counting the number of weeks that the account actually recieved product. I need the average to be from the first time they recieved the product to the Max selected date whether they received the product or not. Does that make sense?

      • Amerivike's avatar
        Amerivike
        Icon for Advocate II rankAdvocate II

        Actually that only can be the case when I get super granular in the data, which is not what this is meant to be as these measures will stay at the state or a higher level so this will work perfectly! You are awesome Forrest!

         

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

    Amerivike - I'm not 100% clear on what the expected output from your sample data would be. Can you share what you are going for?