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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
cong_nguyen_acc
Frequent Visitor

Desviación del precio de cálculo a lo largo del tiempo

Hola

Necesito ayuda para resolver un cálculo como este:

+ La siguiente tabla muestra el precio de compra de un artículo de vez en cuando.

+ Una fecha mays tienen muchos precios, distintos por el aumento de record_ID.

+ Un artículo puede tener muchos códigos de divisa.

+ las fechas no son continuas.

el objetivo es calcular la desviación del precio con el precio anterior, correlacionando con el código de divisa.

Pls ayúdame con esto.

Gracias y saludos,

Record_ID SKU_ID Invoice_Date Invoice_Datetime Purchase_Price Currency_Code

5637227309FO0115/05/201915/05/2019 9:385.68Usd
5637227316FO0116/05/201915/05/2019 10:025.05Usd
5637227328FO0116/05/201916/05/2019 9:096.68Usd
5637227329FO0116/05/201916/05/2019 9:105.68Usd
5637227376FO0117/05/201917/05/2019 7:005.68Usd
5637234115FO0126/06/201926/06/2019 9:425.08Usd
5637234804FO0128/06/201928/06/2019 9:265.08Usd
5637234805FO0128/06/201928/06/2019 9:395.08Usd
5637237067FO0122/07/201922/07/2019 2:507.08Usd
5637255524FO0123/10/201925/10/2019 6:0515.00Sgd
6 REPLIES 6
v-zhenbw-msft
Community Support
Community Support

Hola @cong_nguyen_acc ,

Probamos el código de los nandukrishnavs y funciona bien.

Tal vez puedas probar la siguiente medida.

Measure = 
VAR current_time =
    MIN ( 'Table'[Invoice_Datetime] )
VAR _previousDateTime =
    CALCULATE (
        MAX ( 'Table'[Invoice_Datetime] ),
        ALLSELECTED ( 'Table' ),
        'Table'[SKU_ID] IN DISTINCT ( 'Table'[SKU_ID] ),
        'Table'[Invoice_Datetime] < current_time,
        'Table'[Currency_Code] IN DISTINCT ( 'Table'[Currency_Code] )
    )
VAR _previousPrice =
    CALCULATE (
        SUM ( 'Table'[Purchase_Price] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Invoice_Datetime] = _previousDateTime
    )
RETURN
    IF (
        ISBLANK ( _previousPrice ),
        BLANK (),
        SUM ( 'Table'[Purchase_Price] ) - _previousPrice
)

El resultado así,

C 1.jpg

Si no cumple con su requisito, ¿podría mostrar el resultado exacto esperado basado en la tabla que ha compartido?

BTW, pbix como adjunto.

Saludos

Equipo de Apoyo comunitario _ zhenbw

Si este post ayuda, por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

amitchandak
Super User
Super User

@cong_nguyen_acc , Usted puede obtener el precio de la última fecha como. Usar tabla de fechas

Una nueva medida

Precio no contincioso de último día: CALCULATE(Avg('Table'[Price]),filter(all('Date'),'Date'[Date] ?MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date]]),Table['Date'])))

Y tomar diff con el precio

Para obtener lo mejor de la función de inteligencia de tiempo. Asegúrese de que tiene un calendario de fechas y se ha marcado como la fecha en la vista de modelo. Además, únase a él con la columna de fecha de su hecho/s. Consulte:
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

nandukrishnavs
Super User
Super User

@cong_nguyen_acc

Variation = 
var _currencu='Table'[Currency_Code]
var _previousDateTime=MAXX(FILTER(ALL('Table'),'Table'[SKU_ID]=EARLIER('Table'[SKU_ID])&&'Table'[Invoice_Datetime ]<EARLIER('Table'[Invoice_Datetime ])&&'Table'[Currency_Code]=_currencu),'Table'[Invoice_Datetime ])
var _previousPrice= MAXX(FILTER(ALL('Table'),'Table'[Invoice_Datetime ]=_previousDateTime),'Table'[Purchase_Price ])
var _variation= 'Table'[Purchase_Price ]-_previousPrice
return IF(ISBLANK(_previousPrice),BLANK(),_variation)

