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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Loop for each cust ID... do this

i have customer ID and I have dates that repeat.  i created a function that returns the 1st item in list and says, if item = item from list then null else 1... BUT, how do I use this on each set of Cust_ID?   how do I loop each cust_id group and apply this logic?

 

please see screenshot, desired output is 3rd Col. 

here is code to get 1st item in list and compare to dates.  Just not sure how to loop each cust_id group to apply this to each cust-id thanks 

= Table.AddColumn(#"Reordered Columns", "try_index", each if [Quarter  Received_Date] = List.First( List.Distinct(#"Reordered Columns"[Quarter Received_Date])) then null else 1)

 

mts_1-1701917467961.png

 

 

1 ACCEPTED SOLUTION
spinfuzer
Super User
Super User

Group By first and then create the custom column in the grouped tables.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDJUCDRUitWB840UAo3Q+MZgvhGavBFOeROl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [cust_id = _t, purchase_date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"cust_id", Int64.Type}, {"purchase_date", type text}}),
    #"Grouped Rows" = Table.Group(
        #"Changed Type", 
        {"cust_id"}, 
        {   
            "index", 
            each Table.AddColumn(
                _,
                "index",
                (x) => if x[purchase_date] = List.First( List.Distinct(_[purchase_date])) then null else 1)
        }
        )
in
    #"Grouped Rows"

 

View solution in original post

1 REPLY 1
spinfuzer
Super User
Super User

Group By first and then create the custom column in the grouped tables.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDJUCDRUitWB840UAo3Q+MZgvhGavBFOeROl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [cust_id = _t, purchase_date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"cust_id", Int64.Type}, {"purchase_date", type text}}),
    #"Grouped Rows" = Table.Group(
        #"Changed Type", 
        {"cust_id"}, 
        {   
            "index", 
            each Table.AddColumn(
                _,
                "index",
                (x) => if x[purchase_date] = List.First( List.Distinct(_[purchase_date])) then null else 1)
        }
        )
in
    #"Grouped Rows"

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors