Forum Discussion
Index Column Based on ID and Date
Thank you for helping me out but i get the following error with that DAX: EARLIER/EARLIEST refers to an earlier row context which doesn't exist.
In your example, the AAA ID with the 3/7/2023 date have the same index. I need them to be different.
Hi Sammyben ,
Please try sort by [ID] and [Date] first in ascending order in PowerQuery first:
Then group them by [ID] and add an Index column.
Expand columns and the output:
Advanced editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnR0VNJRMtQ31DcyMDJWitWBCRnrmxMhZKJvaIEQc3JyAhlmpG9oCRI0QhI00TdFV4cQigUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Date", type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"ID", Order.Ascending}, {"Date", Order.Ascending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"ID"}, {{"Data", each Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type)}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Date", "Index"}, {"Date", "Index"})
in
#"Expanded Data"
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum