pivot table filter by Row where either of 2 Column values <>0

craigexcel

Active Member
Joined
Jun 28, 2006
Messages
298
Office Version
  1. 2016
Platform
  1. Windows
I have multiple pivot tables (PT) in a workbook, which are all based on the same source data. Each pivot table is identical except for the unit acronym used in the Report Filter. I just noticed an issue with one of them, and have searched for a while now, without success. I'm certain one of you will be able to a different way to get to a solution. I update the pivot tables via VBA, but I'm pretty sure I can figure that part out if you can help with the 'how to' part.

Each PT has 1 Report Filter, 1 Column (Period, as in Mmm-yy), 2 Rows (GL Account, and Trading Partner acronym), and 1 Value (Sum of Amount). The Columns field actually reports 2 Periods: Dec-17 and Jun-18. I have also added a Calculated Item which subtracts Dec-17 values from Jun-18 values (which is labeled "variance").

The issue I found is this: I have applied a Value Filter to the 'Trading Partner' Row, where "Sum of Amount" <> 0. As I now see, this actually only applies to the "Sum of Amount" values for the Jun-18 field. However, if the Dec-17 field shows a value, but the Jun-18 fields does not, I still need for that Trading Partner acronym to display in the PT. So, ONLY if both Periods' values = 0 do I want that Trading Partner to be hidden in the PT.

Do you know a way to display any Trading Partner if EITHER Period, i.e. "OR") has a value <> 0?

Im using Office 365.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Thanks for your reply sheetspread. I just did a quick addition to a pivot table, but I can't see how that moves me further along. I still would only be able to Filter Values, based on the Trading Partner 'Row', of the "Sum of Amount". I still can't sort by values from both Periods. Am I missing something?
 
Upvote 0
If the sum is 0 and there are no negatives, then all of the months must be 0. Can't you filter that way?
 
Upvote 0
Not exactly. The "variance" (Calculated Item) may not always be 0, nor would it always be positive. The Dec-17 and Jun-18 "Period" values could be either, and therefore, the "variance" could be either positive or negative. In one of the instances where this issue comes into play, the Dec-17 value = 4000, while the Jun-18 value = 0, which returns a "variance" of (4000). I still want that to appear in the pivot table. The "Filter Value" doesn't show the "variance" Calculated Item as an item to filter on, so that's where I'm stuck.
 
Upvote 0
Here are some lines I wrote without seeing your date grouping, etc. If they don't help we can try something else:


Excel 2010
ABCDEFGH
1NameDateNumber
2QDecember87Sum of NumberColumn Labels
3QJune0Row LabelsDecemberJuneFormula1
4QDecember0E00
5QJune87Q87870
6QDecember0R9695-1
7WJune52T8315269
8WDecember0U000
9EJune0W05252
10RDecember6Y69-69
11RJune95
12RDecember90
13RJune0
14RDecember0
15TJune72
16TDecember0
17TJune42
18TDecember83
19TJune38
20YDecember69
21UJune0
22UDecember0
23UJune0
Pivot


Code:
Sub hidepairsofzeroes()
Dim pt As PivotTable
Dim i As PivotItem
Set pt = Sheets("Pivot").PivotTables(1)
For Each i In pt.PivotFields("Name").PivotItems
If pt.GetPivotData("Number", "Name", i.Name, "Date", "June") = 0 And pt.GetPivotData("Number", "Name", i.Name, "Date", "December") = 0 Then
i.Visible = False
End If
Next i
End Sub


Excel 2010
EFGH
2Sum of NumberColumn Labels
3Row LabelsDecemberJuneFormula1
4Q87870
5R9695-1
6T8315269
7W05252
8Y69-69
Pivot
 
Upvote 0
Many many thanks sheetspread! The results of your ad hoc spreadsheet and pivot table are exactly the outcome I'm looking for! Perfect interpretation. Now I just need to incorporate your code into the existing code, and that should do it. Another view from a different angle always helps get it done. Thanks!
 
Upvote 0
So, getting the VBA right is proving to be a bit problematic. Here's what I have so far, in the If statement that compares the "Dec-17" ("Period") column to the "Jun-18" ("Period") column. (These Period values are formatted this way in the source table, and in the pivot table. Both use "1" as the day, but it's just not displayed.)

In the following line, the editor indicates a ")" is missing, but I can't see where. I think I have seen, and have read, before, that sometimes the error description isn't necessarily accurate. Is that what's missing? Or, do I need some additional double quotes when writing this as code, instead of a formula? Or, something else? Also, I took a guess that I could reference the DATE value in the way I did, but don't know if that's accurate.
[C6] is where "Dec-17" is located (in the pivot table).
[D6] is where "Jun-18" is located (in the pivot table).

