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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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
Icey
Community Support
Community Support

Hi @Anonymous ,

 

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.

View solution in original post

6 REPLIES 6
Icey
Community Support
Community Support

Hi @Anonymous ,

 

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.

jairoaol
Impactful Individual
Impactful Individual

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

amitchandak
Super User
Super User

@Anonymous ,

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])))

Anonymous
Not applicable

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.

jairoaol
Impactful Individual
Impactful Individual

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

Anonymous
Not applicable

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors