Generate Batch ID

arnabmit

New Member
Joined
Mar 28, 2009
Messages
27
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi,

I am trying to generate Batch ID based on Course, Date, & Time. I have managed to get result on sample data, but when I put it in 5000+ rows, it doesn't seem to work (no longer increments batch number based on unique criteria)

  • Am I going about in an un-necessarily long-winded way?
  • Is there an easy way to do this?
  • Can this be done without the helper column?

No VBA, only Excel 2016 formula, please.

BatchID.xlsx
ABCDEFG
1StudentIDTeacherCourseDateTimeHelperBatch ID
21234AbcWord1-Sep9:001WOR001
32345AbcWord1-Sep9:000WOR001
43456DefPowerPoint1-Sep9:001POW001
54567AbcWord1-Sep12:001WOR002
65678DefPowerPoint1-Sep12:001POW002
76789XyzExcel1-Sep12:001EXC001
87890AbcWord1-Sep12:000WOR002
98901XyzExcel1-Sep12:000EXC001
109012DefPowerPoint1-Sep12:000POW002
111234XyzExcel2-Sep9:001EXC002
122345DefPowerPoint2-Sep12:001POW003
133456AbcWord2-Sep12:001WOR003
144567XyzExcel2-Sep9:000EXC002
155678DefPowerPoint2-Sep12:000POW003
166789AbcWord2-Sep12:000WOR003
177890XyzExcel2-Sep12:001EXC003
188901AbcWord2-Sep12:000WOR003
199012XyzExcel2-Sep12:000EXC003
201234DefPowerPoint3-Sep15:001POW004
212345XyzExcel3-Sep9:001EXC004
223456AbcWord3-Sep15:001WOR004
234567XyzExcel3-Sep9:000EXC004
245678XyzExcel3-Sep12:001EXC005
256789AbcWord3-Sep15:000WOR004
267890XyzExcel3-Sep12:000EXC005
278901DefPowerPoint3-Sep15:000POW004
289012AbcWord3-Sep15:000WOR004
Sheet1
Cell Formulas
RangeFormula
F2:F28F2=IF(SUMPRODUCT(($C$2:C2=C2)*($D$2:D2=D2)*($E$2:E2=E2))>1,0,1)
G2:G28G2=UPPER(LEFT(C2,3))&TEXT(SUMPRODUCT(($C$2:C2=C2)*($F$2:F2=1)),"000")
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi there

Why not just concatenate the 3 variables then its bound to be unique.
 
Upvote 0
e.g.:
Book1
ABCDEFG
1StudentIDTeacherCourseDateTimeHelperBatch ID
21234AbcWord1.9.2009:00:001Word01092009:00
32345AbcWord1.9.2009:00:000Word01092009:00
43456DefPowerPoint1.9.2009:00:001PowerPoint01092009:00
54567AbcWord1.9.2012:00:001Word01092012:00
65678DefPowerPoint1.9.2012:00:001PowerPoint01092012:00
76789XyzExcel1.9.2012:00:001Excel01092012:00
87890AbcWord1.9.2012:00:000Word01092012:00
98901XyzExcel1.9.2012:00:000Excel01092012:00
109012DefPowerPoint1.9.2012:00:000PowerPoint01092012:00
111234XyzExcel2.9.2009:00:001Excel02092009:00
122345DefPowerPoint2.9.2012:00:001PowerPoint02092012:00
133456AbcWord2.9.2012:00:001Word02092012:00
144567XyzExcel2.9.2009:00:000Excel02092009:00
155678DefPowerPoint2.9.2012:00:000PowerPoint02092012:00
166789AbcWord2.9.2012:00:000Word02092012:00
177890XyzExcel2.9.2012:00:001Excel02092012:00
188901AbcWord2.9.2012:00:000Word02092012:00
Sheet1
Cell Formulas
RangeFormula
F2:F18F2=IF(SUMPRODUCT(($C$2:C2=C2)*($D$2:D2=D2)*($E$2:E2=E2))>1,0,1)
G2:G18G2=C2&TEXT(D2,"ddmmyy")&TEXT(E2,"hh:mm")
 
