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
gerojordan
New Member

Create Row Number for Each Group in Power BI ordered by date

Hi everyone, I have a difficulty in order to make something.

I need to: group by MASTERID, then order each row group(internally) by DateTime , create a new column in each group called ID, and create automatically an index from 1 to the last item in that group.

This is  my table

 

masteriduserdatetimestateinternaliddatetime
191753ZAICO2/1/201708:46:17PERDIDA4388432/1/2017 08:46:17
191781ZAICO2/1/201708:47:16SEGUIMIENTO4388442/1/2017 08:47:16
191952ZAICO2/1/201709:29:37INICIADA4388472/1/2017 09:29:37
191954ZAICO2/1/201709:31:31INICIADA4388482/1/2017 09:31:31
191954ZAICO2/1/201709:34:53SEGUIMIENTO4388492/1/2017 09:34:53
191977VAB2/1/201709:35:28INICIADA4388502/1/2017 09:35:28
191978ZAICO2/1/201709:38:49INICIADA4388512/1/2017 09:38:49
191979ZAICO2/1/201709:41:16INICIADA4388522/1/2017 09:41:16
191980ZAICO2/1/201709:58:42INICIADA4388532/1/2017 09:58:42
191942VAB2/1/201709:56:03SEGUIMIENTO4388542/1/2017 09:56:03
191981ZAICO2/1/201709:59:40INICIADA4388562/1/2017 09:59:40
191982ZAICO2/1/201710:05:17INICIADA4388572/1/2017 10:05:17
191882VAB2/1/201710:12:34INICIADA4388602/1/2017 10:12:34
191737VAB2/1/201710:13:13INICIADA4388612/1/2017 10:13:13
191756VAB2/1/201710:14:54INICIADA4388622/1/2017 10:14:54
191850VAB2/1/201710:16:02INICIADA4388632/1/2017 10:16:02
191872VAB2/1/201710:17:10INICIADA4388652/1/2017 10:17:10
191875VAB2/1/201710:18:30INICIADA4388662/1/2017 10:18:30
191959ZAICO2/1/201710:13:33INICIADA4388672/1/2017 10:13:33
191984YOLAN2/1/201710:23:04INICIADA4388682/1/2017 10:23:04
191985ZAICO2/1/201710:24:21INICIADA4388692/1/2017 10:24:21
191985ZAICO2/1/201710:24:23SEGUIMIENTO4388702/1/2017 10:24:23
191951VAB2/1/201710:19:34SEGUIMIENTO4388712/1/2017 10:19:34

 

Can you give me an idea or help me with a new idea?

Thanks

Wait for your answers 

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @gerojordan ,

 

Both PQ and DAX can be used, it's up to you.

Sort = RANKX(FILTER('Table','Table'[masterid]=EARLIER('Table'[masterid])),'Table'[datetime],,ASC,Dense)

Sample .pbix

 

Best Regards,
Liang
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

4 REPLIES 4
V-lianl-msft
Community Support
Community Support

Hi @gerojordan ,

 

Both PQ and DAX can be used, it's up to you.

Sort = RANKX(FILTER('Table','Table'[masterid]=EARLIER('Table'[masterid])),'Table'[datetime],,ASC,Dense)

Sample .pbix

 

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

amitchandak
Super User
Super User

@gerojordan , Not very clear. But in case you need a index column based on sort order you can add a column in Dax

 

Rank index  = RANKX(ALL(Table), Table[Datetime],,asc,dense)

 

 

Ranindex k = RANKX(ALL(Table), Table[Datetime],,asc,dense) + rank()/1000 -- in case there is some overlap and you want to avoid

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

I tried to be more clear...I rewrite all the question please check, thanks.

jairoaol
Impactful Individual
Impactful Individual

after grouping sorts in a new step by the date column and then you create an index column.

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!

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.