Forum Discussion
Anonymous
3 years agoNot applicable
Flag column for first instance
I need to create a column that returns a 0 or a 1 based on the first instance. Could someone help me? Machine Work Order Material Batch Production Day Machine Scrap Good Qty xxxx xxx...
NaveenGandhi
3 years agoMemorable Member
Hello Anonymous
Your question is very unclear, Can you explain it a bit elaborate and also provide the desired output for the above sample data.
Regards,
Naveen
Anonymous
3 years agoNot applicable
This is what I would like it to do.
| Machine | Work Order | Material | Batch | Production Day | Machine Scrap | Good Qty | First Instance |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 | 1 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 | 1 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 | 1 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 | 1 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 | 1 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 | 1 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 | 0 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 | 0 |
- Ashish_Mathur3 years agoSuper User
Hi,
Even before we inser the First instance column, on what criteria should the data be sorted?
- Anonymous3 years agoNot applicable
Production Day and Machine
- Ashish_Mathur3 years agoSuper User
Hi,
This M code works
let Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Machine", type text}, {"Work Order", type text}, {"Material", type text}, {"Batch", type text}, {"Production Day", type datetime}, {"Machine Scrap", Int64.Type}, {"Good Qty", Int64.Type}}), #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Machine Scrap", Order.Ascending}, {"Production Day", Order.Ascending}}), Partition = Table.Group(#"Sorted Rows", {"Good Qty", "Production Day"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}), #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Machine", "Work Order", "Material", "Batch", "Machine Scrap", "Index"}, {"Machine", "Work Order", "Material", "Batch", "Machine Scrap", "Index"}), #"Added Custom" = Table.AddColumn(#"Expanded Partition", "Custom", each if [Index] = 1 then 1 else 0), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}) in #"Removed Columns"Hope this helps.