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

How to generate unique ID for each category using a measure.

I've been trying create a unique ID using a measure based on a category to allow filtration. For example I've the following table, and I would like to create a measure that for each "location" I would had a diferent ID (1,2,3,..) 

 

Tablename: sensors

ID Instalation ID Sensor ConfigFile Location
1 1 Pressure sensorF1.txt room1
2 1 Temperature sensorF2.txt room1
3 1 Pressure sensorF3.txt house
4 1 Temperature sensorF4.txt house
5 1 Humidity sensorF5.txt room2
6 1 Temperature sensorF6.txt room2
7 1 Humidity sensorF7.txt outside
8 1 Temperature sensorF8.txt outside
1 2 Pressure sensorF1.txt room1
2 2 Temperature sensorF2.txt room1
3 2 Pressure sensorF3.txt house
4 2 Temperature sensorF4.txt house
5 2 Humidity sensorF5.txt room2
6 2 Temperature sensorF6.txt room2
7 2 Humidity sensorF7.txt outside
8 2 Temperature sensorF8.txt outside

 

The output would be:

 

ID Instalation ID Sensor ConfigFile Location UniqueID
1 1 Pressure sensorF1.txt room1 1
2 1 Temperature sensorF2.txt room1 1
3 1 Pressure sensorF3.txt house 2
4 1 Temperature sensorF4.txt house 2
5 1 Humidity sensorF5.txt room2 3
6 1 Temperature sensorF6.txt room2 3
7 1 Humidity sensorF7.txt outside 4
8 1 Temperature sensorF8.txt outside 4

 

I've tried to use the measure bellow. but, the EARLIER does not work in the measure.

 

UniqueID = RANKX(
FILTER(
sensors,
sensors[Location] = EARLIER(sensors[Location])
),
SUM(sensors[Location])
)

 

 

Do anyone has any ideia how could I do something like that?

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@amelo  you can achieve that with following two measures

 

 

 

 

_maxID = MAX(t1[Location])
_rank = RANKX(ALL(t1),[_maxID],,ASC,Dense)

 

 

 

caps.PNG

 

and if you want the ranking to be partitioned by Installion ID

 

Measure = RANKX(FILTER(ALL(t1),t1[Instalation ID]=MAX(t1[Instalation ID])),CALCULATE(MAX(t1[Location])),,ASC,Dense)

 

casw.PNG

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

@amelo  you can achieve that with following two measures

 

 

 

 

_maxID = MAX(t1[Location])
_rank = RANKX(ALL(t1),[_maxID],,ASC,Dense)

 

 

 

caps.PNG

 

and if you want the ranking to be partitioned by Installion ID

 

Measure = RANKX(FILTER(ALL(t1),t1[Instalation ID]=MAX(t1[Instalation ID])),CALCULATE(MAX(t1[Location])),,ASC,Dense)

 

casw.PNG

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Thank you!! Works like a charm!!! 

Well it is neet trick!

parry2k
Super User
Super User

@amelo do you want a unique id between each Installation Id? The output you showed is only for Installation ID, not showing both the IDs, the solution depends on how you want it with different installation ids.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Oh thats because I'm filtering to produce a report for instalation. So, only one instalation will be tested at each time. 

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.