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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
justlogmein
Helper III
Helper III

What is the 'proper' way to arrange my data and what is the code required?

I have a table where nearly all the headers are dates. This data source changes dynamically and the dates will also change, so if my queries (such as Change Type) reference the current headers I will get errors when the data source changes.  However, the rows in the Person column may also change, so I can't use them as headers either. So I am looking for a robust way to arrange the table so I don't get errors (I'm thinking Person, Date and Value as the column names?) I'd like to know if there are any better ways of doing this, and what the code for doing so would be.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VZQ9blwxDITvsrWL1R8llUnpIMgBDBeLZIsAuw4QV769lx8zfEhDvCeJ5AxnpJeX05f7x+nptM1DfYS1PZwfofhXHf519v82H2GUR7CmM5U81lSle5XpofqJkaWs+6/XG1X5zdcKPZZnNJ0jA0CTXa9s3qc7ijYSqf8ui43XpwefX5e7J1T1qV54g6IJVBCCRk3gw5RHN05371G878oyMQIHaX7YtrBEzyMDpFtVOny9yvLK00OZqtKKpsGu+eHZYfR8uV/f1RIYfWTfoubdd+tWbvQ1NbKhr5Z6zK3miIwey6tMnYgx7a5Sa2TuWVQBDvNGaNl3a5LQ2jPWnNHX37fbh4SPjSmr0GMWTW3mrDakp4wI5o1pvG8vKtCXCjAcJMNXTA03AQgPIbInlC7FsO4WFQptLZMdMJmqQefbx+0q5MDqLVGalA/5h8zGxI57NH0Np4YqRV6Zh11D+qW5zdQBVLulDZlWldb/DO/AsfAW1GaaIDb0jxGEnv9c3t6u0sZkp3BrT5ZbLEOurIkB+UWVcHrRuSGDMCVItbzTgF1ppLjxJn2w9+CLO1ilRni8CnHc+xazdkLfrzfNBB0ZUUuDcpW4/iNlAQ5Y8zmaSwxHWi4gNZmq56MxBf+YP/3NUsqqAKWWRoU/5mUwAaAGCmfz4/3n5e9/hivpitqFB527As8mUI5raunreB6Oh3toAKQx3cOcvAe8+XgJ3On6eFM5xtoSvXjuLU3FE3F6ff0E", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, #"19/03/2021" = _t, #"20/03/2021" = _t, #"21/03/2021" = _t, #"22/03/2021" = _t, #"23/03/2021" = _t, #"24/03/2021" = _t, #"25/03/2021" = _t, #"26/03/2021" = _t, #"27/03/2021" = _t, #"28/03/2021" = _t, #"29/03/2021" = _t, #"30/03/2021" = _t, #"31/03/2021" = _t, #"1/04/2021" = _t, #"2/04/2021" = _t, #"3/04/2021" = _t, #"4/04/2021" = _t, #"5/04/2021" = _t, #"6/04/2021" = _t, #"7/04/2021" = _t, #"8/04/2021" = _t, #"9/04/2021" = _t, #"10/04/2021" = _t, #"11/04/2021" = _t, #"12/04/2021" = _t, #"13/04/2021" = _t, #"14/04/2021" = _t, #"15/04/2021" = _t, #"16/04/2021" = _t, #"17/04/2021" = _t, #"18/04/2021" = _t, #"19/04/2021" = _t, #"20/04/2021" = _t, #"21/04/2021" = _t, #"22/04/2021" = _t, #"23/04/2021" = _t, #"24/04/2021" = _t, #"25/04/2021" = _t, #"26/04/2021" = _t, #"27/04/2021" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Person", type text}, {"19/03/2021", Int64.Type}, {"20/03/2021", Int64.Type}, {"21/03/2021", Int64.Type}, {"22/03/2021", Int64.Type}, {"23/03/2021", Int64.Type}, {"24/03/2021", Int64.Type}, {"25/03/2021", Int64.Type}, {"26/03/2021", Int64.Type}, {"27/03/2021", Int64.Type}, {"28/03/2021", Int64.Type}, {"29/03/2021", Int64.Type}, {"30/03/2021", Int64.Type}, {"31/03/2021", Int64.Type}, {"1/04/2021", Int64.Type}, {"2/04/2021", Int64.Type}, {"3/04/2021", Int64.Type}, {"4/04/2021", Int64.Type}, {"5/04/2021", Int64.Type}, {"6/04/2021", Int64.Type}, {"7/04/2021", Int64.Type}, {"8/04/2021", Int64.Type}, {"9/04/2021", Int64.Type}, {"10/04/2021", Int64.Type}, {"11/04/2021", Int64.Type}, {"12/04/2021", Int64.Type}, {"13/04/2021", Int64.Type}, {"14/04/2021", Int64.Type}, {"15/04/2021", Int64.Type}, {"16/04/2021", Int64.Type}, {"17/04/2021", Int64.Type}, {"18/04/2021", Int64.Type}, {"19/04/2021", Int64.Type}, {"20/04/2021", Int64.Type}, {"21/04/2021", Int64.Type}, {"22/04/2021", Int64.Type}, {"23/04/2021", Int64.Type}, {"24/04/2021", Int64.Type}, {"25/04/2021", Int64.Type}, {"26/04/2021", Int64.Type}, {"27/04/2021", Int64.Type}})
in
    #"Changed Type"

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@justlogmein 