Upvote 0
e.g.:
Book1
ABCDEFG
1StudentIDTeacherCourseDateTimeHelperBatch ID
21234AbcWord1.9.2009:00:001Word01092009:00
32345AbcWord1.9.2009:00:000Word01092009:00
43456DefPowerPoint1.9.2009:00:001PowerPoint01092009:00
54567AbcWord1.9.2012:00:001Word01092012:00
65678DefPowerPoint1.9.2012:00:001PowerPoint01092012:00
76789XyzExcel1.9.2012:00:001Excel01092012:00
87890AbcWord1.9.2012:00:000Word01092012:00
98901XyzExcel1.9.2012:00:000Excel01092012:00
109012DefPowerPoint1.9.2012:00:000PowerPoint01092012:00
111234XyzExcel2.9.2009:00:001Excel02092009:00
122345DefPowerPoint2.9.2012:00:001PowerPoint02092012:00
133456AbcWord2.9.2012:00:001Word02092012:00
144567XyzExcel2.9.2009:00:000Excel02092009:00
155678DefPowerPoint2.9.2012:00:000PowerPoint02092012:00
166789AbcWord2.9.2012:00:000Word02092012:00
177890XyzExcel2.9.2012:00:001Excel02092012:00
188901AbcWord2.9.2012:00:000Word02092012:00
Sheet1
Cell Formulas
RangeFormula
F2:F18F2=IF(SUMPRODUCT(($C$2:C2=C2)*($D$2:D2=D2)*($E$2:E2=E2))>1,0,1)
G2:G18G2=C2&TEXT(D2,"ddmmyy")&TEXT(E2,"hh:mm")
I wondered the same, however It needs to be in the specified (existing) format as Batch ID is used as a primary key in the data model.
 
Upvote 0
It doesn't look like in your example you've shown how your formula fails. It looks like your formula works. Who knows what happens further down the line though.

Anyway, this doesn't get rid of the helper column, but it matches the output and might work where your original formula is failing. To make this work I first sorted the data by Course => then by Date => then by Time, and added the new helper column and ID columns H:I.

Dice.xlsm
ABCDEFGHIJ
1StudentIDTeacherCourseDateTimeHelperBatch IDHelper2bIDCheck
26789XyzExcel9/1/202012:00:00 PM1EXC0011EXC001TRUE
38901XyzExcel9/1/202012:00:00 PM0EXC0011EXC001TRUE
41234XyzExcel9/2/20209:00:00 AM1EXC0022EXC002TRUE
54567XyzExcel9/2/20209:00:00 AM0EXC0022EXC002TRUE
67890XyzExcel9/2/202012:00:00 PM1EXC0033EXC003TRUE
79012XyzExcel9/2/202012:00:00 PM0EXC0033EXC003TRUE
82345XyzExcel9/3/20209:00:00 AM1EXC0044EXC004TRUE
94567XyzExcel9/3/20209:00:00 AM0EXC0044EXC004TRUE
105678XyzExcel9/3/202012:00:00 PM1EXC0055EXC005TRUE
117890XyzExcel9/3/202012:00:00 PM0EXC0055EXC005TRUE
123456DefPowerPoint9/1/20209:00:00 AM1POW0011POW001TRUE
135678DefPowerPoint9/1/202012:00:00 PM1POW0022POW002TRUE
149012DefPowerPoint9/1/202012:00:00 PM0POW0022POW002TRUE
152345DefPowerPoint9/2/202012:00:00 PM1POW0033POW003TRUE
165678DefPowerPoint9/2/202012:00:00 PM0POW0033POW003TRUE
171234DefPowerPoint9/3/20203:00:00 PM1POW0044POW004TRUE
188901DefPowerPoint9/3/20203:00:00 PM0POW0044POW004TRUE
191234AbcWord9/1/20209:00:00 AM1WOR0011WOR001TRUE
202345AbcWord9/1/20209:00:00 AM0WOR0011WOR001TRUE
214567AbcWord9/1/202012:00:00 PM1WOR0022WOR002TRUE
227890AbcWord9/1/202012:00:00 PM0WOR0022WOR002TRUE
233456AbcWord9/2/202012:00:00 PM1WOR0033WOR003TRUE
246789AbcWord9/2/202012:00:00 PM0WOR0033WOR003TRUE
258901AbcWord9/2/202012:00:00 PM0WOR0033WOR003TRUE
263456AbcWord9/3/20203:00:00 PM1WOR0044WOR004TRUE
276789AbcWord9/3/20203:00:00 PM0WOR0044WOR004TRUE
289012AbcWord9/3/20203:00:00 PM0WOR0044WOR004TRUE
Sheet3
Cell Formulas
RangeFormula
F2:F28F2=IF(SUMPRODUCT(($C$2:C2=C2)*($D$2:D2=D2)*($E$2:E2=E2))>1,0,1)
G2:G28G2=UPPER(LEFT(C2,3))&TEXT(SUMPRODUCT(($C$2:C2=C2)*($F$2:F2=1)),"000")
H2:H28H2=IF(C2&D2&E2=C1&D1&E1,H1,IF(C2=C1,H1+1,1))
I2:I28I2=UPPER(LEFT(C2,3))&TEXT(H2,"000")
J2:J28J2=I2=G2
 