Code:
    If pt.GetPivotData("AMOUNT_DC:0BALANCE","$A$5","Period",DATE(YEAR(ws.Range("C6")),MONTH(ws.Range("C6")),DAY(ws.Range("C6"))), "GL_ACCOUNT:0GL_ACCOUNT",2090000,"TRAD_PART:0PCOMPANY", i.Name) = 0 & _
        And pt.GetPivotData("AMOUNT_DC:0BALANCE","$A$5","Period",DATE(YEAR(ws.Range("D6")),MONTH(ws.Range("D6")),DAY(ws.Range("D6"))), "GL_ACCOUNT:0GL_ACCOUNT",2090000,"TRAD_PART:0PCOMPANY", i.Name) = 0 Then

Also, I just realized, since there will always be multiple (4) "GL_ACCOUNT:0GL_ACCOUNT" numbers, including 2090000, that will need to be dynamic too. Pivot table shows "GL_ACCOUNT:0GL_ACCOUNT" as the 1st Row in Column A, followed by "TRAD_PART:0PCOMPANY" as the 2nd Row. in Column B. The pivot table is formatted to display "GL_ACCOUNT:0GL_ACCOUNT" in each row of the pivot table, to facilitate LOOKUPS elswhere in the worksheet. So the pivot table displays as: x rows of 1st G/L account number, followed by related "TRAD_PART:0PCOMPANY" acronyms, followed by "Dec-17" "AMOUNT_DC:0BALANCE" values, followed by "Jun-18" "AMOUNT_DC:0BALANCE" values, followed by the "variance" column.

Any thoughts for the proper syntax??
 
Last edited:
Upvote 0
Here's a typical pivot table from the workbook. The "AATN" Trading Partner is the issue here, since each GL Account has a value for Dec-17, but none for Jun-18. My current methodology 'hides' these, since filtering by 'sum of amount...' only takes into account the Jun-18 values.