Capture.JPG



¿Respondí a tu pregunta? ¡Marca mi puesto como solución!
Apreciar con un kudos
🙂


Regards,
Nandu Krishna

Gracias nandukrishnavs,

El código funciona, pero todavía tiene fallos:

La variación sale mal cuando selecciono este elemento:

+ Línea 5637171193 , el resultado esperado debe ser 0 .

+ La línea 5637177070 debe ser 35.

+ La línea 5637182299 debe ser 0.

+ La línea 5637250795 debe ser 0.

Pls comprobar el código con este ejemplo de datos.

Gracias.

Record_IDSKU_IDInvoice_DateInvoice_DatetimeM_Previous_DateM_Min_DatePurchase_PriceCurrency_CodeVariación
563716501601VCDB5TP29/05/2017 0:0030/05/2017 1:5529/05/2017 0:0029/05/2017 0:0030Usd
563717119301VCDB5TP06/09/2017 0:0011/09/2017 6:5306/09/2017 0:0006/09/2017 0:0030Usd-15
563717707001VCDB5TP22/11/2017 0:0022/11/2017 9:1822/11/2017 0:0022/11/2017 0:0065Usd-30
563717707101VCDB5TP22/11/2017 0:0022/11/2017 9:2022/11/2017 0:0022/11/2017 0:0065Usd
563718229901VCDB5TP29/01/2018 0:0030/01/2018 3:3929/01/2018 0:0029/01/2018 0:0065Usd-189
563723263001VCDB5TP12/06/2019 0:0013/06/2019 10:3612/06/2019 0:0012/06/2019 0:0039Usd-26
563725079501VCDB5TP13/09/2019 0:0013/09/2019 7:2913/09/2019 0:0013/09/2019 0:0039Usd-31
563725234901VCDB5TP27/09/2019 0:0027/09/2019 7:2027/09/2019 0:0027/09/2019 0:0039Usd
563726634001VCDB5TP24/02/2020 0:0024/02/2020 10:5724/02/2020 0:0024/02/2020 0:0039Usd
563727006901VCDB5TP08/04/2020 0:0009/04/2020 8:2008/04/2020 0:0008/04/2020 0:0039Usd
AllisonKennedy
Super User
Super User

Si desea el precio al que se vendió más recientemente, deberá utilizar la función EARLIER dentro de una columna calculada. Si desea que el precio de un día o mes anterior, debe crear una tabla de fechas continua, relacionarla con la tabla existente y utilizar la inteligencia de tiempo.

¿Este post ha resuelto tu problema? Por favor, márquelo como una solución para que otros puedan encontrarlo rápidamente y para que la comunidad sepa que su problema ha sido resuelto.

Si has encontrado este post útil, por favor, dale a Kudos.

Trabajo como instructor y consultor para Microsoft 365, especializado en Power BI y Power Query.

https://sites.google.com/site/allisonkennedycv


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Además de mi respuesta anterior, aquí hay una fórmula de muestra que debería ayudar a:

Precio de compra anterior: MAXX(FILTER(Items, Items[SKU_ID]-EARLIER(Items[SKU_ID])&&Items[Currency_Code]-EARLIER(Items[Currency_Code])&& Items[Invoice_DateTime]<EARLIER(Items[Invoice_DateTime])),Items[Purchase_Price])

¿Este post ha resuelto tu problema? Por favor, márquelo como una solución para que otros puedan encontrarlo rápidamente y para que la comunidad sepa que su problema ha sido resuelto.


Si has encontrado este post útil, por favor, dale a Kudos.

Trabajo como instructor y consultor para Microsoft 365, especializado en Power BI y Power Query.

https://sites.google.com/site/allisonkennedycv


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors