Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreThe FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 53 | |
| 40 | |
| 38 | |
| 19 | |
| 18 |
| User | Count |
|---|---|
| 69 | |
| 68 | |
| 34 | |
| 33 | |
| 30 |