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

Cálculo de columnas - determinación del cambio en los valores

¡Hola a todos!

Me gustaría abordar un determinado problema al que me enfrento con Power BI.

Tengo una tabla en el siguiente formato (formato de fecha dd/mm/aaaa):

Fechavalor1valor2valor3
24/04/2020416
23/04/2020345

Los valores 1, 2 y 3 son parámetros relacionados con mi industria.

Necesito una nueva columna, llamada "análisis", que realizará el siguiente cálculo:

análisis (hoy) á (valor1(ayer) + valor2(ayer)) - (valor1(hoy) + valor2(hoy)) + (valor3(hoy) - valor3(ayer))

En palabras, la nueva columna se calculará como el cambio en la suma de los valores 1 y 2, más la adición ocurrida en el valor 3.

En mi ejemplo, el resultado del "análisis" para "24/04/2020":

analysis_24/04/2020 á (3+4) - (4+1) + (6-5) á 7 - 5 + 1 á 3

¿Alguna idea? He intentado usar FILTER combinado con SELECTCOLUMNS, pero teniendo en cuenta un tener una tabla real con mucho más de 2 filas, esto no está funcionando.

¡Gracias de antemano!

1 ACCEPTED SOLUTION

Hola @JGRaiol ,

Pruebe esta columna calculada:

Columna ?
VAR _date á 'Tabla'[fecha]
VAR _lastDate - CALCULATE(MAX('Table'[date]); FILTRO(ALL('Tabla'); 'Tabla'[fecha] < _date))
VAR _tb - FILTER(ALL('Table'); 'Tabla'[fecha] - _lastDate)
devolución
IF(COUNTROWS(_tb) > 0;
(SELECTCOLUMNS(_tb; "V1"; 'Table'[value1]) + SELECTCOLUMNS(_tb; "V2"; 'Tabla'[valor2])) -
('Tabla'[valor1] + 'Tabla'[valor2]) +
('Tabla'[valor3] - SELECTCOLUMNS(_tb; "V3"; 'Tabla'[valor3]));
BLANCO())
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hola

Agregué una fila para el 25 de abril de 2020 con la siguiente información 6,3,4. Este es el resultado que obtuve. Puede descargar mi archivo PBI desde aquí.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
DataZoe
Employee
Employee

Esta medida debería funcionar @JGRaiol:

Analysis = 
sumx(values(analysistable[Date]),
(calculate(sum(analysistable[v1]),PREVIOUSDAY(analysistable[Date]))
    +calculate(sum(analysistable[v2]),PREVIOUSDAY(analysistable[Date])))
-
(sum(analysistable[v1])
    +sum(analysistable[v2]))
+
(sum(analysistable[v3])
    -calculate(sum(analysistable[v3]),PREVIOUSDAY(analysistable[Date]))))

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

az38
Community Champion
Community Champion

Hola @JGRaiol

podría ser una columna como

Column = 
var _thisDate = Table[Date]
var _prevDate = CALCULATE(MAX(Table[Date]), Table[Date] < _thisDate)
var _prevVal1 = CALCULATE(MAX(Table[Value1]), Table[Date] = _prevDate)
var _prevVal2 = CALCULATE(MAX(Table[Value2]), Table[Date] = _prevDate)
var _prevVal3 = CALCULATE(MAX(Table[Value3]), Table[Date] = _prevDate)
RETURN
_prevVal1 + _prevVal2 - ([Value1] + [Value2]) + ([Value3] - _prevVal3 )

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

Hola @az38, muchas gracias por su respuesta!

Entendí perfectamente su implementación, pero cuando la puse en mi BI, todas las prevdate y prevVals están regresando en blanco, y no el valor adecuado. Estoy implementando esto como una columna calculada.

¿Alguna idea?

¡Muchas gracias!

Hola @JGRaiol ,

Pruebe esta columna calculada:

Columna ?
VAR _date á 'Tabla'[fecha]
VAR _lastDate - CALCULATE(MAX('Table'[date]); FILTRO(ALL('Tabla'); 'Tabla'[fecha] < _date))
VAR _tb - FILTER(ALL('Table'); 'Tabla'[fecha] - _lastDate)
devolución
IF(COUNTROWS(_tb) > 0;
(SELECTCOLUMNS(_tb; "V1"; 'Table'[value1]) + SELECTCOLUMNS(_tb; "V2"; 'Tabla'[valor2])) -
('Tabla'[valor1] + 'Tabla'[valor2]) +
('Tabla'[valor3] - SELECTCOLUMNS(_tb; "V3"; 'Tabla'[valor3]));
BLANCO())
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



¡Gracias! ¡Eso funcionó!

Saludos

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.