Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not 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?

 

MachineWork OrderMaterialBatchProduction DayMachine ScrapGood Qty
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM33103734164
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM33103734164
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM33103734164
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM33103734164
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM33103734164
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM29452744589
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM29452744589
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM29452744589
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM29452744589
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM29452744589
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM31577819528
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM31577819528
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM31577819528
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM31577819528
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM31577819528
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM37337422891
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM37337422891
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM37337422891
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM37337422891
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM37337422891
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM22584814593
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM22584814593
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM22584814593
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM22584814593
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM22584814593
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM27079981785
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM27079981785
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM27079981785
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM27079981785
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM27079981785
6 REPLIES 6
Anonymous
Not applicable

Hi  @Anonymous ,

 

Here are the steps you can follow:

1. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_0-1686797859674.png

2. Create calculated column.

First Instance =
IF(
    [Index]=
MINX(
    FILTER(ALL('Table'),'Table'[Good Qty]=EARLIER('Table'[Good Qty])),[Index]),1,0)

3. Result:

vyangliumsft_1-1686797859681.png

 

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

NaveenGandhi
Super User
Super User

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
Not applicable

This is what I would like it to do.

 

MachineWork OrderMaterialBatchProduction DayMachine ScrapGood QtyFirst Instance
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM331037341641
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM331037341640
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM331037341640
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM331037341640
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM331037341640
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM294527445891
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM294527445890
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM294527445890
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM294527445890
xxxxxxxxxxxxxxxx06/01/2023 12:00:00 AM294527445890
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM315778195281
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM315778195280
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM315778195280
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM315778195280
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM315778195280
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM373374228911
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM373374228910
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM373374228910
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM373374228910
xxxxxxxxxxxxxxxx06/02/2023 12:00:00 AM373374228910
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM225848145931
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM225848145930
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM225848145930
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM225848145930
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM225848145930
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM270799817851
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM270799817850
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM270799817850
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM270799817850
xxxxxxxxxxxxxxxx06/03/2023 12:00:00 AM270799817850

Hi,

Even before we inser the First instance column, on what criteria should the data be sorted?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

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.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.