TOTALS doesn't add up when summing data from 2 different time periods

ironfavio

New Member
Joined
Mar 13, 2016
Messages
4
I need to calculate the variation of sales volume of the current month vs the same period of the previous year.


At a product level the formula is working fine, but the subtotals and totals DO NOT ADD UP.


I have tried many approaches and techniques available on the web, but I couldn't find anything related to calculating a measure using data from different periods.


The formula basically is:
[ (Sales Qty 2016) - (Sales Qty 2015) ] * [ (Sales Amount 2015) / (Sales Qty 2015) ]


My DAX formula attempt is:
=(CALCULATE(sumx(Sales_Data,Sales_Data[Qty]))- ****Sales Qty 2016******


CALCULATE(sumx(Sales_Data,Sales_Data[Qty]),SAMEPERIODLASTYEAR(Date_Table[DateKey])))* ****Sales Qty 2015******


(CALCULATE(sumx(Sales_Data,Sales_Data[Net Sales Inc.Rebate]),SAMEPERIODLASTYEAR(Date_Table[DateKey])) / ******Sales Amount 2015******


CALCULATE(sumx(Sales_Data,Sales_Data[Qty]),SAMEPERIODLASTYEAR(Date_Table[DateKey]))) ****Sales Qty 2015******


Any way that I can calculate the subtotal and totals a per the table below.

Qty 2016Qty 2015ASP 2015Var Vol
Product A4941,031$142.11-76,315
Product B10,8887,706$428.291,362,814
Product C3311,218$215.85-191,462
TOTAL11,7209,961$372.43655,112
Should be this total-->1,095,037

<colgroup><col span="5"></colgroup><tbody>
</tbody>



Many thanks.
Favio
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Note sure where those formulas come from, but I used this...
A​
B​
C​
D​
E​
F​
3​
Qty 2016Qty 2015ASP 2015Var Vol
4​
Product A
494
1,031
$142.11
-76,315
($76,313.07)​
5​
Product B
10,888
7,706
$428.29
1,362,814
$1,362,818.78​
6​
Product C
331
1,218
$215.85
-191,462
($191,458.95)​
7​
TOTAL
11,720
9,961
$372.43
655,112
8​
9​
Should be this total-->
1,095,037
F4=(B4-C4)*D4
copied down.

Not sure where you got the values in row 7, but either way, you cannot calc the bottom-line total like that, you need to calc it by row, then sum the row totals
 
Upvote 0
Hi Ford,

Thanks for your response.

The table is an example of the results I get when using the DAX formula in my example. In every row I get the correct result, but the total does not add up. This is the issue I have for my example, I would like to now if there is any trick or different formula I need to apply to get the correct result.

Regards,
Favio
 
Upvote 0
Hi Matt,

Thanks your replying.

I indeed read your post a few days ago, but I wasn't able to solve my issue. I have tried several approaches but I cannot make the subtotals and totals work correctly.

I need this for my job, is there any additional tip you can give me.

Cheers,
Favio
 
Upvote 0
In every row I get the correct result, but the total does not add up. This is the issue I have for my example, I would like to now if there is any trick or different formula I need to apply to get the correct result.

I answered that question in the last line of my post
you cannot calc the bottom-line total like that, you need to calc it by row, then sum the row totals

Each item has a different value, so while you can calc the total for each item/row going across, the same does not apply for the bottom-line total...this MUST be the sum or each row total
 
Upvote 0
Ironfavio

DAX is not like excel. In order to give you a correct formula, I need to know the entire data model. Every table works together and hence table names, column names, joins etc all matter. But let me try to guess. You may need to change table names and/or column names.

That basic pattern you need is

Total sales = sumx(values(sales_data[product column]),calculate(sales_data[qty]))

i dont understand what you are doing with SAMEPERIODLASTYEAR as that needs a date filter to work - you don't provide any information about the filters in your pivot. It this doesn't help, I suggest you post a sample workbook. With what you have got and show what you expect the answer to be.
 
Upvote 0
Hi Matt,

I do not know if it was your advice or that today I may woke up more inspired but I finally did it. Many thanks anyway.

I would like to share my dax formulas in case it is useful for the people on this forum.

Basic formula

(Q2 - Q1) x P1 = Volume variance

Where: Q1 = Sales Quantity in period Y-1
Q2 = Sales Quantity in period Y
P1 = Average Selling Price in period Y-1

My DAX formulas are:

Q2:
=sumx(values(Sale_Data[Product]),CALCULATE(SUM(Sale_Data[Qty]),SAMEPERIODLASTYEAR(Date_Table[Date])))

Q1:
=sumx(values(Sale_Data[Product]),CALCULATE(SUM(Sale_Data[Qty])))

P1:
=sumx(values(Sale_Data[Product]),CALCULATE(SUM(Sale_Data[Amount]),SAMEPERIODLASTYEAR(Date_Table[Date])))/[Q1]

Variance:
=sumx(values(Sale_Data[Product]),([q2]-[Q1])*[P1])

Regards,
Favio
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top