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
Jlbaenlo
Frequent Visitor

Columna adicional en la tabla, rellenada por compensación por X meses otra columna existente de esta tabla

Hola

Necesitaría alguna orientación sobre el siguiente problema

Tengo una mesa

Producto - País - Fecha - KPI1

A-C1-Jan2020- 60

A-C1-Feb2020-70

A-C1-Mar2020-50

Me gustaría añadir una columna adicional que pondría para cada producto-país-fecha el KPI1 de la fecha del mes anterior para ese mismo producto-país (y en blanco si no se encuentra ningún registro)

Producto - País - Fecha - KPI1 - Newcol

A-C1-Jan2020- 60- En blanco

A-C1-Feb2020-70- 60

A-C1-Mar2020-50-70

en el ejemplo anterior puse 60 en la nueva columna ya que era el valor del mes anterior, etc...

Necesito formular la fórmula lo suficientemente genérica para poder decidir cuántos meses atrás quiero tomar el valor.

Muchas gracias,

Br

Jean-Luc

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hola @Jlbaenlo ,

En mi opinión, @amitchandak método es el más simple y eficiente.

Si respondió a su pregunta, por favor marque su puesto como una solución.

Saludos

Eyelyn Qin

Greg_Deckler
Super User
Super User

@Jlbaenlo - Necesitará una columna de fecha verdadera o necesitará una columna de índice o necesitará una gran instrucción SWITCH desagradable para averiguar su mes anterior. Si la columna Fecha, el mes anterior es:

Newcol =
  VAR __Product = [Product]
  VAR __Country = [Country]
  VAR __PreviousMonth = EOMONTH([Date],-1)
  VAR __PreviousDate = DATE(YEAR(__PreviousMonth),MONTH(__PreviousMonth),1))
  VAR __Previous = MAXX(FILTER('Table',[Product]=__Product && [Country]=__Country && [Date]=__PreviousDate),[KPI1]

Para Index y SWITCH, lo mismo básico es cómo llegas a tu "__PreviousDate"


@ 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...
amitchandak
Super User
Super User

@Jlbaenlo, estoy suponiendo que la fecha no es mes año, de lo contrario crear una fecha

una nueva columna
sumX(filter(Table, [Product] ?earlier([Product]) && [Country] á earlier([Country]) && eomonth([Date],0) ?eomonth(earlier([Date]),-1)),[KPI1])

O

sumX(filter(Table, [Product] ?earlier([Product]) && [Country] á earlier([Country]) && eomonth([Date],0) ?eomonth(earlier([Date]),-1)),earlier([KPI1]))

Muchas gracias, funcionó brillantemente !

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.