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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Total en ejecución basado en la categoría

Con la siguiente tabla 'Datos', Me gustaría escribir una medida que calcula el total de ejecución basado en "Producto".

Tabla de entrada: 'Datos'

ProductoTipoCosto
AMaterial200
APersonal150
AMáquina80
BMaterial300
BPersonal140
BMáquina120
CMaterial240
CPersonal200
CMáquina10

Salida ideal:

ProductoCostoCost Running Total
B560560
C4501010
A4301440

Mi solución actual es usar la siguiente fórmula DAX para crear una tabla calculada,'Datos por producto'; conectar las dos tablas,'Datos'y 'Datos por producto' con una tabla de relaciones, 'Producto' que contiene sólo "A", "B", "C" ,y finalmente utilizar la siguiente medida, " Cost RunningTotal" para calcular el costo total de ejecución basado en la columna [Coste] en orden descendente.

Data by Product = 
SUMMARIZE(
    'Data',
    Data[Product],
    "Cost", SUM(Data[Cost])
)

Cost Running Total = 
    CALCULATE(
        SUM(Data[Cost]),
        FILTER(
            ALLSELECTED('Product'[Product]),
            Data[Cost] >= MIN('Data by Product'[Cost])
        )
    )

¿Alguna forma menos engorrosa de realizar el mismo cálculo?

2 ACCEPTED SOLUTIONS
DataInsights
Super User
Super User

@CKWong, pruebe esto:

1. Cree una tabla ProductMaster. Ordene la columna Producto por la columna Index (controla la ordenación en el objeto visual de la tabla).

DataInsights_0-1600280855916.png

2. Une ProductMaster a la tabla de datos.

DataInsights_1-1600280893819.png

3. Crear medidas.

Total Cost = SUM ( ProductCost[Cost] )

Running Total = 
VAR vSelProd =
    SELECTEDVALUE ( ProductMaster[Index] )
VAR vResult =
    CALCULATE (
        [Total Cost],
        ProductMaster[Index] <= vSelProd,
        ALL ( ProductMaster[Product] )
    )
RETURN
    vResult

4. Cree un objeto visual de tabla, utilizando ProductMaster[Product] y las medidas.

5. Resultado:

DataInsights_2-1600280916750.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

FrankAT
Community Champion
Community Champion

Hola @CKWong

qué pasa con la siguiente solución:

16-09-_2020_22-32-55.png

Sum of Cost = SUM(Data[Cost])

Running Total = 
CALCULATE(
    [Sum of Cost],
    FILTER(
        ALL(Data),
        MIN(Data[Product]) <= Data[Product]
    )
)

Con saludos amables desde la ciudad donde la leyenda del 'Pied Piper de Hamelin' está en casa
FrankAT (Orgulloso de ser un Datanaut)

View solution in original post

2 REPLIES 2
FrankAT
Community Champion
Community Champion

Hola @CKWong

qué pasa con la siguiente solución:

16-09-_2020_22-32-55.png

Sum of Cost = SUM(Data[Cost])

Running Total = 
CALCULATE(
    [Sum of Cost],
    FILTER(
        ALL(Data),
        MIN(Data[Product]) <= Data[Product]
    )
)

Con saludos amables desde la ciudad donde la leyenda del 'Pied Piper de Hamelin' está en casa
FrankAT (Orgulloso de ser un Datanaut)

DataInsights
Super User
Super User

@CKWong, pruebe esto:

1. Cree una tabla ProductMaster. Ordene la columna Producto por la columna Index (controla la ordenación en el objeto visual de la tabla).

DataInsights_0-1600280855916.png

2. Une ProductMaster a la tabla de datos.

DataInsights_1-1600280893819.png

3. Crear medidas.

Total Cost = SUM ( ProductCost[Cost] )

Running Total = 
VAR vSelProd =
    SELECTEDVALUE ( ProductMaster[Index] )
VAR vResult =
    CALCULATE (
        [Total Cost],
        ProductMaster[Index] <= vSelProd,
        ALL ( ProductMaster[Product] )
    )
RETURN
    vResult

4. Cree un objeto visual de tabla, utilizando ProductMaster[Product] y las medidas.

5. Resultado:

DataInsights_2-1600280916750.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors