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
Syndicate_Admin
Administrator
Administrator

Total de medidas incorrecto

Hola
Quiero una medida para calcular la diferencia entre la fecha seleccionada y las ventas de la última fecha de venta. Y el promedio de esta diferencia como un gran total. Pero mi medida no es correcta. Cuando se selecciona 2023-01-17, el promedio esperado es 5. Las ventas del Producto 3 en 2022-12-10 también se agregan en promedio. Pero quiero excular esta cantidad 12.

haputhanthree_0-1705534677548.png

Mesa de ventas

IdentificaciónStaffIdProductidFechaVentas
11112/10/2022100
3111/17/202360
7121/17/202360
81212/10/202210
91312/10/202212


Medir

diff =
FUERON selcDate =
SELECTEDVALUE(Ventas[Fecha])
FUERON prvDate =
CALCULAR(
MAXX(
FILTRO(
TODO(Ventas[Fecha])
,Ventas[Fecha] < selcDate
)
,Ventas[Fecha]
)
)
FUERON PrvValue =
CALCULAR(
[Promedio de ventas]
,Ventas[Fecha] = prvDate
)
FUERON CrntValue =
CALCULAR(
[Promedio de ventas]
,Ventas[Fecha] = selcDate
)
FUERON Diff =
SI( ISBLANK(PrvValue) && NO(ISBLANK(CrntValue))
,0
,CrntValue - PrvValue
)
DEVOLUCIÓN
Diff

Archivo PBIX
He adjuntado el archivo PBIX para referencia. Aprecia tu apoyo.

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Hola @haputhanthree ,

En función del problema que haya planteado, puede cambiar el dax a lo siguiente:

diff = 
VAR selcDate =
SELECTEDVALUE(Sales[Date])
VAR prvDate =
CALCULATE(
    MAXX(
        FILTER(
            ALL('Sales')
            ,Sales[Date] < selcDate
        )
    ,Sales[Date]
    )
)
VAR PrvValue =
CALCULATE(
    [Avg Sales]
    ,Sales[Date] = prvDate,
    Sales[ProductId]<>"3"
)
VAR CrntValue =
CALCULATE(
    [Avg Sales]
    ,Sales[Date] = selcDate,
    Sales[ProductId]<>"3"
)
VAR Diff = 
IF( ISBLANK(PrvValue) && NOT(ISBLANK(CrntValue))
    ,0
    ,CrntValue - PrvValue
)
RETURN
   Diff

Resultado final:

vyifanwmsft_0-1705560894186.png

Gracias por su respuesta.
Pero estoy buscando algo dinámico ya que hay múltiples productos en el escenario real en lugar de

Sales[ProductId]<>"3"

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.