Help Index Match

Joeun

New Member
Joined
Sep 10, 2017
Messages
20
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

I was trying to work out an Index Match for my summary.

The problem is whenever the balance column K is 0, then the rest of the below will become disappear.

What I wanted is when that particular row balance is 0, that roll will not show and the row below will move upward.

Thanks for any suggestions.





Stock.xlsx
ABCDEFGHIJKLMNOPQRS
1
2DATELOT NO.IN KGOUT KGBALANCEExample
326/03/2018S0165W23,529.0023,529.00SummarySummary
430/03/2018S0165W1,650.0021,879.00Lot NoInOutBalanceLot NoInOutBalance
503/04/2018S0165W3,300.0018,579.0018S0165W8539484113128118S0165W85394853940(when balance is 0)
607/04/2018S0165W3,300.0015,279.0018S0218W164671584362418S0218W1646715843624
709/04/2018S0165W3,300.0011,979.0018S0282W16929169072218S0282W169291690722
815/04/2018S0165W3,300.008,679.0018S0300W3102928520250918S0300W31029285202509
930/04/2018S0165W23,529.0032,208.00 000000
1027/05/2018S0165W3,300.0028,908.00 000000
1105/06/2018S0165W1,980.0026,928.00 000000
1209/06/2018S0165W726.0026,202.00
1311/06/2018S0165W1,320.0024,882.00
1427/07/2018S0165W1,377.0026,259.00Targeted Result
1511/08/2018S0165W816.0025,443.00Summary
1625/08/2018S0165W660.0024,783.00Lot NoInOutBalance
1707/09/2018S0165W2,244.0022,539.0018S0218W1646715843624
1824/09/2018S0165W1,980.0020,559.0018S0282W169291690722
1902/10/2018S0165W1,089.0019,470.0018S0300W31029285202509
2005/10/2018S0165W1,320.0018,150.00000
2119/10/2018S0165W858.0017,292.00000
2211/11/2018S0165W693.0016,599.00000
2324/11/2018S0165W660.0015,939.00000
2408/12/2018S0165W1,320.0014,619.00
2515/12/2018S0165W4,620.009,999.00
2605/01/2118S0165W6,600.003,399.00
2704/02/2118S0165W3,399.00-
2808/03/2118S0218W16,467.0016,467.00
2908/03/2118S0218W1,980.0014,487.00
3010/03/2118S0218W528.0013,959.00
3111/03/2118S0218W726.0013,233.00
3201/04/2118S0218W1,320.0011,913.00
3307/04/2118S0218W1,386.0010,527.00
3406/04/2118S0218W660.009,867.00
3513/04/2118S0218W1,188.008,679.00
3615/04/2118S0218W1,320.007,359.00
3716/04/2118S0218W1,320.006,039.00
3821/04/2118S0218W660.005,379.00
3922/04/2118S0218W726.004,653.00
4005/06/2118S0282W16,929.0016,929.00
4115/07/2118S0218W2,970.001,683.00
4221/07/2118S0218W396.001,287.00
4324/07/2118S0218W363.00924.00
4430/07/2118S0218W300.00624.00
4530/07/2118S0282W396.0016,533.00
4623/08/2118S0282W1,980.0014,553.00
4722/09/2118S0282W2,112.0012,441.00
4824/09/2118S0282W1,584.0010,857.00
4918/10/2118S0282W528.0010,329.00
5019/10/2118S0282W792.009,537.00
5120/10/2118S0282W1,848.007,689.00
5227/10/2118S0282W1,056.006,633.00
5301/11/2118S0282W6,303.00330.00
5425/11/2118S0165W5,907.005,907.00
5529/11/2118S0165W1,452.004,455.00
5629/11/2118S0282W297.0033.00
5729/11/2118S0165W3,300.001,155.00
5830/11/2118S0282W11.0022.00
5906/12/2118S0165W1,155.00-
6020/12/2118S0165W37.0037.00
6124/12/2118S0300W23,529.0023,529.00
6229/12/2118S0300W3,300.0020,229.00
6331/12/2118S0300W891.0019,338.00
6404/01/2218S0300W6,600.0012,738.00
6518/01/2218S0300W7,500.0020,238.00
6624/01/2218S0300W3,300.0016,938.00
6711/02/2218S0300W1,980.0014,958.00
6811/02/2218S0165W23,529.0023,566.00
6916/02/2218S0300W1,056.0013,902.00
7023/02/2218S0300W660.0013,242.00
7124/02/2218S0300W528.0012,714.00
7201/07/2218S0300W33.0012,681.00
7304/07/2218S0300W5,148.007,533.00
7403/08/2218S0165W2,244.0021,322.00
7508/08/2218S0165W2,508.0018,814.00
7624/08/2218S0165W726.0018,088.00
7703/09/2218S0165W1,980.0016,108.00
7807/09/2218S0165W5,016.0011,092.00
7907/09/2218S0165W165.0010,927.00
8012/09/2218S0165W7,491.003,436.00
8114/09/2218S0165W2,145.001,291.00
8211/10/2218S0165W1,254.0037.00
8328/10/2218S0165W226.00263.00
8419/04/2318S0165W263.00-
8519/04/2318S0300W8.007,525.00
8614/05/2318S0165W7,260.007,260.00
8722/05/2318S0300W1,456.006,069.00
8818/06/2318S0300W3,560.002,509.00
8906/07/2318S0165W792.006,468.00
9007/07/2318S0165W2,013.004,455.00
9115/08/2318S0165W792.003,663.00
9221/08/2318S0165W594.003,069.00
9322/08/2318S0165W595.002,474.00
9423/08/2318S0165W596.001,878.00
9524/08/2318S0165W597.001,281.00
9625/08/2318S0165W1,281.00
97
Sheet3
Cell Formulas
RangeFormula
H5:H11H5=IF(SUMIF($B$3:$B$107,INDEX(B3:B107,MATCH(0,INDEX(COUNTIF($H$4:H4,B3:B107),),0)),$C$3:$C$107)-SUMIF($B$3:$B$107,INDEX(B3:B107,MATCH(0,INDEX(COUNTIF($H$4:H4,B3:B107),),0)),$D$3:$D$107)>0,INDEX(B3:B107,MATCH(0,INDEX(COUNTIF($H$4:H4,B3:B107),),0)),"")
I5:I11I5=SUMIF($B$3:$B$107,H5,$C$3:$C$107)
J5:J11J5=SUMIF($B$3:$B$107,H5,$D$3:$D$107)
K5:K11K5=I5-J5
E3:E96E3=IFNA(LOOKUP(2,1/($B$1:B2=B3),$E$1:E2),0)+C3-D3
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
1235.xlsm
BCDEFGHIJ
1
2LOT NO.IN KGOUT KGBALANCELOT NO.INOutDifference
318S0165W235292352918S0218W1646715843624
418S0165W16502187918S0282W169291690722
518S0165W33001857918S0300W31029285202509
618S0165W33001527918S0165W85394841131281
718S0165W330011979
818S0165W33008679
918S0165W2352932208
1018S0165W330028908
1118S0165W198026928
1218S0165W72626202
1318S0165W132024882
1418S0165W137726259
1518S0165W81625443
1618S0165W66024783
1718S0165W224422539
1818S0165W198020559
1918S0165W108919470
2018S0165W132018150
2118S0165W85817292
2218S0165W69316599
2318S0165W66015939
2418S0165W132014619
2518S0165W46209999
2618S0165W66003399
2718S0165W33990
2818S0218W1646716467
2918S0218W198014487
3018S0218W52813959
3118S0218W72613233
3218S0218W132011913
3318S0218W138610527
3418S0218W6609867
3518S0218W11888679
3618S0218W13207359
3718S0218W13206039
3818S0218W6605379
3918S0218W7264653
4018S0282W1692916929
4118S0218W29701683
4218S0218W3961287
4318S0218W363924
4418S0218W300624
4518S0282W39616533
4618S0282W198014553
4718S0282W211212441
4818S0282W158410857
4918S0282W52810329
5018S0282W7929537
5118S0282W18487689
5218S0282W10566633
5318S0282W6303330
5418S0165W59075907
5518S0165W14524455
5618S0282W29733
5718S0165W33001155
5818S0282W1122
5918S0165W11550
6018S0165W3737
6118S0300W2352923529
6218S0300W330020229
6318S0300W89119338
6418S0300W660012738
6518S0300W750020238
6618S0300W330016938
6718S0300W198014958
6818S0165W2352923566
6918S0300W105613902
7018S0300W66013242
7118S0300W52812714
7218S0300W3312681
7318S0300W51487533
7418S0165W224421322
7518S0165W250818814
7618S0165W72618088
7718S0165W198016108
7818S0165W501611092
7918S0165W16510927
8018S0165W74913436
8118S0165W21451291
8218S0165W125437
8318S0165W226263
8418S0165W2630
8518S0300W87525
8618S0165W72607260
8718S0300W14566069
8818S0300W35602509
8918S0165W7926468
9018S0165W20134455
9118S0165W7923663
9218S0165W5943069
9318S0165W5952474
9418S0165W5961878
9518S0165W5971281
9618S0165W1281
Sheet10
Cell Formulas
RangeFormula
D4D4=1650
E3:E96E3=IFNA(LOOKUP(2,1/($B$1:B2=B3),$E$1:E2),0)+C3-D3
 
