This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
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.
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 36 | |
| 32 | |
| 26 | |
| 24 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 50 | |
| 31 | |
| 26 | |
| 22 |