cancel
Showing results for
Search instead for
Did you mean:
Frequent Visitor

## DAX for quarterly cumulative total

Hi,

I need to write dax to calculate cumulative total quarter wise, TOTALQTD function can work but as we are using live connection so time intelligence functions are not working. I have tried below DAX:

CumTotal =
CALCULATE(Sum(Table1[delta]),
ALL('Table1'),QUARTER(Table1[DATE])<=QUARTER(EARLIER(Table1[DATE]))
)

but it is giving below error:
EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

Can you please help me to achieve expected result with Dax?
1 ACCEPTED SOLUTION
Community Support

Hi @pkhandav ,

It is needed to use "FILTER" in you expression. Try this:

``````CumTotal =
CALCULATE (
SUM ( Table1[delta] ),
FILTER (
ALL ( 'Table1' ),
QUARTER ( Table1[DATE] ) <= QUARTER ( EARLIER ( Table1[DATE] ) )
)
)
``````

Or this:

``````CumTotal =
CALCULATE (
SUM ( Table1[delta] ),
FILTER (
ALL ( 'Table1' ),
QUARTER ( Table1[DATE] ) <= QUARTER ( MAX ( Table1[DATE] ) )
)
)
``````

Best Regards,

Icey

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

6 REPLIES 6
Community Support

Hi @pkhandav ,

It is needed to use "FILTER" in you expression. Try this:

``````CumTotal =
CALCULATE (
SUM ( Table1[delta] ),
FILTER (
ALL ( 'Table1' ),
QUARTER ( Table1[DATE] ) <= QUARTER ( EARLIER ( Table1[DATE] ) )
)
)
``````

Or this:

``````CumTotal =
CALCULATE (
SUM ( Table1[delta] ),
FILTER (
ALL ( 'Table1' ),
QUARTER ( Table1[DATE] ) <= QUARTER ( MAX ( Table1[DATE] ) )
)
)
``````

Best Regards,

Icey

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Responsive Resident

to use the Max function you should use variables or place it first within a Filter function

Super User IV

Try max, But datesqtd should have worked

SumTotal =
CALCULATE(Sum(Table1[delta]),
ALL('Table1'),QUARTER(Table1[DATE])=QUARTER(max(Table1[DATE])) && (Table1[DATE])=(max(Table1[DATE]))
)

This is way for non std qtr

new columns

Qtr Start Date = DATEADD(STARTOFYEAR('Date'[Date],"4/30"),QUOTIENT(DATEDIFF('Date'[Start Of Year], 'Date'[Date],MONTH),3)*3,MONTH)
Qtr Day = DATEDIFF('Date'[Qtr Start Date],'Date'[Date],Day)+1
Qtr Rank = RANKX(all('Date'),'Date'[Qtr Start date],,ASC,Dense)

measures

This Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])))
Last Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])-1))

This QTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank]) && [Qtr Day] <=max([Qtr Day])))
Last QTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])-1 && [Qtr Day] <=max([Qtr Day])))

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Frequent Visitor

Hi @amitchandak ,

Thanks for the response!

I tried below DAX:

SumTotal =
CALCULATE(Sum(Table1[delta]),
ALL('Table1'),QUARTER(Table1[DATE])=QUARTER(max(Table1[DATE])) && (Table1[DATE])=(max(Table1[DATE]))
)

and came across below error:

A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

Can you please suggest.

Responsive Resident

when you work with time intelligence functions you must have a date table in the model.

also review the DatesQTD function https://docs.microsoft.com/en-us/dax/datesqtd-function-dax

Frequent Visitor

Hi @jairoaol ,

Thanks for response!

We are using Live connection so Time intelligence functions are not supported.  We need to write DAX with basic functions in Power BI. DatesQTD function is not working.

## Helpful resources

Announcements

#### Manage your user group events

Check out the News & Announcements to learn more.

#### Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

#### Power BI Dev Camp - September 30th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

#### Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors
Top Kudoed Authors