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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
Memorable Member
Memorable 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
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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors