sumproduct+countif+sumif

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
460
Office Version
  1. 2019
greeting to all,

i am not very good at excel formula, with my data(A1:C19) below

i have to extract the date and time to date only(E2:E19), and then remove duplicate(F2:F3), to calculate the number of order SN(G2:G3)

however, i was wondering, if this 3 formula can be worked(J2:K6) at same time
ps: lower right corner is my expected answer

Mrh Online - Order with SOH (Prompt) Production - Pick Up - Limited Store - Hourly2023-12-29-20-01-01 (002).xlsx
ABCDEFGHIJK
1Order SnUpdated AtLocation Translations.TitleUpdated AtUpdated AtOrder SnLocation Translations.Title12/29/202312/28/2023
223122012181247290812/29/202311112/29/202312/29/20236111
323122012181247290812/29/202311112/29/202312/28/20235222
423122012181247290812/29/202311112/29/2023333
523122012181247290812/29/202311112/29/2023444
623122112021075330512/29/202311112/29/2023555
723122112041678641312/29/202322212/29/2023
823122112044492327912/29/202333312/29/2023
923122112061887234512/29/202344412/29/2023
1023122112173964697812/29/202344412/29/2023
1123122112274392043912/28/202311112/28/2023
1223122112274392043912/28/202311112/28/2023
1323122112274392043912/28/202311112/28/2023
1423122112364830432212/28/202322212/28/2023Location Translations.Title12/29/202312/28/2023
1523122112590730557512/28/202333312/28/202311121
1623122113293850664312/28/202344412/28/202322211
1723122113293850664312/28/202344412/28/202333311
1823122113293850664312/28/202344412/28/202344421
1923122113343088138112/28/202355512/28/202355501
Sheet1
Cell Formulas
RangeFormula
J1J1=F2
K1K1=F3
G2G2=SUMPRODUCT((A2:A10<>"")/COUNTIF(A2:A10,A2:A10&""))
G3G3=SUMPRODUCT((A11:A19<>"")/COUNTIF(A11:A19,A11:A19&""))
E2:E19E2=INT(B2)


