Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

cumsum of weekly dax measure

hey team,
i hope you are doing well!
i've created a dax measure to get the last 12 weeks sales based on a slicer selection.
below is the weekly sales measure : 

Sellout_weekly = 
VAR _selyear = SELECTEDVALUE(weeksTable[year])
VAR _weekNum = SELECTEDVALUE(weeksTable[Week])
VAR _previousYear = _selyear - 1
VAR _weeksToGoBack = 12

-- Calculate the maximum week of the previous year (assuming it might be 52 or 53 weeks)
VAR _maxWeekPreviousYear = MAXX(FILTER(ALL(weeksTable), weeksTable[year] = _previousYear), weeksTable[Week])

-- Check if we need to go back to the previous year
VAR _isCrossYear = _weekNum <= _weeksToGoBack

-- Calculate the week range for both current year and previous year
VAR _StartWeekCurrentYear = IF(_isCrossYear, 1, _weekNum - _weeksToGoBack + 1)
VAR _StartWeekPreviousYear = _maxWeekPreviousYear - (_weeksToGoBack - _weekNum)

RETURN
CALCULATE(
    [Sellout],
    FILTER(
        SALES_SUMMARY_VIEW,
        (
            -- Handle the weeks from the current year
            (SALES_SUMMARY_VIEW[Week] <= _weekNum && SALES_SUMMARY_VIEW[Week] >= _StartWeekCurrentYear && SALES_SUMMARY_VIEW[Year] = _selyear)
        ) ||
        (
            -- Handle the weeks from the previous year if we need to go back
            _isCrossYear && SALES_SUMMARY_VIEW[Week] >= _StartWeekPreviousYear && SALES_SUMMARY_VIEW[Week] <= _maxWeekPreviousYear && SALES_SUMMARY_VIEW[Year] = _previousYear
        )
    )
)

 I have created another measure called weekly ecoulement which is : WeeklySellout - WeeklySellin

ps. weekly sellin is the same measure above but with sum(QTY_sellin)

now i want to get the cummulative ecoulement. (cumsum of ecoulement)

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Do you want to get 31,53,66 in cummulative ecoulement column?

 

I recommend that you get the previous time range based on the current time range, the current range of weeks should have a rule to follow, or are they values for a column in your table? I recommend that you provide your pbix file (does not contain sensitive data), it will help us understand the problem better.

vmengmlimsft_0-1729496296091.png

 

You can also refer to this method first, assuming that each time range has a corresponding sequence number, and the sequence numbers are separated by 1.

columnsum = 
VAR current_week_range = MAX('Table'[WeekRange])
VAR last_week_range = current_week_range-1
VAR last_weekly_ecoulement = IF(ISEMPTY(FILTER(ALL('Table (2)'),'Table[WeekRange]=last_week_Range)),0,CALCULATE([weekly_ecoulement],'Table'[WeekRange]=last_week_range))
RETURN last_weekly_ecoulement +[weekly_ecoulement]

 

 

Best regards,

Mengmeng Li

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

Do you want to get 31,53,66 in cummulative ecoulement column?

 

I recommend that you get the previous time range based on the current time range, the current range of weeks should have a rule to follow, or are they values for a column in your table? I recommend that you provide your pbix file (does not contain sensitive data), it will help us understand the problem better.

vmengmlimsft_0-1729496296091.png

 

You can also refer to this method first, assuming that each time range has a corresponding sequence number, and the sequence numbers are separated by 1.

columnsum = 
VAR current_week_range = MAX('Table'[WeekRange])
VAR last_week_range = current_week_range-1
VAR last_weekly_ecoulement = IF(ISEMPTY(FILTER(ALL('Table (2)'),'Table[WeekRange]=last_week_Range)),0,CALCULATE([weekly_ecoulement],'Table'[WeekRange]=last_week_range))
RETURN last_weekly_ecoulement +[weekly_ecoulement]

 

 

Best regards,

Mengmeng Li

Anonymous
Not applicable

Hamza_Ghannem_0-1729163263193.png

not working 

Bibiano_Geraldo
Super User
Super User

Hi, please try the following DAX

CumulativeEcoulement = 
VAR _selyear = SELECTEDVALUE(weeksTable[year])
VAR _weekNum = SELECTEDVALUE(weeksTable[Week])

RETURN
CALCULATE(
    [WeeklyEcoulement],
    FILTER(
        ALL(weeksTable),
        -- Accumulate from the start of the selected year and week
        (
            weeksTable[year] = _selyear && weeksTable[Week] <= _weekNum
        ) ||
        -- Accumulate from previous years if needed
        (weeksTable[year] < _selyear)
    )
)

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.