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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

SUM multiple month values over years

I'm trying to sum multiple month values over several years e.g. Jan 2007, Jan 2008, Jan 2009.

 

I'm using the following formula however when I try push the date forward 12 months it comes back to the orignial value e.g. (Jan 2007) + Jan 2007 instead of (Jan 2007 + Jan 2008)

 

Is there a way to achieve multiple Jan additions?

Niiru1_0-1633353749797.png

 

I am using Alberto Ferrari's "Rolling Average" file as a sample template

 

My DAX is

Aggregation 2 =
CALCULATE (

SUMX (
Sales,
Sales[Quantity] * Sales[Net Price]
),
ALLEXCEPT (
'Date',
'Date'[Month]
),DATESINPERIOD('Date'[Date],FIRSTDATE('Date'[Date]),1,MONTH))

+


CALCULATE (
SUMX (
Sales,
Sales[Quantity] * Sales[Net Price]
),
ALLEXCEPT (
'Date',
'Date'[Month]
),DATESINPERIOD('Date'[Date],FIRSTDATE('Date'[Date]),1,MONTH),EDATE('Date'[Date],12))
1 ACCEPTED SOLUTION

@Anonymous 

 

Try:

Aggregation 3 =
IF (
    ISINSCOPE ( 'Date'[Month] ),
    CALCULATE (
        SUMX ( Sales, Sales[Quantity] * Sales[Net Price] ),
        ALLEXCEPT ( 'Date', 'Date'[Month] )
    ),
    SUMX (
        FILTER (
            ALL ( Sales ),
            YEAR ( [Order Date] ) <= SELECTEDVALUE ( 'Date'[Calendar Year Number] )
        ),
        Sales[Quantity] * Sales[Net Price]
    )
)

vjaneygmsft_0-1634262764021.png

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.


Best Regards,

Community Support Team _ Janey

View solution in original post

14 REPLIES 14
v-janeyg-msft
Community Support
Community Support

Hello @Anonymous 

 

Sorry I'm late. 

Accoding to the field used in the matrix visual, I create the measure like this:

Aggregation 3 =
IF (
    ISINSCOPE ( 'Date'[Month] ),
    SUMX (
        FILTER (
            ALL ( Sales ),
            YEAR ( [Order Date] ) <= SELECTEDVALUE ( 'Date'[Calendar Year Number] )
                && MONTH ( [Order Date] ) = SELECTEDVALUE ( 'Date'[Month Number] )
        ),
        Sales[Quantity] * Sales[Net Price]
    ),
    SUMX (
        FILTER (
            ALL ( Sales ),
            YEAR ( [Order Date] ) <= SELECTEDVALUE ( 'Date'[Calendar Year Number] )
        ),
        Sales[Quantity] * Sales[Net Price]
    )
)

vjaneygmsft_1-1634191886378.png

The hierarchy context of matrix is different, so the total must be calculated separately, use isinscope() funcion.

Reference:ISINSCOPE function (DAX) - DAX | Microsoft Docs

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.


Best Regards,

Community Support Team _ Janey

Anonymous
Not applicable

This is excellent thank you very very much for the time spent on this, I'm new to the ISINSCOPE function.

 

One last question is it possible to tweak the formula to return the max value rather than cumulative?

 

 

 

 

@Anonymous  What is the logic of the maximum? The yellow part you marked is not the maximum. What should the result be.

Anonymous
Not applicable

I'm trying to get the the sum of each month across years (Total Column below(this is what I meant by the max), apologies if I haven't explained it properly.

 200720082009Total Column
Jan794248.24656766.69580901.052031915.98
Feb891135.91600080.00622581.142113797.05
Mar961289.24559538.52496137.872016965.62
Apr1128104.82999667.17678893.222806665.2
May936192.74893231.961067165.232896589.93
Jun982304.46845141.60872586.22700032.26
Jul922542.98890547.411068396.582881486.97
Aug952834.59721560.95835707.462510103.00
Sep1009868.98963437.23709610.402682916.61
Oct914273.54719792.99806738.222440804.75
Nov825601.871156109.32868164.012849875.20
Dec991548.75921709.14746933.502660191.40

