Add calculated item in pivot table from different items in the same field

MGadAllah

Board Regular
Joined
Apr 13, 2008
Messages
62
Office Version
  1. 365
Platform
  1. Windows
I tried to add a calculated item in pivot table from different items in the same field and the items belong to different sections or parts, but all used items belong to the same field or same column, but always give wrong result.
What is the right way to do so?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
If the source is Power Query, yes. You'd add an Index column, and then add a custom column with the value of the source column referencing the row by the Index number.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="GDPC1"]}[Content],
    PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    AddedIndex = Table.AddIndexColumn(PromotedHeaders, "Index", 0, 1, Int64.Type),
    AddedCustom = Table.AddColumn(AddedIndex, "Previous Quarter", each if [Index]>0 then AddedIndex[value]{[Index]-1} else null)
in
    AddedCustom

End up with this:
1669385286659.png


Just change the offset (-1 in the [Index]-1 part of the M code) if you need to go further back, or a plus value if you need to go ahead. Note the code above prevents the error that would occur for row 1 by not executing if [Index]=0. Adjust to prevent errors or just replace the errors that can be expected with null.

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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