Forum Discussion
Calculated column to assign numeric code to dates
- 3 months ago
Hi all, thank you for your input but it turns out there was actually a very easy way to do this in Power Query. Steps below:
1. Use the group by function on the date column, setting the operation to "all rows", making a nested table for each date.
2. Add an index column (I used the custom starting point of 99001 and incremented at 1)
3. Expand the nested tables back out.
Each row now has a unique identifier based on its date!
Hello
Use Rankx
Date ID = RANKX( ALL('Table'[Date]), 'Table'[Date], , ASC, Dense )
If my response helped you, please consider clicking
Accept as Solution ✅ and giving it a Like 👍 – it helps others in the community too.
Thanks,
Connect with me on:
LinkedIn |
Data With Pankaj - YouTube
Thank you for your reply. In trying this I'm getting a 'Token Literal Expected' error after ASC,. I am not sure how to correct this error. A screenshot is included wtih my table names covered up for confidentiality reasons:
- MasonMA3 months agoSuper User
You are in Power Query. The solution given to you is in Power BI. so go to Data View, select the table, choose New Column and paste the DAX formula there.
Not in Transform Data / Power Query Editor.
- krdavies3 months agoHelper I
Thank you!
Follow up question: is there a way to add a prefix to these numbers? For example, if I wanted all of them to start with 99.
- MasonMA3 months agoSuper User
that would be something like
Date ID =
"99" & RANKX(ALL('Table'[Date]), 'Table'[Date], , ASC, DENSE)but once you add a text prefix, the column becomes a text data type rather than numeric.