Forum Discussion
How to transform / unpivot columns to keep an attribute, value and date
- 2 years ago
Hello lukedaly01 , remember to adhere to the decorum of the Community Forum when asking a question.
Please provide your work-in-progress Power BI Desktop file (with sensitive information removed) that covers your issue or question completely in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523/highlight/true#M607150
This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied. - 2 years ago
lukedaly01 Use the code below to resolve the problem :
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ChangedTypewithLocale = Table.TransformColumnTypes(Source, {{"Task1 DateStamp", type date}, {"Task 2 DateStamp", type date}, {"Task 3 DateStamp", type date}}, "en-GB"),
UnpivotColumns = Table.UnpivotOtherColumns(ChangedTypewithLocale, {"Name", "Reports To"}, "Attributes", "Value"),
Step1 = Table.AddColumn(
UnpivotColumns,
"Values",
each if Value.Is([Value], type date) then null
else [Value], type text
),
Step2 = Table.AddColumn(
Step1,
"Date",
each if Value.Is([Value], type text) then null
else [Value],type date
),
SplitAttr = Table.SplitColumn(Step2, "Attributes", Splitter.SplitTextByDelimiter("D", QuoteStyle.Csv),{"Attribute","Att.1"}),
RemoveColumn = Table.RemoveColumns(SplitAttr, {"Value","Att.1"}),
FilledDown = Table.FillDown(RemoveColumn,{"Values"}),
FilteredRows = Table.SelectRows(FilledDown, each ([Date] <> null)),
TypeChange = Table.TransformColumnTypes(FilteredRows, {{"Name", type text}, {"Reports To", type text}})
in
TypeChange
Please set your own locale for date.
Hope this help!!
If this solved your problem, please mark it as a solution!!
Hello lukedaly01 , you don't need to start a new topic, rather share a link to your Source File and a Work in Progress PBIX.
Link to source file: https://www.dropbox.com/scl/fi/ywkhhd5l2hjyy6gzxv6nc/Source.xlsx?rlkey=pr64przmch386zpmcfaq8lvpd&st=oohhmnrh&dl=0
Link to pbix: https://www.dropbox.com/scl/fi/erg6x2h4ucz0t8phic1fo/SamplePBi.pbix?rlkey=tk7lnlpuwqd76rjkcuovn58iz&st=d4g38sml&dl=0