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

The 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

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.