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.
 
Try:


Excel 2010
ABCD
1GL_ACCOUNT:0GL_ACCOUNTTRAD_PART:0PCOMPANYPeriodAMOUNT_DC:0BALANCE
22090000AA1112/1-8577429.19
32090000AA116/1-8878897.3
42090000AA1212/10
52090000AA126/10
62090000AA1312/10
72090000AA136/10
82090000AA1612/10
92090000AA166/10
102090000AA3312/1-472397.68
112090000AA336/1-293905.64
122090000AA3812/10
132090000AA386/10
142090000AA4012/10
152090000AA406/10
162090000AACI12/10
172090000AACI6/1-2836.36
182090000AADC12/1-37149.8
192090000AADC6/1-21495.04
202090000AAIB12/1-54788390.57
212090000AAIB6/1-54089414.34
222090000AATN12/14408.32
232090000AATN6/10
242090000AATR12/10
252090000AATR6/10
262090000DACH12/10
272090000DACH6/10
286510000AA1112/11887034.42
296510000AA116/11953357.44
306510000AA1212/10
316510000AA126/10
326510000AA1312/10
336510000AA136/10
346510000AA1612/10
356510000AA166/10
366510000AA3312/1163449.59
376510000AA336/1101691.35
386510000AA3812/10
396510000AA386/10
406510000AA4012/10
416510000AA406/10
426510000AACI12/10
436510000AACI6/1468
446510000AADC12/113002.43
456510000AADC6/14513.96
466510000AAIB12/1602672.38
476510000AAIB6/1594983.46
486510000AATN12/1-1102.08
496510000AATN6/10
506510000AATR12/10
516510000AATR6/10
526510000DACH12/10
536510000DACH6/10
548500990AA1112/18577429.19
558500990AA116/18878897.3
568500990AA1212/10
578500990AA126/10
588500990AA1312/10
598500990AA136/10
608500990AA1612/10
618500990AA166/10
628500990AA3312/1472397.68
638500990AA336/1293905.64
648500990AA3812/10
658500990AA386/10
668500990AA4012/10
678500990AA406/10
688500990AACI12/10
698500990AACI6/12836.36
708500990AADC12/137149.8
718500990AADC6/121495.04
728500990AAIB12/154788390.57
738500990AAIB6/154089414.34
748500990AATN12/1-4408.32
758500990AATN6/10
768500990AATR12/10
778500990AATR6/10
788500990DACH12/10
798500990DACH6/10
809900100AA1112/1-1887034.42
819900100AA116/1-1953357.44
829900100AA1212/10
839900100AA126/10
849900100AA1312/10
859900100AA136/10
869900100AA1612/10
879900100AA166/10
889900100AA3312/1-163449.59
899900100AA336/1-101691.35
909900100AA3812/10
919900100AA386/10
929900100AA4012/10
939900100AA406/10
949900100AACI12/10
959900100AACI6/1-468
969900100AADC12/1-13002.43
979900100AADC6/1-4513.96
989900100AAIB12/1-602672.38
999900100AAIB6/1-594983.46
1009900100AATN12/11102.08
Pivot



Excel 2010
ABCD
1019900100AATN6/10
1029900100AATR12/10
1039900100AATR6/10
1049900100DACH12/10
1059900100DACH6/10
Pivot


Code:
Sub hidepairsofzeroes()
Dim pt As PivotTable
Dim i As PivotItem
Dim j As PivotItem
Set pt = Sheets("Pivot").PivotTables(1)
For Each i In pt.PivotFields("GL_ACCOUNT:0GL_ACCOUNT").PivotItems
For Each j In pt.PivotFields("TRAD_PART:0PCOMPANY").PivotItems
On Error Resume Next
If pt.GetPivotData("AMOUNT_DC:0BALANCE", "GL_ACCOUNT:0GL_ACCOUNT", i.Name, "TRAD_PART:0PCOMPANY", j.Name, "Period", 43070) = 0 And pt.GetPivotData("AMOUNT_DC:0BALANCE", "GL_ACCOUNT:0GL_ACCOUNT", i.Name, "TRAD_PART:0PCOMPANY", j.Name, "Period", 43252) = 0 Then
j.Visible = False
End If
Next j
Next i
End Sub


