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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Titatovenaar2
Advocate II
Advocate II

DAX: Running Total that doesn't Reset, with Inactive Relationship (pbix included)

Hi guys,

 

I try to calculate a running total with an inactive relationship that cumulates the data per month. It should always start from the very first moment there is data available, yet there is still a period selector to select the specific From date and To date simultaneously.

 

Currently my main measure on which I apply the Running Total is the following:

 

 

Count New Materials = 
CALCULATE(
    DISTINCTCOUNT('DIM Material'[%MaterialKey]),
    DATESBETWEEN('DIM Material'[Created On],MIN('DIM Calendar'[Date]),MAX('DIM Calendar'[Date]))
    )

 

 

 

And the running total measure I use is the following:

 

 

Count New Materials RT = 
VAR CumulativeValues = 
CALCULATE(
    [Count New Materials]
    ,FILTER(
        ALLSELECTED('DIM Calendar'[Date]),
        'DIM Calendar'[Date] <= MAX('DIM Calendar'[Date])
        )
    --,Maybe add here a USERELATIONSHIP?
    ,ALLEXCEPT ( 'DIM Calendar', 'DIM Calendar'[Month])
    )

RETURN
IF( ISBLANK( [Count New Materials] ) , 
    BLANK() ,
    CumulativeValues )

 

 

 

The data that I currently get:

Titatovenaar2_0-1620644137914.png

Data that I expect:

Titatovenaar2_2-1620644254169.png

 

And I should be able to select via the period selector a specific period, for instance if I would select: 1/1/2018 - 12/31/2019, I would expect the following to show. So the cumulative does not reset itself.

Titatovenaar2_3-1620644313828.png

 

PBIX file 

 

Any suggestions how I could solve this?

 

Kind regards,

Igor

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Yes, this solved the problem because under the hood your DAX is transformed into:

 

VAR v1 = MAX('DIM Calendar'[Date])
RETURN
CALCULATE(
    [Count New Materials],
    // This filter overwrites what's
    // coming from the outside world.
    FILTER(
        ALL( 'DIM Calendar'[Date] ),
        'DIM Calendar'[Date] <= v1
    ),
    // If your table 'DIM Calendar' is
    // marked in the model as a date 
    // table, this ALL (in your code)
    // is not necessary since the engine
    // performs this line below automatically.
    ALL('DIM Calendar')
)

 

The other one does not work because it's equivalent to this DAX:

 

var MaxDate = MAX('DIM Calendar'[Date])
return
CALCULATE(
    [Count New Materials],
    KEEPFILTERS(
        'DIM Calendar'[Date] <= MaxDate
    ),
    ALL('DIM Calendar')
)

 

KEEPFILTERS prevents the expression from reaching rows outside the current filter context and you need to be able to do it to calculate what you want.

View solution in original post

3 REPLIES 3
Titatovenaar2
Advocate II
Advocate II

Interesting stuff, reading through it to get a better understanding. Thanks.

 

Meanwhile this somehow solved the problem:

VAR v1 = MAX('DIM Calendar'[Date])
RETURN
CALCULATE(
    [Count New Materials]
    ,'DIM Calendar'[Date] <= v1
    ,ALL('DIM Calendar')
    )

/* --while the following does not work:
CALCULATE(
    [Count New Materials]
    ,FILTER('DIM Calendar', 'DIM Calendar'[Date] <= MAX('DIM Calendar'[Date]))
    ,ALL('DIM Calendar')
    )
*/
Anonymous
Not applicable

Yes, this solved the problem because under the hood your DAX is transformed into:

 

VAR v1 = MAX('DIM Calendar'[Date])
RETURN
CALCULATE(
    [Count New Materials],
    // This filter overwrites what's
    // coming from the outside world.
    FILTER(
        ALL( 'DIM Calendar'[Date] ),
        'DIM Calendar'[Date] <= v1
    ),
    // If your table 'DIM Calendar' is
    // marked in the model as a date 
    // table, this ALL (in your code)
    // is not necessary since the engine
    // performs this line below automatically.
    ALL('DIM Calendar')
)

 

The other one does not work because it's equivalent to this DAX:

 

var MaxDate = MAX('DIM Calendar'[Date])
return
CALCULATE(
    [Count New Materials],
    KEEPFILTERS(
        'DIM Calendar'[Date] <= MaxDate
    ),
    ALL('DIM Calendar')
)

 

KEEPFILTERS prevents the expression from reaching rows outside the current filter context and you need to be able to do it to calculate what you want.

Anonymous
Not applicable

Hi @Titatovenaar2 

 

First, this is incorrect

DATESBETWEEN('DIM Material'[Created On],MIN('DIM Calendar'[Date]),MAX('DIM Calendar'[Date]))

as time-intel functions DO NOT WORK on arbitrary date columns. The first argument must be a date column from a proper date table.

 

Second, if you don't want it to reset, you can't use ALLSELECTED.

 

Third, ALLEXCEPT is a tricky function and should rarely be used. Please read this to understand its use and consequences. In there you may find a way to make it right with the combination of ALL/VALUES.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.