Formula for Group by Customer

pto160

Active Member
Joined
Feb 1, 2009
Messages
478
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet with customers and invoices. I would like to place zero for the first customer, then 1 for the next customer and back to zero again for the next customer. Is there a way to do this?

Book1
ABCD
1CustomerAmountInvoiceWhat I want
210015Inv-1500
310015Inv-1500
420050Inv-2001
5300100Inv-2500
6300100Inv-2500
7400200Inv-3001
8500300Inv-4000
9500300Inv-4000
Sheet1
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Book8
ABCD
1CustomerAmountInvoiceWhat I want
210015Inv-1500
310015Inv-1500
420050Inv-2001
5300100Inv-2500
6300100Inv-2500
7400200Inv-3001
8500300Inv-4000
9500300Inv-4000
10
11CustomerAll.AmountAll.InvoiceCustom
1210015Inv-1500
1310015Inv-1500
1420050Inv-2001
15300100Inv-2500
16300100Inv-2500
17400200Inv-3001
18500300Inv-4000
19500300Inv-4000
Sheet1


Power Query Solution

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Customer"}, {{"Duplicate", each Table.RowCount(_), Int64.Type}, {"All", each _, type table [Customer=number, Amount=number, Invoice=text, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each if [Duplicate]>1 then 0 else 1),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Duplicate"}),
    #"Expanded All" = Table.ExpandTableColumn(#"Removed Columns", "All", {"Amount", "Invoice"}, {"All.Amount", "All.Invoice"})
in
    #"Expanded All"
 
Upvote 0
Thank you so much. That is a fantastic Power Query solution. I am trying to learn more about using Power Query.

Is there a formula solution I wonder?
 
Upvote 0
Is there a formula solution I wonder?
Would this work for you?
Put a 1 in D1 then the formula shown, copied down.
If you want a different heading, would swapping the 0s and 1s be acceptable as shown in column E?

22 11 08.xlsm
ABCDE
1CustomerAmountInvoice1Hdr
210015Inv-15001
310015Inv-15001
420050Inv-20010
5300100Inv-25001
6300100Inv-25001
7400200Inv-30010
8500300Inv-40001
9500300Inv-40001
0_1
Cell Formulas
RangeFormula
D2:D9D2=IF(A2=A1,D1,1-D1)
E2:E9E2=IF(A2=A1,E1,1-N(E1))
 
Upvote 0
(y)Thanks Peter. Yes swapping the zeros and ones would definitely work for column E.
This will really help me set up conditional formatting where I can group the ones for example with a yellow color.
 
Upvote 0
Sure, that makes for a very simple CF formula. You can even hide the helper column if you want.

22 11 08.xlsm
ABCD
1CustomerAmountInvoiceGroup
210015Inv-1501
310015Inv-1501
420050Inv-2000
5300100Inv-2501
6300100Inv-2501
7400200Inv-3000
8500300Inv-4001
9500300Inv-4001
0_1
Cell Formulas
RangeFormula
D2:D9D2=IF(A2=A1,D1,1-N(D1))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:D9Expression=$D2textNO
 
Upvote 0
Thank you so much for the conditional formatting formula. :)(y) It works great.
 
Upvote 0
You're welcome. Glad it helped. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

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