Excel 2010
FGHIJ
1Sum of AMOUNT_DC:0BALANCEPeriod
2GL_ACCOUNT:0GL_ACCOUNTTRAD_PART:0PCOMPANY12/16/1Formula1
32090000AA11(8,577,429.19)(8,878,897.30)(301,468.11)
42090000AA33(472,397.68)(293,905.64)178,492.04
52090000AACI-(2,836.36)(2,836.36)
62090000AADC(37,149.80)(21,495.04)15,654.76
72090000AAIB(54,788,390.57)(54,089,414.34)698,976.23
82090000AATN4,408.32-(4,408.32)
92090000 Total(63,870,958.92)(63,286,548.68)584,410.24
106510000AA111,887,034.421,953,357.4466,323.02
116510000AA33163,449.59101,691.35(61,758.24)
126510000AACI-468.00468.00
136510000AADC13,002.434,513.96(8,488.47)
146510000AAIB602,672.38594,983.46(7,688.92)
156510000AATN(1,102.08)-1,102.08
166510000 Total2,665,056.742,655,014.21(10,042.53)
178500990AA118,577,429.198,878,897.30301,468.11
188500990AA33472,397.68293,905.64(178,492.04)
198500990AACI-2,836.362,836.36
208500990AADC37,149.8021,495.04(15,654.76)
218500990AAIB54,788,390.5754,089,414.34(698,976.23)
228500990AATN(4,408.32)-4,408.32
238500990 Total63,870,958.9263,286,548.68(584,410.24)
249900100AA11(1,887,034.42)(1,953,357.44)(66,323.02)
259900100AA33(163,449.59)(101,691.35)61,758.24
269900100AACI-(468.00)(468.00)
279900100AADC(13,002.43)(4,513.96)8,488.47
289900100AAIB(602,672.38)(594,983.46)7,688.92
299900100AATN1,102.08-(1,102.08)
309900100 Total(2,665,056.74)(2,655,014.21)10,042.53
31Grand Total0.000.000.00
Pivot


Before setting the pivot table I changed the source data blanks to 0s. After running the code I added the variance calculated item.
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Thanks again sheetspread for your suggestions on resolving this one. Just wanted to close the loop with what I ultimately ended up using. Following is the relevant part of the code that was at issue.

Code:
lMonth1 = CDbl(ws.Range("C6"))       'previous month's value
lMonth2 = CDbl(ws.Range("D6"))       'current month's value

        iLastRowPT = ws.Range("A" & Rows.Count).End(xlUp).Row - 1       'find last row of pivot table (excluding 'Grand Total' row)
        For Each i In pvt.PivotFields("GL_ACCOUNT:0GL_ACCOUNT").PivotItems
            For Each j In pvt.PivotFields("TRAD_PART:0PCOMPANY").PivotItems
            On Error Resume Next
                If pvt.GetPivotData("AMOUNT_DC:0BALANCE", "GL_ACCOUNT:0GL_ACCOUNT", i.Name, "TRAD_PART:0PCOMPANY", j.Name, "Period", lMonth1) = 0 And _
                    pvt.GetPivotData("AMOUNT_DC:0BALANCE", "GL_ACCOUNT:0GL_ACCOUNT", i.Name, "TRAD_PART:0PCOMPANY", j.Name, "Period", lMonth2) = 0 Then
                    j.Visible = False   'if both months' AMOUNT = 0, then hide row
                Else
                    j.Visible = True    'otherwise, leave row visible
                End If
            Next j
        Next i

Many thanks again for a great solution!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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