Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more
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 | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 33103 | 734164 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 |
| xxxx | xxxx | xxxx | xxxx | 06/01/2023 12:00:00 AM | 29452 | 744589 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 31577 | 819528 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 |
| xxxx | xxxx | xxxx | xxxx | 06/02/2023 12:00:00 AM | 37337 | 422891 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 22584 | 814593 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 |
| xxxx | xxxx | xxxx | xxxx | 06/03/2023 12:00:00 AM | 27079 | 981785 |
Hi @Anonymous ,
Here are the steps you can follow:
1. In Power Query -- Add Column – Index Column – From 1.
2. Create calculated column.
First Instance =
IF(
[Index]=
MINX(
FILTER(ALL('Table'),'Table'[Good Qty]=EARLIER('Table'[Good Qty])),[Index]),1,0)
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
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
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 |
Hi,
Even before we inser the First instance column, on what criteria should the data be sorted?
Production Day and Machine
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.
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!
Check out the July 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 30 | |
| 28 | |
| 24 | |
| 23 | |
| 17 |
| User | Count |
|---|---|
| 46 | |
| 32 | |
| 17 | |
| 17 | |
| 16 |