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

Help

Hi,
This is a measure"Row_number() Over (partition By product category Order by [OrderDate])" which I used in Tableau, how can I translate it in powerBI? Thanks

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

Suppose the dataset loaded into Power BI is like below.

1.png

 

Here are two options to add such a row numer, via DAX or Power Query.

 

Option1: Adding a calculated column via DAX.

row_number =
RANKX (
    FILTER (
        Query1,
        Query1[Product category] = EARLIER ( Query1[Product category] )
    ),
    [OrderDate],
    ,
    ASC
)

2.png

 

Option2: Adding a nested index in Query Editor mode.

In Query Editor mode, sort the [OrderDate] Ascending.

Please refer to bleow code.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data.xlsx"), null, true),
    Query1_Sheet = Source{[Item="Query1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Query1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"OrderDate", type date}, {"Product category", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"OrderDate", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Product category"}, {{"index", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded index" = Table.ExpandTableColumn(#"Grouped Rows", "index", {"OrderDate", "Index"}, {"index.OrderDate", "index.Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded index",{{"index.OrderDate", "OrderDate"}, {"index.Index", "Index"}})
in
    #"Renamed Columns"

3.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

Suppose the dataset loaded into Power BI is like below.

1.png

 

Here are two options to add such a row numer, via DAX or Power Query.

 

Option1: Adding a calculated column via DAX.

row_number =
RANKX (
    FILTER (
        Query1,
        Query1[Product category] = EARLIER ( Query1[Product category] )
    ),
    [OrderDate],
    ,
    ASC
)

2.png

 

Option2: Adding a nested index in Query Editor mode.

In Query Editor mode, sort the [OrderDate] Ascending.

Please refer to bleow code.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data.xlsx"), null, true),
    Query1_Sheet = Source{[Item="Query1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Query1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"OrderDate", type date}, {"Product category", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"OrderDate", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Product category"}, {{"index", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded index" = Table.ExpandTableColumn(#"Grouped Rows", "index", {"OrderDate", "Index"}, {"index.OrderDate", "index.Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded index",{{"index.OrderDate", "OrderDate"}, {"index.Index", "Index"}})
in
    #"Renamed Columns"

3.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Gu,

          Thank you so much for help!

Jenny

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 Fabric 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.