Please check this version. This way it will be very useful for your analysis

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VZQ9blwxDITvsrWL1R8llUnpIMgBDBeLZIsAuw4QV769lx8zfEhDvCeJ5AxnpJeX05f7x+nptM1DfYS1PZwfofhXHf519v82H2GUR7CmM5U81lSle5XpofqJkaWs+6/XG1X5zdcKPZZnNJ0jA0CTXa9s3qc7ijYSqf8ui43XpwefX5e7J1T1qV54g6IJVBCCRk3gw5RHN05371G878oyMQIHaX7YtrBEzyMDpFtVOny9yvLK00OZqtKKpsGu+eHZYfR8uV/f1RIYfWTfoubdd+tWbvQ1NbKhr5Z6zK3miIwey6tMnYgx7a5Sa2TuWVQBDvNGaNl3a5LQ2jPWnNHX37fbh4SPjSmr0GMWTW3mrDakp4wI5o1pvG8vKtCXCjAcJMNXTA03AQgPIbInlC7FsO4WFQptLZMdMJmqQefbx+0q5MDqLVGalA/5h8zGxI57NH0Np4YqRV6Zh11D+qW5zdQBVLulDZlWldb/DO/AsfAW1GaaIDb0jxGEnv9c3t6u0sZkp3BrT5ZbLEOurIkB+UWVcHrRuSGDMCVItbzTgF1ppLjxJn2w9+CLO1ilRni8CnHc+xazdkLfrzfNBB0ZUUuDcpW4/iNlAQ5Y8zmaSwxHWi4gNZmq56MxBf+YP/3NUsqqAKWWRoU/5mUwAaAGCmfz4/3n5e9/hivpitqFB527As8mUI5raunreB6Oh3toAKQx3cOcvAe8+XgJ3On6eFM5xtoSvXjuLU3FE3F6ff0E", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, #"19/03/2021" = _t, #"20/03/2021" = _t, #"21/03/2021" = _t, #"22/03/2021" = _t, #"23/03/2021" = _t, #"24/03/2021" = _t, #"25/03/2021" = _t, #"26/03/2021" = _t, #"27/03/2021" = _t, #"28/03/2021" = _t, #"29/03/2021" = _t, #"30/03/2021" = _t, #"31/03/2021" = _t, #"1/04/2021" = _t, #"2/04/2021" = _t, #"3/04/2021" = _t, #"4/04/2021" = _t, #"5/04/2021" = _t, #"6/04/2021" = _t, #"7/04/2021" = _t, #"8/04/2021" = _t, #"9/04/2021" = _t, #"10/04/2021" = _t, #"11/04/2021" = _t, #"12/04/2021" = _t, #"13/04/2021" = _t, #"14/04/2021" = _t, #"15/04/2021" = _t, #"16/04/2021" = _t, #"17/04/2021" = _t, #"18/04/2021" = _t, #"19/04/2021" = _t, #"20/04/2021" = _t, #"21/04/2021" = _t, #"22/04/2021" = _t, #"23/04/2021" = _t, #"24/04/2021" = _t, #"25/04/2021" = _t, #"26/04/2021" = _t, #"27/04/2021" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Person"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", Int64.Type}, {"Attribute", type date}},"en-gb"),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Attribute", "Date"}})
in
    #"Renamed Columns"

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

