+ Reply to Thread
Results 1 to 5 of 5

Power Pivot DAX average calculation of a time period

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    768

    Power Pivot DAX average calculation of a time period

    Hi,
    i'd like to calculate the average of a cumulative figures by a given time interval, so example 7 days, so the total for a rolling 7 day period would be divided by 7, not the number of figures in that interval;

    So if between 11th and the 17th there were 2 returns that that would be the total divided by 7 not 2.

    Just dividing by 7 is fine once you have more than seven dates, in excel I'd use ROW() inside an if statement as the divosor;


    =IF( ROW(1:1)<7, 
    
                      SUMIFS([Sales],[Date],"<="&[@Date],[Date],">"&[@Date]-7)/ROW(1:1)
    
                                                                                    ,SUMIFS([Sales],[Date],"<="&[@Date],[Date],">"&[@Date]-7)/7)

    I've been trying to come up with something similar in DAX, but can't find a function similar to ROW() ,

    is there a way around this I was going to try datesbetween but if anyone has any suggestions ( helpfull 😀 )

    workbook attached.

    Richard
    Attached Files Attached Files

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Pivot DAX average calculation of a time period

    maybe

    https://learn.microsoft.com/en-us/dax/row-function-dax

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,966

    Re: Power Pivot DAX average calculation of a time period

    If you use your calendar date column in the pivot, then you could use a measure like:

    Rolling 7 day Average:=VAR mdate = MAX('Calendar'[Date]) 
    VAR ApplicRows = FILTER(ALL('Calendar'[Date]),'Calendar'[Date]<= mdate  
    && 'Calendar'[Date] >mdate-7 )
    VAR Divisor = If(COUNTROWS(ApplicRows)<7,COUNTROWS(ApplicRows),7)
    VAR anser  =
    if(countrows(Non_Consec)>0,CALCULATE([Tsales NC],ApplicRows)/Divisor,blank())
    
    RETURN anser
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    768

    Re: Power Pivot DAX average calculation of a time period

    BTW, I did realize after posting I'd overcomplicated, and I could use the count for everything, I just had the excel structure on the brain.

    Richard.

  5. #5
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    768

    Re: Power Pivot DAX average calculation of a time period

    I've used this but will go through your suggestion,


    7 day rolling:=VAR mdate = MAX('Calendar'[Date]) 
    VAR anser = 
    CALCULATE([Tsales],DATESINPERIOD('Calendar'[Date],mdate-6,7,DAY))
    RETURN anser

    Then to get 1,2,3,4,5,6 and then 7 onwards,

    count:=VAR mdate = MAX('Calendar'[Date]) 
    VAR drange = DATESBETWEEN('Calendar'[Date],mdate-6,mdate ) 
    RETURN 
    COUNTROWS(drange)
    and lastly

    Rolling Avg by Count:=VAR div1 = [7 day rolling] / [count]
    VAR count1 = [count]
    VAR anser2 = [7 day rolling]/7
    RETURN
    IF(count1 <7 ,div1,anser2 )

    Seem to work, I'll let you know how I get on with your suggestion,

    Richard.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 12-17-2021, 08:41 AM
  2. [SOLVED] Average value for a given time period applied to all previous time periods
    By fpkid1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-27-2021, 11:52 AM
  3. Hourly calculation over a period of time
    By soodaakash04 in forum Excel General
    Replies: 10
    Last Post: 04-03-2020, 03:42 PM
  4. Replies: 2
    Last Post: 02-03-2017, 07:39 AM
  5. Replies: 11
    Last Post: 05-20-2011, 02:09 PM
  6. Specific time period calculation from a time range
    By Khaldon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2011, 06:44 AM
  7. [SOLVED] Time calculation for a givenn period
    By KT in forum Excel General
    Replies: 1
    Last Post: 04-27-2005, 01:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1