Upvote 0
It doesn't look like in your example you've shown how your formula fails. It looks like your formula works. Who knows what happens further down the line though.

Anyway, this doesn't get rid of the helper column, but it matches the output and might work where your original formula is failing. To make this work I first sorted the data by Course => then by Date => then by Time, and added the new helper column and ID columns H:I.

Dice.xlsm
ABCDEFGHIJ
1StudentIDTeacherCourseDateTimeHelperBatch IDHelper2bIDCheck
26789XyzExcel9/1/202012:00:00 PM1EXC0011EXC001TRUE
38901XyzExcel9/1/202012:00:00 PM0EXC0011EXC001TRUE
41234XyzExcel9/2/20209:00:00 AM1EXC0022EXC002TRUE
54567XyzExcel9/2/20209:00:00 AM0EXC0022EXC002TRUE
67890XyzExcel9/2/202012:00:00 PM1EXC0033EXC003TRUE
79012XyzExcel9/2/202012:00:00 PM0EXC0033EXC003TRUE
82345XyzExcel9/3/20209:00:00 AM1EXC0044EXC004TRUE
94567XyzExcel9/3/20209:00:00 AM0EXC0044EXC004TRUE
105678XyzExcel9/3/202012:00:00 PM1EXC0055EXC005TRUE
117890XyzExcel9/3/202012:00:00 PM0EXC0055EXC005TRUE
123456DefPowerPoint9/1/20209:00:00 AM1POW0011POW001TRUE
135678DefPowerPoint9/1/202012:00:00 PM1POW0022POW002TRUE
149012DefPowerPoint9/1/202012:00:00 PM0POW0022POW002TRUE
152345DefPowerPoint9/2/202012:00:00 PM1POW0033POW003TRUE
165678DefPowerPoint9/2/202012:00:00 PM0POW0033POW003TRUE
171234DefPowerPoint9/3/20203:00:00 PM1POW0044POW004TRUE
188901DefPowerPoint9/3/20203:00:00 PM0POW0044POW004TRUE
191234AbcWord9/1/20209:00:00 AM1WOR0011WOR001TRUE
202345AbcWord9/1/20209:00:00 AM0WOR0011WOR001TRUE
214567AbcWord9/1/202012:00:00 PM1WOR0022WOR002TRUE
227890AbcWord9/1/202012:00:00 PM0WOR0022WOR002TRUE
233456AbcWord9/2/202012:00:00 PM1WOR0033WOR003TRUE
246789AbcWord9/2/202012:00:00 PM0WOR0033WOR003TRUE
258901AbcWord9/2/202012:00:00 PM0WOR0033WOR003TRUE
263456AbcWord9/3/20203:00:00 PM1WOR0044WOR004TRUE
276789AbcWord9/3/20203:00:00 PM0WOR0044WOR004TRUE
289012AbcWord9/3/20203:00:00 PM0WOR0044WOR004TRUE
Sheet3
Cell Formulas
RangeFormula
F2:F28F2=IF(SUMPRODUCT(($C$2:C2=C2)*($D$2:D2=D2)*($E$2:E2=E2))>1,0,1)
G2:G28G2=UPPER(LEFT(C2,3))&TEXT(SUMPRODUCT(($C$2:C2=C2)*($F$2:F2=1)),"000")
H2:H28H2=IF(C2&D2&E2=C1&D1&E1,H1,IF(C2=C1,H1+1,1))
I2:I28I2=UPPER(LEFT(C2,3))&TEXT(H2,"000")
J2:J28J2=I2=G2
Thanks! will try it, though I might not be allowed to sort the data though. Could you think of any alternate way to generate the IDs?
 
Upvote 0
I don't understand this task. Is this for work? Why would you not be able to sort data...?

Anyway, you said no VBA. But, you also said you have Excel 2016. Which means you have Power Query.

Now if, for some reason I can't imagine, you can't sort the data, I really wonder about the probability of being able to use Power Query... But hey, here it goes anyway.