Upvote 0
1698735273113.png
1698735347190.png
1698735469872.png





This can b done by simply qwery query step as i send in pic
 
Upvote 0
First, I wanted to confirm that you do not use Excel 365? Because if you do, some relatively easy formulas would lead to a much more direct solution.

There are a couple of issues with the formula that is intended to return unique lot numbers:
1. Some of the ranges need to be locked so that they reference the entire (and correct) full range of data (currently several ranges are not locked).
2. The formula will return a blank if the Balance is <=0...which I know is intended, but within the formula is COUNTIF($H$4:H4,B3:B107). This looks above at the list of unique Lot Numbers that have already been found. And because the logic in the first part of the formula (with the SUMIFs) has potentially resulted in a unique Lot Number being ignored and replaced by a blank (""), COUNTIF($H$4:H4,B3:B107) cannot consider that the unique lot number has already been found and should be ignored; therefore the formula attempts to return the same unique Lot Number...and the SUMIFs logic will continually return a blank. And this happens row after row in the Summary table.

I would recommend forming some helper columns (they can be hidden). One helper contains the unique Lot Numbers. Another contains unique Lot Numbers whose final Balance >0. One other Helper cell is used to form dynamic ranges so that the entire range of your source data is considered, without making the range any longer than necessary (this suppresses a 0 that would be returned in subsequent steps). Then the final Summary table can be created by referring to the intermediate results in the helper cells. In the sample below, I've forced a 0 balance for lot 18S0165W by inserting 1281 in cell D3, and when that happens, the lot is removed from the summary table and the table collapses to include only those lots whose balance remains positive.
MrExcel_20231030_B.xlsx
ABCDEFGHIJKLMN
1
2DATELOT NO.IN KGOUT KGBALANCE
34391618S0165W23529128122248Summary
44392018S0165W165020598Lot NoInOutBalanceHelper UniquesHelper PosBalLrow
54392418S0165W33001729818S0218W164671584362418S0165W 96
64392818S0165W33001399818S0282W16929169072218S0300W18S0300W
74393018S0165W33001069818S0300W3102928520250918S0282W18S0282W
84393618S0165W33007398    18S0218W18S0218W
94395118S0165W2352930927      
104397818S0165W330027627      
114398718S0165W198025647
124399118S0165W72624921
134399318S0165W132023601
144403918S0165W137724978
154405418S0165W81624162
164406818S0165W66023502
174408118S0165W224421258
184409818S0165W198019278
194410618S0165W108918189
204410918S0165W132016869
Sheet4
Cell Formulas
RangeFormula
H5:H10H5=IFERROR(INDEX(M:M,AGGREGATE(14,6,ROW($M$5:$M$10)/--($M$5:$M$10<>""),ROWS(H$4:H4))),"")
I5:I10I5=IF(H5="","",SUMIF(B:B,H5,C:C))
J5:J10J5=IF(H5="","",SUMIF(B:B,H5,D:D))
K5:K10K5=IF(H5="","",I5-J5)
L5:L10L5=IFNA(LOOKUP(2,1/(COUNTIF(L$4:L4,$B$3:INDEX($B:$B,$N$5))=0),$B$3:INDEX($B:$B,$N$5)),"")
M5:M10M5=IF(SUMIF(B:B,L5,C:C)-SUMIF(B:B,L5,D:D)>0,L5,"")
N5N5=LOOKUP(2,1/--(B:B<>""),ROW(B:B))
E3:E20E3=IFNA(LOOKUP(2,1/($B$1:B2=B3),$E$1:E2),0)+C3-D3
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
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