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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
nanoshi
New Member

Incremental Number by Group using DAX

Hi,

I'm trying to add an incremental index calculated by a group like that:

 

KeyRow_Id
123prod1_20161
123prod1_20162
123prod1_20163
456prod2_20171
456prod2_20172
456prod2_20173

 

 I found this function but doesn't work (the output is 1 for all rows):

 

=RANKX(FILTER(Table;EARLIER(Table[Key])=Table[Key]);Table[Key])

 

Thanks for the help

1 ACCEPTED SOLUTION
ricardocamargos
Continued Contributor
Continued Contributor

Hi @nanoshi,

 

You can do that using M Language,

 

Just click on Edit Queries and Advanced Editor and type this code replacing the table name/source

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyjg8I8ndRitXBxzExNSPIiQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Key = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", type text}}),
#"Group" = Table.Group(#"Changed Type", {"Key"}, {{"Rows", each Table.AddIndexColumn(_,"Index", 1), type table}}),
#"Expanded" = Table.ExpandTableColumn(#"Group", "Rows", {"Key", "Index"}, {"Rows.Key", "Rows.Index"}),
#"Removed Columns" = Table.RemoveColumns(Expanded,{"Rows.Key"})
in
#"Removed Columns"

View solution in original post

1 REPLY 1
ricardocamargos
Continued Contributor
Continued Contributor

Hi @nanoshi,

 

You can do that using M Language,

 

Just click on Edit Queries and Advanced Editor and type this code replacing the table name/source

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyjg8I8ndRitXBxzExNSPIiQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Key = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", type text}}),
#"Group" = Table.Group(#"Changed Type", {"Key"}, {{"Rows", each Table.AddIndexColumn(_,"Index", 1), type table}}),
#"Expanded" = Table.ExpandTableColumn(#"Group", "Rows", {"Key", "Index"}, {"Rows.Key", "Rows.Index"}),
#"Removed Columns" = Table.RemoveColumns(Expanded,{"Rows.Key"})
in
#"Removed Columns"

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.