Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Nausikaa
New Member

help rearranging data

Hi

I am new to power bi and need some help from you (probably this might be a stupid question)

 

I have data that is arranged this way:

datenamebuddy
1/05/2021XY
31/05/2021AB

 

and want to transform it to:

dateName
1/05/2021X
1/05/2021Y
31/05/2021A
31/05/2021B

 

How can it be done?

 

regards,

Nausikaa

4 REPLIES 4
Nausikaa
New Member

Hi,

many thanks for your help, did not quite give me the result I was looking for because in my case there were even more columns, but in the end it set me in the right direction and could figure it out myself.

regards,

Nausikaa

 

 

Hi @Nausikaa ,

 

Could you Accept my post as the solution to make the thread closedif it makes sense to you? More people will benefit from it.

 

Hope to hear from you😀

 

Best Regards,
Eyelyn Qin

v-eqin-msft
Community Support
Community Support

Hi @Nausikaa ,

 

I have done it in two ways, hope it could help you :

 

1. In Power Query:

  • Select date column -->Transform--Unpivot Other Columns-->Remove Attribute column --> Rename Value column

In power query.PNG

  • Here is the whole M code:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3MNU3MjAyVNJRigDiSKVYnWglY2RhRyB2UoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [date = _t, name = _t, buddy = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type text}, {"name", type text}, {"buddy", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"date"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "Name"}})
in
    #"Renamed Columns"

 

2. Use DAX to create a calculated table:

Use DAX = 
var t1=DISTINCT(SELECTCOLUMNS('Table',"date",[date],"Name",[name]))
var t2=DISTINCT(SELECTCOLUMNS('Table',"date",[date],"Name",[buddy]))
return UNION(t1,t2)

 The final output is shown below:

two methods.PNG

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parry2k
Super User
Super User

@Nausikaa go to transform data and unpivot. Right-click on the date column and then choose unpivot other columns

 

parry2k_0-1624637122676.png

 

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.