Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Terra
Contributor II
Contributor II

Add Custom Totals to Pivot Table

I have a simple table that has a list of accounts, date, and the revenue for that day. I am trying to add a custom row that sums the revenue for certain accounts. I still want to keep all columns and rows, just with the added custom row. Example below. The expression I am using is sum(revenue). How can I achieve this?

Account10/1/202110/2/202110/3/2021
A$465.00$128.00$761.00
A$234.00$567.00$197.00
A$541.00$967.00$321.00
A$843.00$456.00$112.00
B$354.00$687.00$446.00
B$426.00$239.00$799.00
B$564.00$896.00$462.00
C$765.00$489.00$475.00
C$897.00$327.00$471.00
Total$5,089.00$4,756.00$4,044.00
Custom Total for A&B$3,427.00$3,940.00$3,098.00

 

3 Replies
Almen
Creator II
Creator II

Would suggest to add custom Totals in Script so you can add the Account per usual. 

If you like to see individual amounts you need a Amount_ID as well, otherwise only sum will be visible in Pivot table.

Alternative you can create  a column per Date for the Amount in a straight table.

 

[MainTable]:
LOAD
	[Account],
	PurgeChar([44206],'$')			as Amount,
    '10/1/2021'			as Date
 FROM [YourPath]

LOAD
	[Account],
	PurgeChar([44237],'$')			as Amount,
    '10/2/2021'			as Date
 FROM [YourPath]

LOAD
	[Account],
	PurgeChar([44265],'$')			as Amount,
    '10/3/2021'			as Date
 FROM [YourPath]


Sum:
Load
'Total A&B'				as Account,
Sum(Amount)				as Amount,
Date
Resident MainTable where Account<>'C' group by Account, Date;
Terra
Contributor II
Contributor II
Author

I am looking more for an expression to do this. My date spans over years of data, not just 3 days. Thanks

Almen
Creator II
Creator II

You can't add custom rows as far as I'm aware of. However, you could try using ValueList() to create a custom dimensions and apply custom measurements.

 

It would be something like this:

Create a variable: 

 

vDim

=Chr(39)&'Total'&Chr(39)&','&Chr(39)&'Total A&B'&Chr(39)&','&Concat(Distinct chr(39)&Account&chr(39), ',')

 

 

Create a Pivot Table and as Dimension choose ValueList($(vDim))

As Measurement use 

 

=Pick(Match(ValueList($(vDim)), $(vDim)),
Sum(Revenue), //Total
Sum({<Account-={'C'}>} Revenue), //For Total excluding Account C
Sum({<Account={"$(=Pick(3, $(vDim)))"}>} Revenue), //individual sums
Sum({<Account={"$(=Pick(4, $(vDim)))"}>} Revenue),
Sum({<Account={"$(=Pick(5, $(vDim)))"}>} Revenue)) 

 

 

I don't know the amount of Accounts you have in your Data but if it's not in the hundreds you can repeat the function and increase the value of pick by  1 each time.