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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Calculating Cumulative Sum that works with certain data fields

EDIT: Formula is working, issue is rather arrising since not all [Sales Type] values are available on all the years.
Here is an example of the issue:
You can see that sales type highlighted here in orange is not shown on all years after it first occur (see FY26) and this is what needs fixing somehow.

KK92_1-1680707359273.png

 

 



Hi, 
I`m trying to develop a calculation that returns the correct cumulative sum of field [Sales] on a stacked bar chart. 
Details are: 
(see in comments sample data)
Y-axis: [Sales] from view_metrics table 
X-Axis: [Year of first payment]   from view_scenarios table
Filter: [Sales year] from view_metrics table
Legend: [Sales Type] from view_scenarios table

The current formula I have, and works for all apart from when I add the legend is: 

Cumulative Sales =
CALCULATE (
SUM(view_metrics[Sales]),
FILTER (
ALLSELECTED( viewmetrics[Sales Year] ),
view_metrics[Sales Year]<= MAX ( view_metrics[Sales Year] )
),
ALLSELECTED( view_scenario[Year of first payment].[Year]),
view_scenario[Year of first payment]<= MAX ( view_scenario[Year of first payment] )
)

The formula works perfectly until I add the legend [Sales Type].


Any suggestions are welcomed, many thanks.

7 REPLIES 7
FreemanZ
Super User
Super User

hi @Anonymous 

How are viewmetrics and view_scenario related?

Anonymous
Not applicable

Hey @FreemanZ 
Yes they are through [sales id] columns, many (view_metrics) to one (view_scenario) relationship.
Cross filter direction: Both

hi @Anonymous 

could you paste some sample data?

Anonymous
Not applicable

Would something like this help?

View_Metrics
   
Sales IDSales YearSales
1202310
1202410
1202520
1202630
1202740
1202810
1202920
2202540
2202610
2202730
2202850
22029100
2203030
3202510
3202630
3202740
3202810
4202530
4202610
4202740

 

View_Scenario
   
Sales IDYear of first paymentSales Type
12022Direct
22023Card
32023Direct
42024Card



@Anonymous In response to your PM, I believe what you are looking for is below. PBIX file is attached below signature.

Measure = 
    VAR __IDs = DISTINCT('View_Metrics'[Sales ID])
    VAR __Year = MAX('View_Metrics'[Sales Year])
    VAR __Table = FILTER(ALL('View_Metrics'), [Sales ID] IN __IDs && [Sales Year] <= __Year)
    VAR __Result = SUMX( __Table, [Sales])
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks @Greg_Deckler for your response. 

This measure is not calculating the cumulative sum for me against [Year of first payment] on x-axis, but does work perfectly fine for the [Sales Year] on x-axis instead.
I downloaded the PBIX as well and I don`t think it`s working on there too. 

I have figured out that my issue isn`t in the measure itself but rather that some of the sales types are not present every year (please see example added to main body), and perhaps what is required is to adjust for that. 

Anonymous
Not applicable

@FreemanZ Hi there, are you able to provide any further advice?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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