Forum Discussion
How to Create a unique identifier column based on the combination of two columns?
Hi Everyone,
My requirement is to create a new identifier column based on the combination of the two existing columns.
For Example, Let us consider this to be the Sample data. We need to create this ID (First column) based on the combination of "Country & PG" column.
| ID | Country | PG | Area | Action |
| 1 | C1 | P1 | A1 | TRUE |
| 2 | C1 | P1 | A2 | FALSE |
| 1 | C1 | P2 | A1 | TRUE |
| 2 | C1 | P2 | A2 | TRUE |
| 3 | C1 | P2 | A3 | FALSE |
| 1 | C1 | P3 | A1 | TRUE |
| 1 | C2 | P1 | A1 | TRUE |
| 2 | C2 | P1 | A2 | FALSE |
We need to increment the ID, if the combination of the Country and PG is same. If one of them seems to change, then again we need to start from the index 1. Can anyone please help me in implementing this ID column. It would be really helpful If you could able to give me the solution file or M code.
Thanks in advance!!
Anonymous , First add index column in power query and then try a new column in dax
ID=
countx(filter(Table, [Country] =earlier([country]) && [PG] =earlier([PG]) && [index] <=earlier([index]) ), [index])
https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi
2 Replies
- amitchandakSuper User
Anonymous , First add index column in power query and then try a new column in dax
ID=
countx(filter(Table, [Country] =earlier([country]) && [PG] =earlier([PG]) && [index] <=earlier([index]) ), [index])
https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi
- AnonymousNot applicable