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

Totales en matriz no correctos

Hola a todos

Actualmente estoy trabajando con el siguiente conjunto de datos:

FechaFin del clienteCanalDistribuidorRegiónProductoUnidadesPrecioIngresos
01/03/2020AMayoristaA LtdUkP001102.525
01/03/2020BComercioA LtdUkP001203.162
01/03/2020CDomésticaA LtdUkP002000
01/03/2020DMayoristaB LtdReyP002401.872
01/03/2020EComercioB LtdReyP002000
01/03/2020FDomésticaB LtdReyP002601.696
01/03/2020GComercialB LtdReyP003502.7135
01/03/2020HComercioC LtdFranciaP00341.546.16
01/02/2020AMayoristaA LtdUkP00182.4519.6
01/02/2020BComercioA LtdUkP001000
01/02/2020CDomésticaA LtdUkP002153.146.5
01/02/2020DMayoristaB LtdReyP002101.9519.5
01/02/2020EComercioB LtdReyP0025210
01/02/2020FDomésticaB LtdReyP002000
01/02/2020GComercialB LtdReyP003122.9535.4
01/02/2020HComercioC LtdFranciaP003101.5415.4
01/01/2020AMayoristaA LtdUkP001202.652
01/01/2020BComercioA LtdUkP00130390
01/01/2020CDomésticaA LtdUkP00223.46.8
01/01/2020DMayoristaB LtdReyP00225250
01/01/2020EComercioB LtdReyP002161.524
01/01/2020FDomésticaB LtdReyP00251.829.1
01/01/2020GComercialB LtdReyP003000
01/01/2020HComercioC LtdFranciaP003221.124.2

Estoy tratando de calcular la variación de precio por "Canal" de un mes al siguiente (01/03/2020 vs 01/02/2020). En la siguiente tabla, puedes ver el resultado que estoy obteniendo para [Price Var]:

price variance.png

La medida dax es la siguiente:

Price Var = 
VAR Intervals = MonthsPrior[MonthsPrior Value]
VAR PricePriorPeriod =
CALCULATE(
    [Average Price],
    DATEADD( Data[Date], (Intervals *-1), MONTH)
)
RETURN
IF(
    ISFILTERED( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    SUMX(
        Data,
        (Data[Price] - PricePriorPeriod) * Data[Units]
    )
)

Los totales para cada canal individual (totales de línea) son correctos... sin embargo, el total general en la parte inferior es incorrecto. El total general debe ser una suma del total de cada canal. I.e:

-12,5 + -90 + 27,52 + -11,61 a -86,59

El total que estoy buscando en la línea total es de -86.59

Medidas adicionales de referencia:

Precio medio

Average Price = 
DIVIDE( 
    SUM(Data[Revenue]), 
    SUM(Data[Units] )
)

Precio Período anterior

Price Prior Period = 
VAR Intervals = MonthsPrior[MonthsPrior Value]
RETURN
CALCULATE(
    [Average Price],
    DATEADD( Data[Date], (Intervals *-1), MONTH)
)

Cualquier ayuda sería muy apreciada!
Gracias
Aaron

10 REPLIES 10
Greg_Deckler
Super User
Super User

@aaron92 Esto parece un problema de totales de medida. Muy común. Vea mi post al respecto aquí: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Además, esta Medida Rápida, Medir Totales, La Palabra Final debe obtener lo que necesita:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


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

Hola @Greg_Deckler ,


Gracias por responder tan rápido!

He actualizado mi medida a esto:

Price Var = 
IF(
    HASONEFILTER( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    SUMX(
        Data,
        (Data[Price] - [Price Prior Period]) * Data[Units]
    )
)

Sin embargo, todavía no estoy obteniendo el resultado esperado. Mi resultado se convierte en 396.16 en lugar de -86.59.

Creo que esto probablemente tiene algo que ver con el hecho de que estoy tratando de restar el precio del período actual (esto es definido por el usuario en un filtro de fecha en la página) por el precio en el período anterior al período seleccionado.

Si echa un vistazo a la captura de pantalla de abajo, he definido el período como 01/03/2020 y el parámetro "MonthsPrior" se establece en 1, por lo tanto, las medidas (Mes Anterior) están mostrando las cifras para 01/02/2020. Los resultados reales línea por línea para Price Var son correctos, ¡pero no el total! 😞

¿Alguna idea?

price var.png

Aaron

@aaron92

Debe utilizar SUMMARIZE o GROUPBY en función de cómo está agrupando las cosas en el objeto visual:

Price Var = 
IF(
    HASONEFILTER( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    SUMX(
        Data, //this generally needs to be a SUMMARIZE or GROUPBY of the table based upon how data is grouped/summarized in the table/matrix
        (Data[Price] - [Price Prior Period]) * Data[Units]
    )
)

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

Hola @Greg_Deckler

Intenté lo siguiente, pero aparece un error:


"La función CALCULATE no se puede utilizar en un argumento de expresión para la función GROUPBY()."

Price Var = 
IF(
    HASONEFILTER( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    GROUPBY(
        Data,
        Data[Channel],
        "Price Variance", 
        SUMX(
            CURRENTGROUP(),
            ( Data[Price] - [Price Prior Period] ) * Data[Units]
        )
    )
)

¿Es esto porque estoy tratando de usar la medida [Período anterior de precio] que utiliza CALCULATE?

Price Prior Period = 
VAR Intervals = MonthsPrior[MonthsPrior Value]
RETURN
CALCULATE(
    [Average Price],
    DATEADD( Data[Date], (Intervals *-1), MONTH)
)

@aaron92 Sin embargo, otra razón por la que no me gustan las funciones CALCULATE, o T"I".

https://community.powerbi.com/t5/Community-Blog/CALCUHATE-Why-I-Don-t-Use-DAX-s-CALCULATE-Function/b...

https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000


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

@Greg_Deckler

¿Algún consejo sobre cómo actualizaría mi medida para que funcione? Dado el conjunto de datos anterior, etc.?

@aaron92 Bueno, tal vez intente RESUMIR en lugar de GROUPBY, pero de lo contrario tendría que simularlo y deshacerse de las funciones T"I" y CALCULATE usando algo como AVERAGEX y lo que FILTER sea necesario para deshacerse de DATEADD (como EOMONTH, etc.) Me tomaría un tiempo para relajarse.


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

@aaron92 OK, lo tengo descargado, voy a tratar de revisar hoy y ver si puedo conseguir que se desenrolle.


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

¡Eres un héroe! ¡Gracias! 😊

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.