Forum Discussion

JorgeMartinez92's avatar
JorgeMartinez92
Frequent Visitor
3 years ago
Solved

How can I categorize within a table or Pivot Table?

Hi all,    I am bulding the template for a food even budget. I have one table with the list of ingredients and 4 more tables with the names of the dishes, including which and how many ingredients e...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi JorgeMartinez92 

    You can create three blank queries in power query, then put the following codes to Advanced Editor in power query.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZHNbsMgEIRfJeKMLGxMDEfLl0pNJFftzcphm6KIygY1xoe+fVlI/JPmYGTt7Dc7sF1H6m9HKMmpVCpjDH/D93ohJ9qRRn+6vodQ4BKl/SK1ZtDWOxsqolDhLBbtww3gNSpKPTM0SBWPw+rLBOfE5VTNaVa+DVzBeRhDpYpiuWgvcDUWdi3YyOeC/efbHjxYF3mBYrXxtjiaU8lu6JoMqdMzifIWbMXWZ21iblnd73uIwtukR7erh5At8ZwKwRPPMrE4pMZ36OErte3vITZtR7Be/0wm7aSk7EnUxg3GoklFlZhN8rXJr7N6RIeCcs4yJR7n4CrmFcn5OiEfjt0s7vQH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ingrediente = _t, Precio = _t, #"Cantidad Comprada" = _t, #"Unidad de medida" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ingrediente", type text}, {"Precio", type number}, {"Cantidad Comprada", type number}, {"Unidad de medida", type text}})
    in
        #"Changed Type"
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcszKV9JRMtAzMAZSAakFmYkpiUqxOtFKzqlJ+Tk5iWBJQyM0Scf00sTkxJJUoLChAZpcAFAbyExTPQs0meDEHIhd6Mb5JuaVpBaWZsLtw5CvzM9LLYZImiJLxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ingrediente = _t, Usado = _t, Arepa = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ingrediente", type text}, {"Usado", type number}, {"Arepa", type text}})
    in
        #"Changed Type"
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY/BCsJADER/RXIupbUr6lF6FhS9LT1EDbKy3ajdPfj3bhsEI54C8zLDjLWwTzTw7IAeLwwFVGWzzOdI9/SCrrCw8xgx8JBFDTY3+Te1kls6sfcoUWsd5XoKkcPEavPH5oSZhWb4RI44VmjKuS5xJhdpMmnQcu+CFKxWiuSpIv8kXdNYWo/ZYoj0SO4z6It2bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ingrediente = _t, Usado = _t, Arepa = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ingrediente", type text}, {"Usado", type number}, {"Arepa", type text}}),
        #"Appended Query" = Table.Combine({#"Changed Type", Query2}),
        #"Merged Queries" = Table.NestedJoin(#"Appended Query", {"Ingrediente"}, Query1, {"Ingrediente"}, "Query1", JoinKind.LeftOuter),
        #"Expanded Query1" = Table.ExpandTableColumn(#"Merged Queries", "Query1", {"Precio"}, {"Precio"}),
        #"Added Custom" = Table.AddColumn(#"Expanded Query1", "Custom", each [Usado]*[Precio]),
        #"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Custom", "Costo"}}),
        #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Precio"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Arepa", "Ingrediente", "Usado", "Costo"}),
        #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Arepa", Order.Ascending}, {"Ingrediente", Order.Ascending}})
    in
        #"Sorted Rows"

     

    Best Regards!

    Yolo Zhu

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