Book1
ABCDEFGHIJKLMN
1StudentIDTeacherCourseDateTimeHelperBatch IDStudentIDTeacherCourseDateTimeBatchID
21234AbcWord9/1/20209:00:00 AM1WOR0011234AbcWord9/1/20209:00:00 AMWOR001
32345AbcWord9/1/20209:00:00 AM0WOR0012345AbcWord9/1/20209:00:00 AMWOR001
43456DefPowerPoint9/1/20209:00:00 AM1POW0013456DefPowerPoint9/1/20209:00:00 AMPOW001
54567AbcWord9/1/202012:00:00 PM1WOR0024567AbcWord9/1/202012:00:00 PMWOR002
65678DefPowerPoint9/1/202012:00:00 PM1POW0025678DefPowerPoint9/1/202012:00:00 PMPOW002
76789XyzExcel9/1/202012:00:00 PM1EXC0016789XyzExcel9/1/202012:00:00 PMEXC001
87890AbcWord9/1/202012:00:00 PM0WOR0027890AbcWord9/1/202012:00:00 PMWOR002
98901XyzExcel9/1/202012:00:00 PM0EXC0018901XyzExcel9/1/202012:00:00 PMEXC001
109012DefPowerPoint9/1/202012:00:00 PM0POW0029012DefPowerPoint9/1/202012:00:00 PMPOW002
111234XyzExcel9/2/20209:00:00 AM1EXC0021234XyzExcel9/2/20209:00:00 AMEXC002
122345DefPowerPoint9/2/202012:00:00 PM1POW0032345DefPowerPoint9/2/202012:00:00 PMPOW003
133456AbcWord9/2/202012:00:00 PM1WOR0033456AbcWord9/2/202012:00:00 PMWOR003
144567XyzExcel9/2/20209:00:00 AM0EXC0024567XyzExcel9/2/20209:00:00 AMEXC002
155678DefPowerPoint9/2/202012:00:00 PM0POW0035678DefPowerPoint9/2/202012:00:00 PMPOW003
166789AbcWord9/2/202012:00:00 PM0WOR0036789AbcWord9/2/202012:00:00 PMWOR003
177890XyzExcel9/2/202012:00:00 PM1EXC0037890XyzExcel9/2/202012:00:00 PMEXC003
188901AbcWord9/2/202012:00:00 PM0WOR0038901AbcWord9/2/202012:00:00 PMWOR003
199012XyzExcel9/2/202012:00:00 PM0EXC0039012XyzExcel9/2/202012:00:00 PMEXC003
201234DefPowerPoint9/3/20203:00:00 PM1POW0041234DefPowerPoint9/3/20203:00:00 PMPOW004
212345XyzExcel9/3/20209:00:00 AM1EXC0042345XyzExcel9/3/20209:00:00 AMEXC004
223456AbcWord9/3/20203:00:00 PM1WOR0043456AbcWord9/3/20203:00:00 PMWOR004
234567XyzExcel9/3/20209:00:00 AM0EXC0044567XyzExcel9/3/20209:00:00 AMEXC004
245678XyzExcel9/3/202012:00:00 PM1EXC0055678XyzExcel9/3/202012:00:00 PMEXC005
256789AbcWord9/3/20203:00:00 PM0WOR0046789AbcWord9/3/20203:00:00 PMWOR004
267890XyzExcel9/3/202012:00:00 PM0EXC0057890XyzExcel9/3/202012:00:00 PMEXC005
278901DefPowerPoint9/3/20203:00:00 PM0POW0048901DefPowerPoint9/3/20203:00:00 PMPOW004
289012AbcWord9/3/20203:00:00 PM0WOR0049012AbcWord9/3/20203:00:00 PMWOR004
Sheet1
Cell Formulas
RangeFormula
F2:F28F2=IF(SUMPRODUCT(($C$2:C2=C2)*($D$2:D2=D2)*($E$2:E2=E2))>1,0,1)
G2:G28G2=UPPER(LEFT(C2,3))&TEXT(SUMPRODUCT(($C$2:C2=C2)*($F$2:F2=1)),"000")


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ID = Table.AddIndexColumn(Source, "IDX", 0, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(ID, {"Course", "Date", "Time"}, {{"Count", each _, type table [StudentID=nullable number, Teacher=nullable text, Course=nullable text, Date=nullable date, Time=nullable time]}}),
    Index = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1, Int64.Type),
    RunningCount = Table.AddColumn(Index, "Custom", (OT) => Table.RowCount(Table.SelectRows(Index, (IT)=> IT[Index] <= OT[Index] and IT[Course] = OT[Course]))),
    BatchID = Table.AddColumn(RunningCount, "Custom.1", each Text.Upper(Text.Start([Course],3))&Text.PadStart(Text.From([Custom]),3,"0")),
    Expand = Table.ExpandTableColumn(BatchID, "Count", {"StudentID", "Teacher", "Course", "Date", "Time", "IDX"}, {"Count.StudentID", "Count.Teacher", "Count.Course", "Count.Date", "Count.Time","Count.IDX"}),
    Types = Table.TransformColumnTypes(Expand,{{"Date", type date}, {"Time", type time}, {"Count.StudentID", Int64.Type}, {"Count.IDX", Int64.Type}, {"Index", Int64.Type}, {"Custom", Int64.Type}, {"Custom.1", type text}, {"Count.Date", Int64.Type}, {"Count.Time", type number}}),
    Sort = Table.Sort(Types,{{"Count.IDX", Order.Ascending}}),
    SC = Table.SelectColumns(Sort,{"Count.StudentID", "Count.Teacher", "Count.Course", "Count.Date", "Count.Time", "Custom.1"}),
    RC = Table.RenameColumns(SC,{{"Custom.1", "BatchID"}, {"Count.StudentID", "StudentID"}, {"Count.Teacher", "Teacher"}, {"Count.Course", "Course"}, {"Count.Date", "Date"}, {"Count.Time", "Time"}})
