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
sonm10
Helper I
Helper I

Valor anterior con grupo/categoría

Hola a todos,

Tengo valores para 3 elementos contra la fecha. Quiero calcular la tasa de cambio del valor para el artículo. Las fechas no son necesariamente consecutivas y cada artículo puede no tener las mismas fechas. Si no había ningún elemento, puedo usar index para realizar un seguimiento del valor anterior. Sin embargo, con los artículos que estoy perdido. Quiero mis datos de la siguiente manera.

FechaArtículoValorRetorno (valor anterior - actual)
11/12/2020A1
11/15/2020A21
11/16/2020A30.5
11/17/2020A2-0.333333333
11/18/2020A1-0.5
11/19/2020A21
11/21/2020A1-0.5
11/22/2020A43
11/26/2020A50.25
11/12/2020B12
11/15/2020B11-0.083333333
11/16/2020B120.090909091
11/17/2020B3-0.75
11/18/2020B216
11/19/2020B1-0.952380952
11/21/2020B21
11/22/2020B41
11/26/2020B60.5
11/12/2020C7
11/15/2020C1-0.857142857
11/16/2020C21
11/17/2020C30.5
11/18/2020C50.666666667
11/19/2020C60.2
11/21/2020C70.166666667
11/22/2020C80.142857143
11/26/2020C6-0.25

Gracias.

1 ACCEPTED SOLUTION

@sonm10 - Lo siento, lo arruiné.

Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Test','Test'[Date] < EARLIER('Test'[Date]) && [Group] = EARLIER([Group])),[Date])
VAR __Previous = MAXX(FILTER('Test','Test'[Date] = __PreviousDate && [Group] = EARLIER([Group])),[Value])
RETURN
__Current - __Previous

@ 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...

View solution in original post

6 REPLIES 6
mahoneypat
Employee
Employee

Pruebe esta expresión de columna que obtiene los resultados deseados.

Cambiar ?
VAR thisvalue á 'Tabla'[Valor]
VAR thisitem á 'Tabla'[Elemento]
VAR thisdate á 'Tabla'[Fecha]
PREv de VAR ?
CALCULAR (
LASTNONBLANKVALUE ( 'Tabla'[Fecha], MAX ( 'Tabla'[Valor] ) ),
ALL ( 'Tabla'),
'Tabla'[Fecha] < thisdate,
'Tabla'[Elemento] - thisitem
)
devolución
DIVIDE ( thisvalue - prev, prev )

Si esto funciona para usted, márquelo como la solución. Los elogios también son apreciados. Por favor, avísame si no.

saludos

palmadita





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@sonm10 , Pruebe una nueva columna como

New column =
Var _Last_date = maxx(filter(table,[Date]<earlier([Date])),[Date])
var _Last_value = maxx(filter(table,[Date]=_Last_date),[Value])
return 
divide([Value]-_Last_value,_Last_value)

Gracias @amitchandak por su solución. Sin embargo, ya que tengo varios elementos en la misma fecha y quiero que el cálculo se haga para cada elemento separado, no funciona. La solución funciona si no hay varios elementos

Greg_Deckler
Super User
Super User

@sonm10 - Si entiendo lo que está pidiendo, vea mi artículo sobre el tiempo medio entre el fracaso (MTBF) que utiliza ANTES: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
El patrón básico es:
Columna ?
VAR __Current á [Valor]
VAR __Previous á MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date]) && [Item] á EARLIER([Item])),[Value])
devolución
__Current - __Previous


@ 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...

Hola @Greg_Deckler. He implementado su solución, pero pocos datos están llegando bien, pero la mayoría de ellos son incorrectos. Se adjunta debajo de la captura de pantalla del conjunto de datos de ejemplo.

sonm10_0-1598273625472.png

He calcutuado la nueva columna de la siguiente manera:


Columna ?
VAR __Current á [Valor]
VAR __Previous á MAXX(FILTER('Test','Test'[Date] < EARLIER('Test'[Date]) && [Group] á EARLIER([Group])),[Value])
devolución
__Current - __Previous


El campo de retorno es el que debe ser el valor correcto. Se ha calculado en Excel para las comparaciones.

@sonm10 - Lo siento, lo arruiné.

Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Test','Test'[Date] < EARLIER('Test'[Date]) && [Group] = EARLIER([Group])),[Date])
VAR __Previous = MAXX(FILTER('Test','Test'[Date] = __PreviousDate && [Group] = EARLIER([Group])),[Value])
RETURN
__Current - __Previous

@ 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.