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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
JorgeMartinez92
Frequent Visitor

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 each one requires:

I have created 1 to 1 relationships between the ingredients table and each dishes table. 

 

1 to 1 relationships example1 to 1 relationships example

 

I would like to create a table or a Pivot Table which has all the dishes and each ingredient necessary for their preparation. The best approach I can come up with (which I have not tried) is to merge all the dishes tables and from there create the calculated columns / measures I need. But I would like to know if there is another way of doing this. 

 

I do not know how this arrange would be called, so I have not had much luck researching on the internet. Can somebody please shed light upon this?

 

I am looking for something like this, where I could filter and see how many dishes share the same ingredient and the total cost, for example:

 

ResultResult

 

Base table with the ingredients:

 

IngredientePrecioCantidad CompradaUnidad de medida
Ajo1,899.00

1.00

Kg
Cebolla380.006.00Kg
Pimenton529.002.00Kg
Tomate599.001.00Kg
Cebollin200.001.00Kg
Aguacate1,999.0012.00Kg
Caraotas700.00

4.00

Kg
Harina Pan1,150.0012.00Kg
Platanos750.007.00Kg
Carne3,800.002.00Kg
Pollo1,549.007.00Kg
Aceite879.001.00L
Queso Amarillo3,553.000.50Kg
Queso Salado3,600.000.50Kg
Mantequilla4,000.002.00Kg
Comino7,950.000.10Kg
Mayonesa2,330.950.50Kg
Agua200.008.00L
Sal400.001.00Kg

 

Pepiada dish:

 

IngredienteUsadoArepa
Ajo0.03Pepiada
Cebolla0.12Pepiada
Aguacate10.00Pepiada
Pollo5.80Pepiada
Sal0.02Pepiada
Mantequilla0.10Pepiada
Mayonesa0.50Pepiada

 

Tepuy dish:

 

IngredienteUsadoArepa
Queso Salado0.37Tepuy
Platanos7.00Tepuy
Ajo0.41Tepuy
Cebolla0.39Tepuy
Pimenton0.14Tepuy
Cebollin0.45Tepuy
Caraotas3.20Tepuy
Aceite0.20Tepuy
Comino0.08Tepuy
Sal0.02Tepuy
Agua1.00Tepuy
Mantequilla0.10Tepuy
1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

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"

 

vxinruzhumsft_0-1691637019276.png

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.

 

View solution in original post

2 REPLIES 2
JorgeMartinez92
Frequent Visitor

Thank you, it worked!

v-xinruzhu-msft
Community Support
Community Support

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"

 

vxinruzhumsft_0-1691637019276.png

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.

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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