in
    RC
 
Upvote 0
Solution
I don't understand this task. Is this for work? Why would you not be able to sort data...?

Anyway, you said no VBA. But, you also said you have Excel 2016. Which means you have Power Query.

Now if, for some reason I can't imagine, you can't sort the data, I really wonder about the probability of being able to use Power Query... But hey, here it goes anyway.

Book1
ABCDEFGHIJKLMN
1StudentIDTeacherCourseDateTimeHelperBatch IDStudentIDTeacherCourseDateTimeBatchID
21234AbcWord9/1/20209:00:00 AM1WOR0011234AbcWord9/1/20209:00:00 AMWOR001
32345AbcWord9/1/20209:00:00 AM0WOR0012345AbcWord9/1/20209:00:00 AMWOR001
43456DefPowerPoint9/1/20209:00:00 AM1POW0013456DefPowerPoint9/1/20209:00:00 AMPOW001
54567AbcWord9/1/202012:00:00 PM1WOR0024567AbcWord9/1/202012:00:00 PMWOR002
65678DefPowerPoint9/1/202012:00:00 PM1POW0025678DefPowerPoint9/1/202012:00:00 PMPOW002
76789XyzExcel9/1/202012:00:00 PM1EXC0016789XyzExcel9/1/202012:00:00 PMEXC001
87890AbcWord9/1/202012:00:00 PM0WOR0027890AbcWord9/1/202012:00:00 PMWOR002
98901XyzExcel9/1/202012:00:00 PM0EXC0018901XyzExcel9/1/202012:00:00 PMEXC001
109012DefPowerPoint9/1/202012:00:00 PM0POW0029012DefPowerPoint9/1/202012:00:00 PMPOW002
111234XyzExcel9/2/20209:00:00 AM1EXC0021234XyzExcel9/2/20209:00:00 AMEXC002
122345DefPowerPoint9/2/202012:00:00 PM1POW0032345DefPowerPoint9/2/202012:00:00 PMPOW003
133456AbcWord9/2/202012:00:00 PM1WOR0033456AbcWord9/2/202012:00:00 PMWOR003
144567XyzExcel9/2/20209:00:00 AM0EXC0024567XyzExcel9/2/20209:00:00 AMEXC002
155678DefPowerPoint9/2/202012:00:00 PM0POW0035678DefPowerPoint9/2/202012:00:00 PMPOW003
166789AbcWord9/2/202012:00:00 PM0WOR0036789AbcWord9/2/202012:00:00 PMWOR003
177890XyzExcel9/2/202012:00:00 PM1EXC0037890XyzExcel9/2/202012:00:00 PMEXC003
188901AbcWord9/2/202012:00:00 PM0WOR0038901AbcWord9/2/202012:00:00 PMWOR003
199012XyzExcel9/2/202012:00:00 PM0EXC0039012XyzExcel9/2/202012:00:00 PMEXC003
201234DefPowerPoint9/3/20203:00:00 PM1POW0041234DefPowerPoint9/3/20203:00:00 PMPOW004
212345XyzExcel9/3/20209:00:00 AM1EXC0042345XyzExcel9/3/20209:00:00 AMEXC004
223456AbcWord9/3/20203:00:00 PM1WOR0043456AbcWord9/3/20203:00:00 PMWOR004
234567XyzExcel9/3/20209:00:00 AM0EXC0044567XyzExcel9/3/20209:00:00 AMEXC004
245678XyzExcel9/3/202012:00:00 PM1EXC0055678XyzExcel9/3/202012:00:00 PMEXC005
256789AbcWord9/3/20203:00:00 PM0WOR0046789AbcWord9/3/20203:00:00 PMWOR004
267890XyzExcel9/3/202012:00:00 PM0EXC0057890XyzExcel9/3/202012:00:00 PMEXC005
278901DefPowerPoint9/3/20203:00:00 PM0POW0048901DefPowerPoint9/3/20203:00:00 PMPOW004
289012AbcWord9/3/20203:00:00 PM0WOR0049012AbcWord9/3/20203:00:00 PMWOR004
Sheet1
Cell Formulas
RangeFormula
F2:F28F2=IF(SUMPRODUCT(($C$2:C2=C2)*($D$2:D2=D2)*($E$2:E2=E2))>1,0,1)
G2:G28G2=UPPER(LEFT(C2,3))&TEXT(SUMPRODUCT(($C$2:C2=C2)*($F$2:F2=1)),"000")


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ID = Table.AddIndexColumn(Source, "IDX", 0, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(ID, {"Course", "Date", "Time"}, {{"Count", each _, type table [StudentID=nullable number, Teacher=nullable text, Course=nullable text, Date=nullable date, Time=nullable time]}}),
    Index = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1, Int64.Type),
    RunningCount = Table.AddColumn(Index, "Custom", (OT) => Table.RowCount(Table.SelectRows(Index, (IT)=> IT[Index] <= OT[Index] and IT[Course] = OT[Course]))),
    BatchID = Table.AddColumn(RunningCount, "Custom.1", each Text.Upper(Text.Start([Course],3))&Text.PadStart(Text.From([Custom]),3,"0")),
    Expand = Table.ExpandTableColumn(BatchID, "Count", {"StudentID", "Teacher", "Course", "Date", "Time", "IDX"}, {"Count.StudentID", "Count.Teacher", "Count.Course", "Count.Date", "Count.Time","Count.IDX"}),
    Types = Table.TransformColumnTypes(Expand,{{"Date", type date}, {"Time", type time}, {"Count.StudentID", Int64.Type}, {"Count.IDX", Int64.Type}, {"Index", Int64.Type}, {"Custom", Int64.Type}, {"Custom.1", type text}, {"Count.Date", Int64.Type}, {"Count.Time", type number}}),
    Sort = Table.Sort(Types,{{"Count.IDX", Order.Ascending}}),
    SC = Table.SelectColumns(Sort,{"Count.StudentID", "Count.Teacher", "Count.Course", "Count.Date", "Count.Time", "Custom.1"}),
    RC = Table.RenameColumns(SC,{{"Custom.1", "BatchID"}, {"Count.StudentID", "StudentID"}, {"Count.Teacher", "Teacher"}, {"Count.Course", "Course"}, {"Count.Date", "Date"}, {"Count.Time", "Time"}})
