+ Reply to Thread
Results 1 to 6 of 6

DAX Measure Running Total last 7 values non consecutive dates

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

    DAX Measure Running Total last 7 values non consecutive dates

    Hi,
    I would like to calculate the last X ( eg 7) number of units using

    I have managed to get some way in this with Power query or DAX using the dates from sales table but I would like to reproduce the measure I have
    but to work with the Calendar table ;

    I want to Calculate a running total for the last 7 units ; in PQ I used SelectRows ;
    Please Login or Register  to view this content.

    In DAX I started by summing the dates and then ranking them ;

    Sumdate:=SUMX( Table3, Table3[Date])

    Then using as them in running total measure ;

    Please Login or Register  to view this content.
    And then bewtweenn two rankings

    Please Login or Register  to view this content.
    So is there a way I can get this to work but for the 'calendar' table ? I have attached workbook with PQ, and DAX pivot.

    Richard.
    Attached Files Attached Files

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

    Re: DAX Measure Running Total last 7 values non consecutive dates

    If you use Calendar[Date] in the pivot table, not the Date from Table3, then:

    =VAR curDate = MAX('Calendar'[Date]) VAR prev7 = TOPN(7,FILTER(SUMMARIZE(ALL('Calendar'),'Calendar'[Date],"UnitSum",[TotalUnits]),'Calendar'[Date]<=curDate&&NOT(ISBLANK([UnitSum]))),'Calendar'[Date],DESC)
    RETURN
    IF(ISBLANK([TotalUnits]),blank(),CALCULATE([TotalUnits],prev7))
    Everyone who confuses correlation and causation ends up dead.

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

    Re: DAX Measure Running Total last 7 values non consecutive dates

    Thanks, not had a chance to work through it properly, yesterday I thought about using topn, i also thought about trying
    a countrows and allselected,

    One think I did find and I've found similar before, is that in m mine using the dates from 'Table', this works where the rank is a VAR

    Please Login or Register  to view this content.
    )
    )


    But if you make the RANKX a measure and then use it you get the total,

    Please Login or Register  to view this content.






    Richard

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

    Re: DAX Measure Running Total last 7 values non consecutive dates

    I did not doubt it would work, but yes, fed tired the first part in studio to get back 7 row table;

    I'm not sure about the last ; IF(ISBLANK([TotalUnits]),blank(),CALCULATE([TotalUnits],prev7))

    if [total] = blank return blank

    re previous response about Measure v VAR ; is the measure outside the current filter context so the total is returned.

    Richard.

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

    Re: DAX Measure Running Total last 7 values non consecutive dates

    Quote Originally Posted by Dicken View Post
    I'm not sure about the last ; IF(ISBLANK([TotalUnits]),blank(),CALCULATE([TotalUnits],prev7))
    If using the calendar date field in the pivot, the measure will return a value for all dates otherwise.

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

    Re: DAX Measure Running Total last 7 values non consecutive dates

    Thanks, perhaps my new year resolution should be to properly read Mr R & S's Definitive Guide.

    RD

+ 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: 0
    Last Post: 09-21-2022, 09:10 AM
  2. Power Pivot running total measure by criteria
    By Dicken in forum Office 365
    Replies: 0
    Last Post: 09-17-2022, 11:25 AM
  3. [SOLVED] Formula finds the max number of consecutive times and the Total of consecutive values
    By rayhen in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-01-2021, 03:06 AM
  4. Measure Consecutive days using Sumproduct
    By Lorens29 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-24-2020, 06:27 AM
  5. Pivot Table: Grand Total different measure from Column measure
    By chinneywow in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-07-2019, 06:22 AM
  6. Running total of a measure DAX
    By Hassan1977 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 12-29-2017, 10:32 AM
  7. Running Total with dates
    By cronerd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-24-2013, 12:10 AM

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