thank you very much for your answering
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Is the Order Sn to be considered? You use it in your G2:G3 formulas, but your expected results results table seems to ignore the Order Sn. Are you familiar with Power Query? You can process the data source table and transform it into the desired output with a few steps. Note that my results don't look like your expected ones, so I might be misunderstanding something.
MrExcel_20231231.xlsx
MNO
1Location Translations.Title12/29/202312/28/2023
211153
322211
433311
544423
65551
Sheet2

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Updated At", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Location Translations.Title", "Updated At"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Grouped Rows", {{"Updated At", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Grouped Rows", {{"Updated At", type text}}, "en-US")[#"Updated At"]), "Updated At", "Count", List.Sum)
in
    #"Pivoted Column"
 
Upvote 0
I am not sure if this work for you. Please check-
Book1
IJK
1Location Translations.Title12/29/202312/28/2023
211121
322211
433311
544421
655501
Sheet1
Cell Formulas
RangeFormula
J1J1=F2
K1K1=F3
J2:K6J2=IFERROR(ROWS(UNIQUE(FILTER($A$2:$A$19,INT($B$2:$B$19)=INT(J$1*($C$2:$C$19=$I2))))), 0)

Thanks
 
Upvote 0
@Sam_D_Ben, the OP’s profile indicates that Excel 2019 is being used, so FILTER and UNIQUE would not be available…however, perhaps the profile is incorrect. Importantly, you are taking a count of unique Order Sn’s for each combination of “Location Translations.Title” and date. That may answer the question I posed and explain the discrepancy between my result and the expected.
 
Upvote 0
Is the Order Sn to be considered? You use it in your G2:G3 formulas, but your expected results results table seems to ignore the Order Sn. Are you familiar with Power Query? You can process the data source table and transform it into the desired output with a few steps. Note that my results don't look like your expected ones, so I might be misunderstanding something.
MrExcel_20231231.xlsx
MNO
1Location Translations.Title12/29/202312/28/2023
211153
322211
433311
544423
65551
Sheet2

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Updated At", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Location Translations.Title", "Updated At"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Grouped Rows", {{"Updated At", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Grouped Rows", {{"Updated At", type text}}, "en-US")[#"Updated At"]), "Updated At", "Count", List.Sum)
in
    #"Pivoted Column"
thank you very much for your reply, Krice

yes, colmun A - order SN is considered
my goal is need to return how many order SN base on column B and column C without duplicate calculation
as i said i am not a excel expert and i dont know power query so i use two stupid method to do it
first, extract the date and remove duplicate
second, maybe a sumifs in J2:K6

thanks again for the guidance
 
Upvote 0
I am not sure if this work for you. Please check-
Book1
IJK
1Location Translations.Title12/29/202312/28/2023
211121
322211
433311
544421
655501
Sheet1
Cell Formulas
RangeFormula
J1J1=F2
K1K1=F3
J2:K6J2=IFERROR(ROWS(UNIQUE(FILTER($A$2:$A$19,INT($B$2:$B$19)=INT(J$1*($C$2:$C$19=$I2))))), 0)

Thanks
thank you for your reply, Sam_D_Ben

i use v2016 at office and v2019 at home, both return "that function is invaild"
 
Upvote 0
Or try this in J2:

=COUNT(1/(ROW($A$2:$A$19)-1=MATCH($A$2:$A$19&J$1&$I2,$A$2:$A$19&INT($B$2:$B$19)&$C$2:$C$19,0)))

Enter with Ctrl+Shift+Enter.
 
Upvote 0
If you want to investigate using Power Query, copy the code below to your clipboard (click on the clipboard icon in the upper right as a shortcut). Then select any cell in your source table (perhaps cell B3) and then choose Data>Get Data>From Other Sources>From Table/Range. This will open up a small dialog box to convert your data range to an official Excel table. Confirm that the auto-detected range covers the correct range, and also confirm that your table has headings (in row 1 in this example). Power Query will automatically open and insert your table into it for processing. Then instead of using Power Query's Graphical User Interface to repeat the steps I've shown, you can take another shortcut: select View>Advanced Editor (which opens the PQ editor...this is where you can write code directly). Delete everything in the editor window and paste the code from your clipboard and confirm by clicking Done. You should see your processed/transformed results appear in PQ. Finally, from within PQ, click File>Close & Load and use the options to specify where you want the resulting table to be placed in your Excel workbook. I chose cell M1 of the current worksheet where the original source data are found, but you can specify other locations.

The advantage of this approach is that there are no formulas in your worksheet and you don't need to build the row and column headings or paste a counting formula through the results table...and it is dynamic. As your source table changes in size, the results can be refreshed by clicking on Data>Refresh All.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    // convert date/time format to date only
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Updated At", type date}}),
    // remove duplicate rows, leaving only unique combinations of Order Sn, Location Translations.Title, and Date
    #"Removed Duplicates" = Table.Distinct(#"Changed Type"),
    // group de-duplicated table by Location Translations.Title and Date, and count aggregated results (which is the number of Order Sn within that subgrouping
    #"Grouped Rows" = Table.Group(#"Removed Duplicates", {"Location Translations.Title", "Updated At"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    // pivot the table to show dates across the columns, Location Translations.Title in rows, and the counts of Order Sn's as the table data
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Grouped Rows", {{"Updated At", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Grouped Rows", {{"Updated At", type text}}, "en-US")[#"Updated At"]), "Updated At", "Count", List.Sum),
    // get all column names as list
    allColumnNames = Table.ColumnNames(#"Pivoted Column"),
    // transform col name list into a list of lists, where every inner list contains col name and a function for replacing null value
    allTransformations = List.Transform(allColumnNames, each {_, each if _ = null or _ = "" then 0 else _}),
    // apply the transformations
    transformColumns = Table.TransformColumns(#"Pivoted Column", allTransformations)
in
    transformColumns
MrExcel_20231231.xlsx
MNO
1Location Translations.Title12/29/202312/28/2023
211121
322211
433311
544421
655501
Sheet2
 
Upvote 0
The alternative using formulas is more involved, as you'll need to create the unique row and column headings, and then that table layout can be populated with a counting formula...I've adopted the version offered by @Phuoc. The rows and column heading formulas are entered in the first cell and then dragged across or down until blanks are returned, indicating all unique values are accounted for. Then the counting formula is copied throughout the table. I still prefer Power Query for this, but it's good to have options.
MrExcel_20231231.xlsx
MNOP
1Location Translations.Title12/29/202312/28/2023 
211121
322211
433311
544421
655501
7 
Sheet4
Cell Formulas
RangeFormula
N1:P1N1=IFERROR(INDEX(INT($B$2:$B$19),MATCH(0,INDEX(COUNTIF($M$1:M1,INT($B$2:$B$19)),0),0)),"")
N2:O6N2=COUNT(1/(ROW($A$2:$A$19)-1=MATCH($A$2:$A$19&N$1&$M2,$A$2:$A$19&INT($B$2:$B$19)&$C$2:$C$19,0)))
M2:M7M2=IFERROR(INDEX($C$2:$C$19,MATCH(0,INDEX(COUNTIF($M$1:M1,$C$2:$C$19),0),0)),"")
 
Upvote 0
Or try this in J2:

=COUNT(1/(ROW($A$2:$A$19)-1=MATCH($A$2:$A$19&J$1&$I2,$A$2:$A$19&INT($B$2:$B$19)&$C$2:$C$19,0)))

Enter with Ctrl+Shift+Enter.
thank you very much for your reply, Phuoc
this is really fantastic

however, i found my formula below dosent work as yours, and returns only "1"
and also, if my data is more than 1000, likely A2:A2000, it will be very very slow running even restart the workbook
=COUNT(1/(ROW($A$2:$A$100)-1=MATCH($A$2:$A$100&AF$1&$AE2,$A$2:$A$100&INT($E$2:$E$100)&$AE$2:$AE$10,0)))

thank you very much
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
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