Book1
ABCDE
3ASSIGNMENT:0ALLOC_NMBRAADO
4
5Sum of AMOUNT_DC:0BALANCEPeriod
6GL_ACCOUNT:0GL_ACCOUNTTRAD_PART:0PCOMPANYDec-17Jun-18variance
72090000AA11(8,577,429.19)(8,878,897.30)(301,468.11)
82090000AA120.00
92090000AA130.00
102090000AA160.00
112090000AA33(472,397.68)(293,905.64)178,492.04
122090000AA380.00
132090000AA400.00
142090000AACI(2,836.36)(2,836.36)
152090000AADC(37,149.80)(21,495.04)15,654.76
162090000AAIB(54,788,390.57)(54,089,414.34)698,976.23
172090000AATN4,408.32(4,408.32)
182090000AATR0.00
192090000DACH0.00
202090000 Total(63,870,958.92)(63,286,548.68)584,410.24
216510000AA111,887,034.421,953,357.4466,323.02
226510000AA120.00
236510000AA130.00
246510000AA160.00
256510000AA33163,449.59101,691.35(61,758.24)
266510000AA380.00
276510000AA400.00
286510000AACI468.00468.00
296510000AADC13,002.434,513.96(8,488.47)
306510000AAIB602,672.38594,983.46(7,688.92)
316510000AATN(1,102.08)1,102.08
326510000AATR0.00
336510000DACH0.00
346510000 Total2,665,056.742,655,014.21(10,042.53)
358500990AA118,577,429.198,878,897.30301,468.11
368500990AA120.00
378500990AA130.00
388500990AA160.00
398500990AA33472,397.68293,905.64(178,492.04)
408500990AA380.00
418500990AA400.00
428500990AACI2,836.362,836.36
438500990AADC37,149.8021,495.04(15,654.76)
448500990AAIB54,788,390.5754,089,414.34(698,976.23)
458500990AATN(4,408.32)4,408.32
468500990AATR0.00
478500990DACH0.00
488500990 Total63,870,958.9263,286,548.68(584,410.24)
499900100AA11(1,887,034.42)(1,953,357.44)(66,323.02)
509900100AA120.00
519900100AA130.00
529900100AA160.00
539900100AA33(163,449.59)(101,691.35)61,758.24
549900100AA380.00
559900100AA400.00
569900100AACI(468.00)(468.00)
579900100AADC(13,002.43)(4,513.96)8,488.47
589900100AAIB(602,672.38)(594,983.46)7,688.92
599900100AATN1,102.08(1,102.08)
609900100AATR0.00
619900100DACH0.00
629900100 Total(2,665,056.74)(2,655,014.21)10,042.53
63Grand Total0.000.000.00
pivot AADC
Cell Formulas
RangeFormula
A3ASSIGNMENT:0ALLOC_NMBR
A5Sum of AMOUNT_DC:0BALANCE
A6GL_ACCOUNT:0GL_ACCOUNT
A72090000
A82090000
A92090000
A102090000
A112090000
A122090000
A132090000
A142090000
A152090000
A162090000
A172090000
A182090000
A192090000
A202090000 Total
A216510000
A226510000
A236510000
A246510000
A256510000
A266510000
A276510000
A286510000
A296510000
A306510000
A316510000
A326510000
A336510000
A346510000 Total
A358500990
A368500990
A378500990
A388500990
A398500990
A408500990
A418500990
A428500990
A438500990
A448500990
A458500990
A468500990
A478500990
A488500990 Total
A499900100
A509900100
A519900100
A529900100
A539900100
A549900100
A559900100
A569900100
A579900100
A589900100
A599900100
A609900100
A619900100
A629900100 Total
A63Grand Total
B3AADO
B6TRAD_PART:0PCOMPANY
B7AA11
B8AA12
B9AA13
B10AA16
B11AA33
B12AA38
B13AA40
B14AACI
B15AADC
B16AAIB
B17AATN
B18AATR
B19DACH
B21AA11
B22AA12
B23AA13
B24AA16
B25AA33
B26AA38
B27AA40
B28AACI
B29AADC
B30AAIB
B31AATN
B32AATR
B33DACH
B35AA11
B36AA12
B37AA13
B38AA16
B39AA33
B40AA38
B41AA40
B42AACI
B43AADC
B44AAIB
B45AATN
B46AATR
B47DACH
B49AA11
B50AA12
B51AA13
B52AA16
B53AA33
B54AA38
B55AA40
B56AACI
B57AADC
B58AAIB
B59AATN
B60AATR
B61DACH
C5Period
C643070
C7-8577429.19
C11-472397.68
C15-37149.8
C16-54788390.57
C174408.32
C20-63870958.92
C211887034.42
C25163449.59
C2913002.43
C30602672.38
C31-1102.08
C342665056.74
C358577429.19
C39472397.68
C4337149.8
C4454788390.57
C45-4408.32
C4863870958.92
C49-1887034.42
C53-163449.59
C57-13002.43
C58-602672.38
C591102.08
C62-2665056.74
C631.00535544333979E-08
D643252
D7-8878897.3
D11-293905.64
D14-2836.36
D15-21495.04
D16-54089414.34
D20-63286548.68
D211953357.44
D25101691.35
D28468
D294513.96
D30594983.46
D342655014.21
D358878897.3
D39293905.64
D422836.36
D4321495.04
D4454089414.34
D4863286548.68
D49-1953357.44
D53-101691.35
D56-468
D57-4513.96
D58-594983.46
D62-2655014.21
D633.49245965480804E-10
E6variance
E7=Period[-1]-Period[-2]
E8=Period[-1]-Period[-2]
E9=Period[-1]-Period[-2]
E10=Period[-1]-Period[-2]
E11=Period[-1]-Period[-2]
E12=Period[-1]-Period[-2]
E13=Period[-1]-Period[-2]
E14=Period[-1]-Period[-2]
E15=Period[-1]-Period[-2]
E16=Period[-1]-Period[-2]
E17=Period[-1]-Period[-2]
E18=Period[-1]-Period[-2]
E19=Period[-1]-Period[-2]
E20584410.239999958
E21=Period[-1]-Period[-2]
E22=Period[-1]-Period[-2]
E23=Period[-1]-Period[-2]
E24=Period[-1]-Period[-2]
E25=Period[-1]-Period[-2]
E26=Period[-1]-Period[-2]
E27=Period[-1]-Period[-2]
E28=Period[-1]-Period[-2]
E29=Period[-1]-Period[-2]
E30=Period[-1]-Period[-2]
E31=Period[-1]-Period[-2]
E32=Period[-1]-Period[-2]
E33=Period[-1]-Period[-2]
E34-10042.5299999993
E35=Period[-1]-Period[-2]
E36=Period[-1]-Period[-2]
E37=Period[-1]-Period[-2]
E38=Period[-1]-Period[-2]
E39=Period[-1]-Period[-2]
E40=Period[-1]-Period[-2]
E41=Period[-1]-Period[-2]
E42=Period[-1]-Period[-2]
E43=Period[-1]-Period[-2]
E44=Period[-1]-Period[-2]
E45=Period[-1]-Period[-2]
E46=Period[-1]-Period[-2]
E47=Period[-1]-Period[-2]
E48-584410.239999958
E49=Period[-1]-Period[-2]
E50=Period[-1]-Period[-2]
E51=Period[-1]-Period[-2]
E52=Period[-1]-Period[-2]
E53=Period[-1]-Period[-2]
E54=Period[-1]-Period[-2]
E55=Period[-1]-Period[-2]
E56=Period[-1]-Period[-2]
E57=Period[-1]-Period[-2]
E58=Period[-1]-Period[-2]
E59=Period[-1]-Period[-2]
E60=Period[-1]-Period[-2]
E61=Period[-1]-Period[-2]
E6210042.5299999993
E636.00266503170133E-11
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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