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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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