Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
Creé una tabla dinámica en el Editor de consultas usando la columna dinámica. Tengo cuentas financieras como columnas y tengo una etiqueta de proyecto para cada fila. Lo que quiero hacer es crear dos nuevas columnas: una para Ingresos y otra para Costo de Ingresos para cada proyecto. Sé que las cuentas financieras que comienzan con "4" son cuentas de ingresos y las cuentas financieras que comienzan con "5" son cuentas de costos. ¿Hay una instrucción if en M Query que calcule los valores en función de estas condiciones?
Hola @smallfires0628, enfoque similar aquí.
Resultado (se agregaron 2 columnas a la tabla de ejemplo)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRS0lEyNDAAkmbmYCaIsICzQIQRlBWrE63k7AIWAImYmoGETeHqTVE0gdTHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project Name" = _t, #"40567-service income" = _t, #"40785 - product income" = _t, #"40037 - additional income" = _t, #"50678 - materials cost" = _t, #"54678 - service cost" = _t, #"56890 - driver fee" = _t, #"56768 - gasoline fee" = _t, #"56780 - additional fee" = _t]),
// You can delete this step if you have columns with correct types.
ChangedToNumbers = Table.TransformColumns(Source, {}, each try Number.From(_) otherwise Text.From(_)),
ColumnNames = List.Buffer(Table.ColumnNames(ChangedToNumbers)),
StepBack = ChangedToNumbers,
Ad_Revenue = Table.AddColumn(StepBack, "Revenue", each List.Sum(Record.ToList(Record.SelectFields(_, List.Select(ColumnNames, (x)=> Text.StartsWith(x, "4"))))), type number),
Ad_CostOfRevenue = Table.AddColumn(Ad_Revenue, "Cost of Revenue", each List.Sum(Record.ToList(Record.SelectFields(_, List.Select(ColumnNames, (x)=> Text.StartsWith(x, "5"))))), type number)
in
Ad_CostOfRevenue
Vea el código a continuación
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRS0lEyNDAAkmbmYCaIsICzQIQRlBWrE63k7AIWAImYmoGETeHqTVE0gdTHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project Name" = _t, #"40567-service income" = _t, #"40785 - product income" = _t, #"40037 - additional income" = _t, #"50678 - materials cost" = _t, #"54678 - service cost" = _t, #"56890 - driver fee" = _t, #"56768 - gasoline fee" = _t, #"56780 - additional fee" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"40567-service income", Int64.Type}, {"40785 - product income", Int64.Type}, {"40037 - additional income", Int64.Type}, {"50678 - materials cost", Int64.Type}, {"54678 - service cost", Int64.Type}, {"56890 - driver fee", Int64.Type}, {"56768 - gasoline fee", Int64.Type}, {"56780 - additional fee", Int64.Type}}),
ListOfColumns = List.Buffer(Table.ColumnNames(Source)),
ColumnCount = Table.ColumnCount(Source) - 1,
#"Added Custom" = Table.AddColumn(#"Changed Type", "Revenue", each List.Sum(List.Transform({0..ColumnCount}, (x)=> if Text.StartsWith(ListOfColumns{x},"4") then Record.ToList(_){x} else null))),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Cost of Revenue", each List.Sum(List.Transform({0..ColumnCount}, (x)=> if Text.StartsWith(ListOfColumns{x},"5") then List.RemoveLastN(Record.ToList(_),1){x} else null)))
in
#"Added Custom1"
Hola @smallfires0628
Posible solución para la nueva columna a continuación
= si Text.StartsWith([Cuenta], "4") entonces [TuCantidadColumna]
de lo contrario, si Text.StartsWith([Account], "5") then [YourAmountColumn]
else null
Enlace para esta función
Mi tabla se ve más o menos así:
Nombre del proyecto | 40567-Ingresos por servicios | 40785 - Ingresos por productos | 40037 - Ingresos adicionales | 50678 - Coste de los materiales | 54678 - Coste del servicio | 56890 - Tarifa de conductor | 56768 - Tarifa de gasolina | 56780 - Tarifa adicional | Nueva columna - Ingresos | Nueva columna - Costo de los ingresos |
APAGADO | 100 | 67 | 10 | 18 | 10 | 10 | 20 | 10 | ||
CD | 200 | 56 | 15 | 18 | 15 | 10 | 10 | 10 |
Si he entendido bien, la función text.startswith examinará una columna específica (digamos la columna de ingresos por servicio) y añadirá cantidades en función de si los valores que hay debajo coinciden con una condición. Lo que quiero es algo como esto: si el encabezado de la columna comienza con "4", agregue valores.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.