Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I need to transpose or unpivot text values into separate columns based on relative date. My data looks like this:
Unique ID | Date | Comment |
1 | 7/1/2019 | aaaaa |
1 | 8/1/2019 | bbbbb |
1 | 9/1/2019 | ccccc |
2 | 7/1/2019 | ddddd |
2 | 8/1/2019 | eeeee |
2 | 9/1/2019 | fffff |
3 | 7/1/2019 | ggggg |
3 | 8/1/2019 | hhhhh |
3 | 9/1/2019 | iiiii |
I need to create separate columns that return the most recent, 2nd most recent, third most recent values in the Comment column based on the Date field per Unique ID. My end result would look something like this:
Unique ID | Most Recent Comment | 2nd Most Recent Comment | Third Most Recent Comment |
1 | ccccc | bbbbb | aaaaa |
2 | fffff | eeeee | ddddd |
3 | iiiii | hhhhh | ggggg |
I realize that the easiest way to address this is with the Query Editor, but unique circumstances require me to use DAX and calculated columns only.
How would I go about creating these calculated columns?
Solved! Go to Solution.
Hi @TimQ
Did you try Matrix?
Hi @TimQ
Try below M code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VczLCYAwEIThXuYciBsPmlrCHnxr/w3oRNhs/tPAB1MKBAFTlJgGyd9cGDT8MDdYmUFusLEKqb/amYG7OpiBuzpZhbG/upiBu7qZgbt6GFRf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Unique ID" = _t, Date = _t, Comment = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Unique ID", Int64.Type}, {"Date", type date}, {"Comment", type text}}), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"Date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"Date", type text}}, "en-US")[Date]), "Date", "Comment") in #"Pivoted Column"
Pbix attached.
Thanks. This solution seems like it would work but due to a weird network circumstance I am unable to transform my data table in the query editor, so my solution would have to be executed as a series of DAX calculated columns in a visual.
Hi @TimQ
Did you try Matrix?
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
62 | |
62 | |
52 | |
39 | |
24 |
User | Count |
---|---|
85 | |
57 | |
45 | |
43 | |
38 |