in
    RC
I inherited legacy database, and trying to make it efficient. Sheet contains 200,000 plus rows with 30+ columns. there are at least 4 columns with sumproduct formula to calculate conditional unique numbers. A sort triggers all the formulas to recalculate, which freezes excel for 3-4 hours.

Will it be possible to guide me on how to use the power query? I know how to import tables as query, but don't know how or where to put in the code.
 
Upvote 0
I copied your data from post #1 using the XL2BB copy icon and pasted it into my workbook. Then I select any cell in the range I just pasted. Then, hit Alt+A+T+P. This adds the data to PQ. Then, in the PQ editor, under the 'Home' tab, I think, you click 'Advanced Editor' and paste the M code I posted before. Then close and load and it should be good to go. I did have to fiddle with the data types for the date and time fields, but it should work regardless.
 
Upvote 0
I copied your data from post #1 using the XL2BB copy icon and pasted it into my workbook. Then I select any cell in the range I just pasted. Then, hit Alt+A+T+P. This adds the data to PQ. Then, in the PQ editor, under the 'Home' tab, I think, you click 'Advanced Editor' and paste the M code I posted before. Then close and load and it should be good to go. I did have to fiddle with the data types for the date and time fields, but it should work regardless.
Great! I will try this.

Meanwhile, can I do something like this in a calculated column using DAX, instead of M code? This is so that I can modify it later if needed if parameters change.
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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