Search code examples
excelexcel-pivot

Excel Pivot Table IF Statement


What I'm trying to do is, I have on the sheet of multiple dates (report dates) in column A and a transition date column in column E. From B - D I have numbers in each column corresponding with actual price then fees. What happens in this is sheet is reports come in and get transitioned on a specific date and switches fees from Column C (Before Transition Date) to Column D (After Transition Date). What I want to do with the Pivot table is this: I want to be able to add column B & C but when the item hits the transition date to switch over to adding B & D and continues the SUM of it all. My thought process is it would have to do a IF statement, something along the lines of

IF(Transition Date >= Date, Add B & C, IF(Transition Date <= Date, Add B & D),0)

But I could be wrong, just trying to figure this part out on a Pivot Table. Again I am new with Pivot Tables so if my terminology is incorrect please correct me.


Solution

  • If i have understood you correctly you want to add a calculated field to your pivot.

    Say your data looked like this Range("A1:E4") in image:

    Image of data and pivot

    You would add a calculated field to the pivot (Starting row 13 in image) using the following formula:

    =IF(Date < TransitionDate, Cost + 'Ore Fee', Cost + 'Mineral Fee')
    

    This equates to:

    =IF(ReportDate < TransitionDate, ColB + BeforeTransitionDate, ColB + AfterTransitionDate)
    

    Your mileage on layout may vary as i am using an old mac which is not ideal for pivottables and i have hidden some irrelevant pivot fields.

    Windows machine i think you add a calculated field by selecting a cell inside the pivot, the going to Analyze -> Fields, Items, & Sets -> click the little down arrow -> Calculated Field. Example here

    Layout of pivot:

    Approximate pivottable layout (using Mac)

    Where to enter calculated field:

    Calculated field

    And comparing with in sheet formulas without pivottable see Column H rows 14:16 (formula i gave from the comments):

    Comparing pivot with in sheet formulas