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
Anonymous
Not applicable

Cálculo de columnas dependiendo de la segmentación de datos

Hola
Estoy buscando una solución en Power BI, que he implementado en Excel mediante VBA.
photo.PNG

Función en la columna 'Coste' es una suma de valores de 'Tabla de costes adicionales' y la fórmula está cambiando basándose en los valores de las casillas de verificación. Los cambios en la columna 'Coste' afectan a la columna 'Margen'. En el panel de Power BI, me gustaría mostrar el gráfico con Margen y usar Slicer para agregar o quitar algún costo adicional calculado en "Tabla de costos adicionales". El problema es que cada costo adicional se calcula por mes y la fórmula de la columna 'Coste' también depende del valor del mes en la primera columna de la misma fila.


1 ACCEPTED SOLUTION

Hola @mgruszec ,

Modifico las fórmulas basadas en su tabla temporal, por favor pruebe.

Additional Cost Table = 
UNION(
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 1", "Result",'Table'[Value 1]),
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 2", "Result",'Table'[Value 2]),
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 3", "Result",'Table'[Value 3])
)
Filter Value Table = VALUES('Additional Cost Table'[Data])
Measure = 
var result = CALCULATE(
    SUM('Additional Cost Table'[Result]),
FILTER(
    'Additional Cost Table',
    'Additional Cost Table'[Data] in ALLSELECTED('Filter Value Table'[Data])
    )
)
return
IF(ISFILTERED('Filter Value Table'[Data]),result,0)

1.PNG

Para obtener más información, consulte el archivo adjunto.

Best Regards,
Xue Ding
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

5 REPLIES 5
v-xuding-msft
Community Support
Community Support

Hola @mgruszec ,

Según la descripción, creé una muestra simple.

  • En primer lugar, desplanto las tres columnas de valores en Tabla de costes adicionales. Porque es calcular para Power BI en función de columnas en lugar de filas.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMK00sqlTSUTI0MACSRmDSGEjG6kQruaUmFcGkTcHSYNIYSMbGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, value1 = _t, value2 = _t, value3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}, {"value1", Int64.Type}, {"value2", Int64.Type}, {"value3", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Month"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Value", "Data"}, {"Attribute", "Value"}})
in
    #"Renamed Columns"

1.gif

  • Cree una nueva tabla. Y usa la columna como cortadora.
Filter Value Table = VALUES('Aditional Cost Table'[Value])
  • Crear una medida
Measure = 
CALCULATE(
    SUM('Aditional Cost Table'[Data]),
FILTER(
    ALLEXCEPT('Aditional Cost Table','Aditional Cost Table'[Month]),
    'Aditional Cost Table'[Value] in ALLSELECTED('Filter Value Table'[Value])
    )
)

2.gif

Para obtener más detalles, descargue mi ejemplo a continuación.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Gracias por la respuesta rápida y la visualización. Esta solución se ve perfecta, pero tengo problema con el primer paso - tabla unpivot.
Los valores de "Tabla de costes adicionales" se calculan en Power BI basándose en otra tabla (se trata de funciones SUM con algunos filtros especificados). Intenté usar la función UNION, pero el número de filas no es constante, porque se agregarán nuevos meses.

Creo que UNION es una solución, algo así:

Table = 
UNION(
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 1", "Result",'Table'[Value 1]),
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 2", "Result",'Table'[Value 2]),
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 3", "Result",'Table'[Value 3])
)

Anonymous
Not applicable

@v-xuding-msft

En más cosas:

cuando todo en Slicer está desmarcado, entonces está sumando todos los valores (el mismo resultado como todos se comprobará). ¿Es posible mostrar 0 cuando todo está desmarcado?

Hola @mgruszec ,

Modifico las fórmulas basadas en su tabla temporal, por favor pruebe.

Additional Cost Table = 
UNION(
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 1", "Result",'Table'[Value 1]),
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 2", "Result",'Table'[Value 2]),
SELECTCOLUMNS('Table', "Month", 'Table'[Month], "Type of value", "Value 3", "Result",'Table'[Value 3])
)
Filter Value Table = VALUES('Additional Cost Table'[Data])
Measure = 
var result = CALCULATE(
    SUM('Additional Cost Table'[Result]),
FILTER(
    'Additional Cost Table',
    'Additional Cost Table'[Data] in ALLSELECTED('Filter Value Table'[Data])
    )
)
return
IF(ISFILTERED('Filter Value Table'[Data]),result,0)

1.PNG

Para obtener más información, consulte el archivo adjunto.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Tendrá que usar una medida para esto. Por favor, consulte este post sobre cómo obtener su pregunta respondida rápidamente: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

Las partes más importantes son:
1. Muestra datos como texto, utilice la herramienta de tabla en la barra de edición
2. Salida esperada a partir de datos de muestra
3. Explicación en palabras de cómo obtener de 1. a 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.