Niiru1_2-1634226176391.png

 

 

I know I have these results in the column [Aggregation] (highlighted above)

 

Aggregation = 
CALCULATE (

SUMX (
Sales,
Sales[Quantity] * Sales[Net Price]
),
ALLEXCEPT (
'Date',
'Date'[Month]
))

however when I filter the year e.g. 2007 it remains as these MAX numbers where I would like the ALLEXCEPT function to be a bit more dynamic. So with no date filters applied return [Total Column] and then when I pick the year e.g. 2007 it will change to just those values

 

 2007Total Column
Jan794248.242031915.98
Feb891135.912113797.05
Mar961289.242016965.62
Apr1128104.822806665.2
May936192.742896589.93
Jun982304.462700032.26
Jul922542.982881486.97
Aug952834.592510103.00
Sep1009868.982682916.61
Oct914273.542440804.75
Nov825601.872849875.20
Dec991548.752660191.40

@Anonymous 

 

Try:

Aggregation 3 =
IF (
    ISINSCOPE ( 'Date'[Month] ),
    CALCULATE (
        SUMX ( Sales, Sales[Quantity] * Sales[Net Price] ),
        ALLEXCEPT ( 'Date', 'Date'[Month] )
    ),
    SUMX (
        FILTER (
            ALL ( Sales ),
            YEAR ( [Order Date] ) <= SELECTEDVALUE ( 'Date'[Calendar Year Number] )
        ),
        Sales[Quantity] * Sales[Net Price]
    )
)

vjaneygmsft_0-1634262764021.png

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.


Best Regards,

Community Support Team _ Janey

Anonymous
Not applicable

Create a measure based on month not at all the date. it will work I had the same issue.

Anonymous
Not applicable

Good advice. Tried this but still the same Sales vs. Date table issue.

v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

Do you want to calculate like below?

vjaneygmsft_0-1633596268437.png

You can try:

Aggregation 2 =
SUMX (
    FILTER (
        ALL ( Sales ),
        YEAR ( [Date] ) <= YEAR ( SELECTEDVALUE ( Sales[Date] ) )
            && MONTH ( [Date] ) = MONTH ( SELECTEDVALUE ( Sales[Date] ) )
    ),
    Sales[Quantity] * Sales[Net Price]
)

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.


Best Regards,

Community Support Team _ Janey

Anonymous
Not applicable

Thank you for the reply @v-janeyg-msft . I've tried to incorporate this measure into the sample but no luck. The Sales table only has an 'Sales'[Order Date] and I have been using 'Date'[Date] for the visual above but I can't bring 'Date'[Date]' into the measure:

Aggregation 2 = 

SUMX (
FILTER (
ALL ( Sales ),
YEAR ( [Order Date] ) <= YEAR ( SELECTEDVALUE (Sales[Order Date] ) )
&& MONTH ( [Order Date] ) = MONTH ( SELECTEDVALUE ( Sales[Order Date] ) )
),
Sales[Quantity] * Sales[Net Price]
)
Do I need to cross filter somehow? From your visual above is there a pbix you can share?
 
 

 

Hi, @Anonymous  

 

The picture is yours, I just ask about your needs. You didn’t provide a sample file. How could I have it? I iust wrote the code according to your description.

If you still need help, please upload some insensitive data samples and expected output, So we can help you soon.

 

Best Regards,

Community Support Team _ Janey

Anonymous
Not applicable

@Anonymous  Sorry, I'm too busy today and I will get back to you tomorrow.

amitchandak
Super User
Super User

@Anonymous , with help from date table, You can try like

example

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks @amitchandak but it's not quite what I'm looking for.

 

I'm trying to group all of them together rather than just obtain a 'Date'[Date],-1,YEAR)

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors