how do i count the number of contracts associated with a gl?

bigdan

Well-known Member
Joined
Oct 5, 2009
Messages
846
Office Version
  1. 2013
Platform
  1. Windows
How do I find the number of unique contracts that are associated with a GL?

Please see sample data.

For ABC the answer should be 1. For DEF it should be 3. For GHI it should be 2.

I would've thought a pivot table would do the trick. It does not. In a pivot if I put GL in rows and Count of Contracts in Values, it gives me 3 for ABC rather than 1. So it's giving me the number of rows associated with ABC, as opposed to the number of UNIQUE rows.

Can anyone advise?


GLContract
ABC123
ABC123
ABC123
DEF411
DEF511
DEF611
GHI559
GHI459
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
How about
Excel Formula:
=SUM(--(FREQUENCY(IF($A$2:$A$100=D2,$B$2:$B$100),$B$2:$B$100)>0))
This needs to be confirmed with Ctrl Shift Enter, rather than just enter
 
Upvote 0
PowerQuery
Assuming data is in A1:B9 range (it's a table called "DATA"):
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="DATA"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"GL", type text}, {"Contracts", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"GL"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}})
in
    #"Grouped Rows"
 
Upvote 0
How about
Excel Formula:
=SUM(--(FREQUENCY(IF($A$2:$A$100=D2,$B$2:$B$100),$B$2:$B$100)>0))
This needs to be confirmed with Ctrl Shift Enter, rather than just enter

Thanks! This kinda sorta works but not exactly. I made a small table of all the GLs in my worksheet, which was a list of 10. Next to each of them I used your formula to see how many unique contracts relate to them. The total number of unique contracts was given as 2166. But the total number of rows in the workbook is 2680. I would've expected your formula to give me a higher number, since one contract could be in 2 different GLs, not a lower number. So I looked at an individual GL level. With the first one, this formula gave me 243 contracts. I counted 246. So it's quite close. Not sure where the inaccuracy is coming from. But it is there unfortunately. In another example this formula gave me 122 contracts, I counted 127.
 
Upvote 0
PowerQuery
Assuming data is in A1:B9 range (it's a table called "DATA"):
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="DATA"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"GL", type text}, {"Contracts", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"GL"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}})
in
    #"Grouped Rows"
I'm sorry I'm not familiar with PowerQuery. I appreciate the help though!
 
Upvote 0
Can you post some sample data that shows the problem.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
But it is there unfortunately. In another example this formula gave me 122 contracts, I counted 127.
I would hazard a guess that there is more likely a discrepancy in the data than a problem with the formula (as appears also to be the case in your previous thread).
See mini sheet below for 2 formula methods, note that there is a difference between the results of my formula in column E and @Fluff's formula in column F if there is a GL with an empty cell for contract.
Book1
ABCDEF
1GLContract
2ABC123ABC11
3ABC123DEF33
4ABC123GHI22
5DEF411JKL01
6DEF511
7DEF611
8GHI559
9GHI459
10GHI459
11JKL
Sheet4
Cell Formulas
RangeFormula
E2:E5E2=SUM(IFERROR(1/COUNTIFS($A$2:$A$100,D2,$B$2:$B$100,$B$2:$B$100),))
F2:F5F2=SUM(--(FREQUENCY(IF($A$2:$A$100=D2,$B$2:$B$100),$B$2:$B$100)>0))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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