1 REPLY 1
Fowmy
Super User
Super User

@justlogmein 

Please check this version. This way it will be very useful for your analysis

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VZQ9blwxDITvsrWL1R8llUnpIMgBDBeLZIsAuw4QV769lx8zfEhDvCeJ5AxnpJeX05f7x+nptM1DfYS1PZwfofhXHf519v82H2GUR7CmM5U81lSle5XpofqJkaWs+6/XG1X5zdcKPZZnNJ0jA0CTXa9s3qc7ijYSqf8ui43XpwefX5e7J1T1qV54g6IJVBCCRk3gw5RHN05371G878oyMQIHaX7YtrBEzyMDpFtVOny9yvLK00OZqtKKpsGu+eHZYfR8uV/f1RIYfWTfoubdd+tWbvQ1NbKhr5Z6zK3miIwey6tMnYgx7a5Sa2TuWVQBDvNGaNl3a5LQ2jPWnNHX37fbh4SPjSmr0GMWTW3mrDakp4wI5o1pvG8vKtCXCjAcJMNXTA03AQgPIbInlC7FsO4WFQptLZMdMJmqQefbx+0q5MDqLVGalA/5h8zGxI57NH0Np4YqRV6Zh11D+qW5zdQBVLulDZlWldb/DO/AsfAW1GaaIDb0jxGEnv9c3t6u0sZkp3BrT5ZbLEOurIkB+UWVcHrRuSGDMCVItbzTgF1ppLjxJn2w9+CLO1ilRni8CnHc+xazdkLfrzfNBB0ZUUuDcpW4/iNlAQ5Y8zmaSwxHWi4gNZmq56MxBf+YP/3NUsqqAKWWRoU/5mUwAaAGCmfz4/3n5e9/hivpitqFB527As8mUI5raunreB6Oh3toAKQx3cOcvAe8+XgJ3On6eFM5xtoSvXjuLU3FE3F6ff0E", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, #"19/03/2021" = _t, #"20/03/2021" = _t, #"21/03/2021" = _t, #"22/03/2021" = _t, #"23/03/2021" = _t, #"24/03/2021" = _t, #"25/03/2021" = _t, #"26/03/2021" = _t, #"27/03/2021" = _t, #"28/03/2021" = _t, #"29/03/2021" = _t, #"30/03/2021" = _t, #"31/03/2021" = _t, #"1/04/2021" = _t, #"2/04/2021" = _t, #"3/04/2021" = _t, #"4/04/2021" = _t, #"5/04/2021" = _t, #"6/04/2021" = _t, #"7/04/2021" = _t, #"8/04/2021" = _t, #"9/04/2021" = _t, #"10/04/2021" = _t, #"11/04/2021" = _t, #"12/04/2021" = _t, #"13/04/2021" = _t, #"14/04/2021" = _t, #"15/04/2021" = _t, #"16/04/2021" = _t, #"17/04/2021" = _t, #"18/04/2021" = _t, #"19/04/2021" = _t, #"20/04/2021" = _t, #"21/04/2021" = _t, #"22/04/2021" = _t, #"23/04/2021" = _t, #"24/04/2021" = _t, #"25/04/2021" = _t, #"26/04/2021" = _t, #"27/04/2021" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Person"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", Int64.Type}, {"Attribute", type date}},"en-gb"),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Attribute", "Date"}})
in
    #"Renamed Columns"

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors