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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mike1234
Regular Visitor

Incorrect cumulative values when creating multiple line charts with multiple cumulative values

I am trying to create cumulative sales vs goal line charts by person, team and group but am having a challenge with the calculation to cumulate the sales.  Any help / ideas would be appreciated.

 

I have the two tables below:

 

  PERSONAL GOAL - Notes the 12 month sales goal for an individual and which team they are on as well as which group they are in.

  PERSONAL SALES - Notes the sales over the last 12 months for the individuals.

 

 PERSONAL GOAL 

PersonTeamGroupPerson Sales Goal
SamA1100000
JohnA1110000
JaneB1120000
SteveB190000
SusanC2130000
AnnC295000

 

 

PERSONAL SALES

PersonSales MonthMonthly Sales
Ann324900
Ann837700
Ann929900
Jane541800
Jane636400
Jane1219200
John19800
John55700
John537200
Sam224600
Sam52000
Sam1012400
Steve123700
Steve826400
Steve1117000
Susan12800
Susan310800
Susan1220100

 

My problem is when I try to calculate the cumulative sales for each of the three different charts (person, team and group) the calculations don't seem to work. 

 

I've put a "Person Index" on the table and cumulate the sales as follows:

      Person Cumulative Sales = CALCULATE (
          SUM ( 'Monthly Sales'[Monthly Sales] ),
          ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Person] ),
          'Monthly Sales'[Person Index] <= EARLIER ('Monthly Sales'[Person Index]))

 

This seems to work okay and I get the trendline below.

Person Trendline.png

 

In the same table, I sorted Team, then Month and added another index (Team Index).  Then I created the calculation below but it doesn't calculate correctly: 

 

    Team Cumulative Sales = CALCULATE (
       SUM ( 'Monthly Sales'[Monthly Sales] ),
       ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Team] ),
       'Monthly Sales'[Team Index] <= EARLIER ('Monthly Sales'[Team Index])) 

  

Note that in the resulting table below both the A5 and C3 calculations for Team Cumulative Sales are incorrect.  I believe this is because there are multiple entries for those months for that team and it isn't handling it well.  Any ideas?

 Team Data.png

 

 

If it helps, here's the merged table, showing how I merged the tables and created indexes.  If there's a better way of doing it let me know

Merged Table.png

 

Thanks, in advance.

1 ACCEPTED SOLUTION
mike1234
Regular Visitor

I came up with a solution to get around the Months that have multiple Sales records:

 

  • Use the "Merge Queries as New" function to crate a new table from the Personal Sales.  That way I don't mess with that table).
  • Used the "Group By" function to combine the sales that are in the same month.  After doing this I didn't have the problem with duplicates.   
  • Once I did that, using the statement from Phil (thanks, Phil!), I created a calculated column to create the cumulative sales, as appropriate.  

I had to do this for each of the three charts I wanted (person, team and group). and it worked.

 

Here's what I ended up with.

Sample PBIX

 

 

View solution in original post

4 REPLIES 4
mike1234
Regular Visitor

I came up with a solution to get around the Months that have multiple Sales records:

 

  • Use the "Merge Queries as New" function to crate a new table from the Personal Sales.  That way I don't mess with that table).
  • Used the "Group By" function to combine the sales that are in the same month.  After doing this I didn't have the problem with duplicates.   
  • Once I did that, using the statement from Phil (thanks, Phil!), I created a calculated column to create the cumulative sales, as appropriate.  

I had to do this for each of the three charts I wanted (person, team and group). and it worked.

 

Here's what I ended up with.

Sample PBIX

 

 

@mike1234,

 

Glad to hear that you've solved this problem. You may help accept the solution above. Your contribution is highly appreciated.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @mike1234

 

If you are doing this as a calculated column, then this might be closer to what you need

 

Team Cumulative Sales = CALCULATE (
       SUM ( 'Monthly Sales'[Monthly Sales] ),
       FILTER(ALL( 'Monthly Sales' ),
       'Monthly Sales'[Team] = EARLIER('Monthly Sales'[Team]) &&
       'Monthly Sales'[Sales Month] <= EARLIER ('Monthly Sales'[Sales Month])))

Bare in mind, you probably want to use an actual date for your Month, rather than an integer to handle when you have data for more than a single year.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks.  I pasted the formula in (as a calculated column) and here's what I get. 

 Results Test 2.png

 

It still looks like the Sales Months with multiple sales are not calculating correctly.

 

As a side note - For this use case I need to use Month as a relative month rather than actual month.  

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.