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
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
Employee
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
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.