Populate Date Based On Non-Modal Count?

xlmaniac

Well-known Member
Joined
Jul 2, 2009
Messages
527
Office Version
  1. 2010
Platform
  1. Windows
Dear All,
I do have a sample data set across A1:E4.
The data represents the NO Of BINs in which the SKU is kept at the DC.
I would like to figure out the dates on which the no of BINs is more than the Modal no of BINs across a given period.
The formulae put in F2=COUNTIF(B2:E2,"<>"&MODE(B2:E2)) & so on.
Could somebody help me out with the formulae across G2:G4 which can populate the desired result as shown below?

SKU01-Oct02-Oct03-Oct04-OctNon Modal FrequencyDesired Result
A4344102-Oct
B88910203.10.2017/04.10.2017
C12151212102-Oct

<tbody>
</tbody>
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Re: How To Populate Date Based On Non-Modal Count?

Try this, copied across and down.


Book1
ABCDEFGHI
1SKU1-Oct2-Oct3-Oct4-OctNon Modal FrequencyDesired Result
2A434412-Oct
3B8891023-Oct4-Oct
4C1215121212-Oct
Non modal Dates
Cell Formulas
RangeFormula
G2=IFERROR(AGGREGATE(15,6,$B$1:$E$1/($B2:$E2<>MODE($B2:$E2)),COLUMNS($G2:G2)),"")
 
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

If you wanted the results in a single cell and you have Excel 2016 through Office 365 then try this. It is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down.


Book1
ABCDEFG
1SKU1-Oct2-Oct3-Oct4-OctNon Modal FrequencyDesired Result
2A434412-Oct
3B8891023-Oct/4-Oct
4C1215121212-Oct
Non modal Dates (2)
Cell Formulas
RangeFormula
G2{=TEXTJOIN("/",TRUE,IF(B2:E2<>MODE(B2:E2),TEXT(B$1:E$1,"d-mmm"),""))}
Press CTRL+SHIFT+ENTER to enter array formulas.



If you wanted this in a single cell and you don't have the TEXTJOIN function then
a) How many date columns do you really have?
b) Would a vba solution be acceptable?
 
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

If you wanted the results in a single cell and you have Excel 2016 through Office 365 then try this. It is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down.

ABCDEFG
1SKU1-Oct2-Oct3-Oct4-OctNon Modal FrequencyDesired Result
2A434412-Oct
3B8891023-Oct/4-Oct
4C1215121212-Oct

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Non modal Dates (2)

Array Formulas
CellFormula
G2{=TEXTJOIN("/",TRUE,IF(B2:E2<>MODE(B2:E2),TEXT(B$1:E$1,"d-mmm"),""))}

<thead>
</thead><tbody>
</tbody>
Enter without the {} but confirm with Ctrl+Shift+Enter, not just Enter
If entered correctly, Excel will insert the {}

<tbody>
</tbody>




If you wanted this in a single cell and you don't have the TEXTJOIN function then
a) How many date columns do you really have?
b) Would a vba solution be acceptable?

Dear Sir,
Thanks a lot for the mesmerising solution.
I have Office 2010.
The columns will vary between 30(Min) to 120 Nos.
Pls provide a VBA Solution which can yield the result. It will be OK with me.
Regards
 
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

Confirming then that you want all the results in a single cell on each row, not separate cells like in post #2 ?

Also, with up to 120 columns, it would seem quite possible that there could be more than one mode. Is that possible and, if so, how should we deal with it?

For example, what should the result below be?


Book1
ABCDEFGH
1SKU1-Oct2-Oct3-Oct4-Oct5-Oct6-Oct7-Oct
2A4336542
Non modal Dates
 
Last edited:
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

Confirming then that you want all the results in a single cell on each row, not separate cells like in post #2 ?

Also, with up to 120 columns, it would seem quite possible that there could be more than one mode. Is that possible and, if so, how should we deal with it?

For example, what should the result below be?

ABCDEFGH
1SKU1-Oct2-Oct3-Oct4-Oct5-Oct6-Oct7-Oct
2A4336542

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Non modal Dates

Dear Sir,
Thanks a lot for your reply.
In a span of 4 months, there could be maximum 4 instances of deviation(against a particular SKU) since we have put a validation in system so that once 4th occurrences are made system will not allow to breach.
Due to this, there will be no effect on the modal number.
The code should be able to populate maximum 4 dates in a cell across 120 columns.
Pls help.
Regards
 
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

This assumes
- the date columns are B:DQ (120 columns) and puts the results in column DT.
- values to be checked against the mode are whole numbers like the sample data.

Test in a copy of your workbook.

Code:
Sub NonModaldates()
  Dim a As Variant
  Dim i As Long, j As Long, ModeVal As Long, cols As Long
  Dim s As String
  
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, 121).Value
  cols = UBound(a, 2)
  For i = 2 To UBound(a)
   ModeVal = Application.Mode(Application.Index(a, i, 0))
   s = ""
   For j = 2 To cols
     If a(i, j) <> ModeVal And a(i, j) <> "" Then
       s = s & "/" & Format(a(1, j), "d-mmm")
     End If
   Next j
   a(i, 1) = Mid(s, 2)
  Next i
  With Range("A1").Offset(, cols + 2).Resize(UBound(a))
    .Value = Application.Index(a, 0, 1)
    .Cells(1).Value = "Non-Modal Date(s)"
    .Columns.AutoFit
  End With
End Sub
 
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

This assumes
- the date columns are B:DQ (120 columns) and puts the results in column DT.
- values to be checked against the mode are whole numbers like the sample data.

Test in a copy of your workbook.

Code:
Sub NonModaldates()
  Dim a As Variant
  Dim i As Long, j As Long, ModeVal As Long, cols As Long
  Dim s As String
  
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, 121).Value
  cols = UBound(a, 2)
  For i = 2 To UBound(a)
   ModeVal = Application.Mode(Application.Index(a, i, 0))
   s = ""
   For j = 2 To cols
     If a(i, j) <> ModeVal And a(i, j) <> "" Then
       s = s & "/" & Format(a(1, j), "d-mmm")
     End If
   Next j
   a(i, 1) = Mid(s, 2)
  Next i
  With Range("A1").Offset(, cols + 2).Resize(UBound(a))
    .Value = Application.Index(a, 0, 1)
    .Cells(1).Value = "Non-Modal Date(s)"
    .Columns.AutoFit
  End With
End Sub

Dear Sir,
My sincere gratitude for helping me out with the VBA solution.
I have incorporated the code and have tried to run the same.
But it is throwing an error:-"Run Time Error 13" Type Mismatch.
Pls help in fixing the same.
Regards
 
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

But it is throwing an error:-"Run Time Error 13" Type Mismatch.
What line of code is causing the error (Click Debug)?
 
Upvote 0
Re: How To Populate Date Based On Non-Modal Count?

Dear Sir,
My sincere gratitude for helping me out with the VBA solution.
I have incorporated the code and have tried to run the same.
But it is throwing an error:-"Run Time Error 13" Type Mismatch.
Pls help in fixing the same.
Regards

Dear Sir,
The following line is highlighted while clicking the Debug button:-

ModeVal = Application.Mode(Application.Index(a, i, 0))

Regards
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,549
Members
449,170
Latest member
Gkiller

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