Formula to match criteria

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
857
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a very large data set that I was attempting to count the occurrences by each line but it was bogging down the system. So a way to avoid is if I can accomplish the same based off a summary tab where I list the data. Two formulas I think I need to accomplish that I am struggling to find.

Quick explanation I have a program that will consolidate based off two criteria. Cost (rounded to 4 digits) and Date. For simplicity reasons I am going to avoid date for now. After it consolidates the two, three, or four occurrences it creates a new combined lot . This is an inventory management tool. I am trying to get myself some reporting and been working on VBA to do is. I am super close just running into headaches along the way like this.

I summarized the data below, short snipbit. The data is over 500k rows that is why I figure a summary is quicker than applying formulas to each row, then summarize based off that formula later.

ProductIdentifierDate OpenedUnique Lot Cost Cost Rounded to 4 digits Result should beResult should be
Group AB11/1/20201$ 20.91$ 20.9125Will be removedAdded BackDifference
Group AB11/9/20192$ 22.00$ 22.0000B152-3
Group AB11/9/19993$ 22.00$ 22.0000C1000
Group AB16/4/19994$ 65.00$ 65.0000D163-3
Group AB17/9/20005$ 65.00$ 65.0000E142-2
Group AB14/8/19886$ 22.00$ 22.0000
Group AC15/5/20057$ 35.00$ 35.0000
Group AC110/10/20208$ 20.96$ 20.9575
Group AC11/1/20209$ 40.00$ 40.0000
Group AC11/9/201910$ 40.99$ 40.9900
Group AC11/9/199911$ 41.30$ 41.2990
Group AC16/4/199912$ 50.56$ 50.5565
Group AD17/9/200013$ 51.28$ 51.2750
Group AD14/8/198814$ 99.97$ 99.9652
Group AD15/5/200515$ 20.91$ 20.9125
Group AD11/1/202016$ 20.91$ 20.9125
Group AD11/1/202017$ 99.97$ 99.9652
Group AD11/9/201918$ 51.28$ 51.2750
Group AE11/9/199919$ 41.30$ 41.2990
Group AE16/4/199920$ 41.30$ 41.2990
Group AE17/9/200021$ 51.28$ 51.2750
Group AE14/8/198822$ 51.28$ 51.2750
Group AE15/5/200523$ 50.56$ 50.5565
Group AE110/10/202024$ 20.96$ 20.9575
 
Oh this is great. Honestly don't even need J3 could just use I3 and K3. Let me apply it to my code and see how it manifests. but with my small dataset it seems to be working. I will just need to mess around cause the data is all mixed around
 
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.
Ok few questions/help if I set the formula on the data sheet using VBA will that fill it down too? I tried both but doesn't seem to fill down.

Unless I keep it on the sheet for my example but on that sheet I only have identifier so would need to reference somewhere else so i don't think that would work.

This copies down, but now i am worried about time strain
VBA Code:
lr1 = .Cells(rows.count, "A").End(xlUp).row
 .Range("R2:R" & lr1).Formula = "=COUNTIFS($D$2:$D$" & lr1 & ",$D$2:$D$" & lr1 & ",$M$2:$M$" & lr1 & ",$M$2:$M$" & lr1 & ")"

noticed it puts the @ in front of the formulas? =COUNTIFS($D$2:$D$123,@$D$2:$D$123,$M$2:$M$123,@$M$2:$M$123)

If I do this it doesn't fill down unless I am doing it wrong
VBA Code:
lr1 = .Cells(rows.count, "A").End(xlUp).row
 .Range("R2").Formula = "=COUNTIFS($D$2:$D$" & lr1 & ",$D$2:$D$" & lr1 & ",$M$2:$M$" & lr1 & ",$M$2:$M$" & lr1 & ")"
 
Upvote 0
Ok so I placed the helper on the data sheet. Then on my summary sheet I placed formula of column I. But I would have to reference each sheet based off the left most character. I tried to incorporate an indirect formula but its not working. Am I unable to do that approach? I can get close but then referencing with the countIF kicks the REF.

1709672092045.png
 
Upvote 0
Made some improvements. Got myself further. converted the formula into a COUNTIF from COUNTIFS used an additional helper column of Identifier & cost. Then countif to just that new column. Macro went from running for 10 hours to 5 hours :cry: am I just SOL with the size of my data? I would hope i am not because now I am not sure what is left to do
 
Upvote 0
If you want I can have a try to shorten that more, but I would need to have the file. It might be that VBA and/or PowerQuery could shorten it even more, but that's hard to say.
 
Last edited by a moderator:
Upvote 0
I fully understand - the data is quite large so I figured I would be in a very tough spot here
 
Upvote 0
You're right, I missed that part.

Create a helper column:
Excel Formula:
G2: =COUNTIFS($B$2:$B$25,$B$2:$B$25,$F$2:$F$25,$F$2:$F$25)  (should fill G2:G25)
I3: = COUNTIFS($B$2:$B$25,H3,$G$2#,">1")
J3: = I3+K3
K3: =COUNTA(UNIQUE(FILTER($E$2:$E$25,$B$2:$B$25=H3)))-COUNTIFS($B$2:$B$25,H3)

You can probably create a one-cell formula in I3 etc, but that takes a bit of fiddling, probably with SUMPRODUCT, UNIQUE, COUNTIFS etc. Note that $G$2# refers to $G$2:$G$25, but is a new way Excel refers to the spilled ranges (see my link with your #SPILL error).
@Rijnsent I been thoroughly testing this and noticed the formula for column K creates records of 1 even when the data isn't even present. See below for an example - would you know why that could be the case?

1710446609842.png
 
Upvote 0
@Rijnsent I been thoroughly testing this and noticed the formula for column K creates records of 1 even when the data isn't even present. See below for an example - would you know why that could be the case?

View attachment 108381
Sorry you can ignore I found a minor tweak to get it to work. having it reference a helper column removed that problem
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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