Reply
ashrafkotb
Helper I
Helper I
Syndicated - Inbound

¿Cómo crear una columna calculada para restar el valor de fila anterior?

Source Community: Power BI

Hola

Necesito crear una columna calculada que resta el valor de fila actual del valor de fila anterior en función de la fecha y el nombre del cliente. Por ejemplo:

FechaValorClienteCalc_column (valor esperado)
01-04-2020100A
01-04-2020400B
01-04-2020500C
02-04-2020120A20
02-04-2020440B40
02-04-2020560C60

¡Gracias de antemano!

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Source Community: Power BI
Syndicated - Inbound

Hola @ashrafkotb

Tratar

Calc_column = 
var _thisDate = Table[Date]
var _prevDate = CALCULATE(MAX(Table[Date]), ALLEXCEPT(Table, Table[Customer]), Table[Date] < _thisDate )

RETURN
Table[Value] - CALCULATE(MAX(Table[Value]), ALLEXCEPT(Table, Table[Customer]), Table[Date] = _prevDate )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Source Community: Power BI
Syndicated - Inbound

Vea mi artículo sobre el tiempo medio entre el error (MTBF) que utiliza EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...

Así que en tu caso, algo como:

Calc_column = 
  VAR __PreviousDate = MAXX(FILTER('Table',[Date] < EARLIER([Date]) && [Customer] = EARLIER([Customer])),[Date])
  VAR __PreviousValue = MAXX(FILTER('Table',[Date] = __PreviousDate) && [Customer] = EARLIER([Customer])),[Date])
RETURN
  [Value] - __PreviousValue
  


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Source Community: Power BI
Syndicated - Inbound

Obtener un error de sintaxis para esta fórmula.

amitchandak
Super User
Super User

Source Community: Power BI
Syndicated - Inbound

@ashrafkotb ,

Pruebe nuevas columnas como

Fecha máxima: maxx(filter(Table, table[Date]<earlier(Table[Date]) && table[Customer]-earlier(Table[Customer])),Table[Date])
diff - Table[value] - maxx(filter(Table, table[Date]-earlier(Table[max date]) && table[Customer]-earlier(Table[Customer])),Table[value])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
az38
Community Champion
Community Champion

Source Community: Power BI
Syndicated - Inbound

Hola @ashrafkotb

Tratar

Calc_column = 
var _thisDate = Table[Date]
var _prevDate = CALCULATE(MAX(Table[Date]), ALLEXCEPT(Table, Table[Customer]), Table[Date] < _thisDate )

RETURN
Table[Value] - CALCULATE(MAX(Table[Value]), ALLEXCEPT(Table, Table[Customer]), Table[Date] = _prevDate )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Source Community: Power BI
Syndicated - Inbound

Esto funcionó, gracias.

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)