cancel
Showing results for 
Search instead for 
Did you mean: 
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

 

 

Eyelyn9
Community Support
Community Support

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

Eyelyn9
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.






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
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors