The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hola,
Necesito sumar ventas por período para tiendas. Tengo 2 unidades negocio y cada unidad de negocio tiene una cantidad X de tiendas. Necesito obtener la suma de ventas para cada tienda en período 2021 y 2022 con una formula en DAX, ya que luego necesito dividir eso por el promedio de superficie por período para cada tienda.
ejemplo : para 2021 tienda 1 necesito ventas totales (300+200+300) divido por el promedio de superficie de esa tienda (1200+1200+1000/3), lo mismo para cada tienda de cada unidad de negocio.
Solved! Go to Solution.
Hi @J3
You can put the following code to advanced editor in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdBRCoAwCAbgu/i8B/23RT3WNcbuf42GFTFS6cEN/PgRbY2EEu2jMvN4BfqBIdTTq1db2FY/e4wq2l5tRIRmEvfQqu3NRkQo3kxrF8xa5zvMWqqXNbZBdIcfyWebJcIcoXywnw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Tienda = _t, #"Unidad de negocio " = _t, Venta = _t, #"Superficie venta" = _t, fecha = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Tienda", Int64.Type}, {"Unidad de negocio ", type text}, {"Venta", Int64.Type}, {"Superficie venta", Int64.Type}, {"fecha", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Tienda", "Unidad de negocio ", "fecha"}, {{"Sum_ve", each List.Sum([Venta]), type nullable number}, {"avg_su", each List.Average([Superficie venta]), type nullable number}, {"Data", each _, type table [Tienda=nullable number, #"Unidad de negocio "=nullable text, Venta=nullable number, Superficie venta=nullable number, fecha=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [Sum_ve]/[avg_su]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type number}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Changed Type1", "Data", {"Venta", "Superficie venta"}, {"Venta", "Superficie venta"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Data",{"Tienda", "Unidad de negocio ", "fecha", "Venta", "Superficie venta", "Sum_ve", "avg_su", "Custom"}),
#"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "Sum_ve/avg_su"}})
in
#"Renamed Columns"
Output
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.
Hi @J3
You can put the following code to advanced editor in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdBRCoAwCAbgu/i8B/23RT3WNcbuf42GFTFS6cEN/PgRbY2EEu2jMvN4BfqBIdTTq1db2FY/e4wq2l5tRIRmEvfQqu3NRkQo3kxrF8xa5zvMWqqXNbZBdIcfyWebJcIcoXywnw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Tienda = _t, #"Unidad de negocio " = _t, Venta = _t, #"Superficie venta" = _t, fecha = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Tienda", Int64.Type}, {"Unidad de negocio ", type text}, {"Venta", Int64.Type}, {"Superficie venta", Int64.Type}, {"fecha", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Tienda", "Unidad de negocio ", "fecha"}, {{"Sum_ve", each List.Sum([Venta]), type nullable number}, {"avg_su", each List.Average([Superficie venta]), type nullable number}, {"Data", each _, type table [Tienda=nullable number, #"Unidad de negocio "=nullable text, Venta=nullable number, Superficie venta=nullable number, fecha=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [Sum_ve]/[avg_su]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type number}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Changed Type1", "Data", {"Venta", "Superficie venta"}, {"Venta", "Superficie venta"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Data",{"Tienda", "Unidad de negocio ", "fecha", "Venta", "Superficie venta", "Sum_ve", "avg_su", "Custom"}),
#"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "Sum_ve/avg_su"}})
in
#"Renamed Columns"
Output
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.