We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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
Solved! Go to Solution.
Hi @Anonymous ,
Suppose the dataset loaded into Power BI is like below.
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
)
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"
Best regards,
Yuliana Gu
Hi @Anonymous ,
Suppose the dataset loaded into Power BI is like below.
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
)
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"
Best regards,
Yuliana Gu
Hi Gu,
Thank you so much for help!
Jenny
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 57 | |
| 38 | |
| 33 | |
| 19 | |
| 16 |
| User | Count |
|---|---|
| 68 | |
| 66 | |
| 41 | |
| 34 | |
| 25 |