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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
EnricoGiordano
Regular Visitor

How to find first order info per user id

Hello everyone,

 

is there a simple way to find and calculate, for each customer of my table, the first order date and the correlated information? Such as the quantity and the price he paid?

 

I have a table like this:

 

profile_id

order_date

quantity

price

 

Thanks!

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

8 REPLIES 8
Ahmedx
Super User
Super User

and this in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY5BDsAgCAT/wtkYWKvx2vYZxv9/Q5DUNBzYTRgWGIOkZa4ZjEKJRKuaQ+WmmZTjx63dzFnlcd5DfjufPDjkr2//61wC31npZ4BLOGBDgD8wFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [order_date = _t, customer_id = _t, quantity = _t, #"revenue €" = _t, product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"order_date", type date}, {"customer_id", Int64.Type}, {"quantity", Int64.Type}, {"revenue €", Int64.Type}, {"product", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"customer_id"}, {{"Count", (x)=> Table.SelectRows(x, (y)=> y[order_date] = List.Min(x[order_date]) )
}}),
    #"Removed Other Columns" = Table.Combine( Table.SelectColumns(#"Grouped Rows",{"Count"})[Count])
in
    #"Removed Other Columns"

 

Ahmedx
Super User
Super User

try this

Screen Capture #1269.png

Anonymous
Not applicable

Hi @EnricoGiordano ,

 

I suggest you to create a measure to filter your visual.

My Sample:

vrzhoumsft_1-1686541406198.png

Filter data on First Order Date = 
VAR _FIRSTORDER = CALCULATE(MIN('Table'[order_date]),ALLEXCEPT('Table','Table'[profile_id]))
RETURN
if(MAX('Table'[order_date]) = _FIRSTORDER,1,0)

Add this measure into visual level filter and set it to show items when value = 1.

vrzhoumsft_0-1686541384745.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Hi, yes sure this is an example of the starting table from which I need to extract the info explained above:

EnricoGiordano_0-1686996114346.png

 

My need is actually to create a new table in Power BI from that starting one, which only shows for each profile_id (customer) the first service date and the related info to this specific order (price_gross, quantity and product ordered).

The solution provided is partially correct for me, but I would like to know if it's possibile to create a new table for this analysis too, starting from the initially order table.

Thank you

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Hi, here again the sample data that covers my issue.

In my power bi dataset i have a table that contains all the orders done by each customers, based on the order date. Each row represents a single order transaction made by a specific customer, with information about the product and the sale order in €.

order_datecustomer_idquantityrevenue €product
16/05/20231512 €A
12/05/20232620 €B
18/05/20231310 €A
20/05/20232412 €C
21/05/202321018 €C
03/05/20231222€B

 

My issue is to extract and create from this table above a new table, showing only the rows of the first order made by each customer, as following:

 

first_order_datecustomer_idfirst_quantityfirst_revenue €first_product
03/05/20231222 €B
12/05/20232620 €B

 

Is it clear now?

 

Thenk you very much,

 

Enrico

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTTNzDVNzIwMlbSUTIEYlMQbaTwqGkNkOGoFKsDVGOEpMYIiM1AtAFUjRNEjQWaOWDaAMUcIwM0c0yQ7XKGqDFEU2NoACIsUBQZGKNZBlJoZAR3TywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [order_date = _t, customer_id = _t, quantity = _t, #"revenue €" = _t, product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"order_date", type date}},"es"),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"customer_id"}, {{"Rows", each _, type table [order_date=nullable date, customer_id=nullable text, quantity=nullable text, #"revenue €"=nullable text, product=nullable text]}}),
    #"Replaced Value" = Table.ReplaceValue(#"Grouped Rows",each [Rows],each Table.FirstN(Table.Sort([Rows],{{"order_date", Order.Ascending}}),1),Replacer.ReplaceValue,{"Rows"}),
    #"Expanded Rows" = Table.ExpandTableColumn(#"Replaced Value", "Rows", {"order_date", "quantity", "revenue €", "product"}, {"order_date", "quantity", "revenue €", "product"})
in
    #"Expanded Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors