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
Anonymous
Not applicable

Porcentaje de tiempo con un valor.

Reduction.JPG¡Hola!

Estoy trabajando en un cálculo de dax de reducción de CO2, y tengo algunos problemas con él.

Hice un filtro del año, pero en el año 2020 sólo tengo datos de enero a abril.

En mi cálculo i Dividir el uso de CO2 de los últimos años con este año. Lo que significa que a pesar de que trato de usar "Sameperiodlastyear" no puedo obtener el resultado que iam buscando.

Aquí tiene la tabla con los datos de prueba de este año (total de emisiones de CO2) y el año pasado (emisiones de CO2 del año pasado).

Mi cálculo en "reducción":

Reducción total de calculate(FORMAT(DIVIDE([emisiones de CO2) SUM(Query1[Total Reduction]));"; por ciento"))
¿Es posible hacer un cálculo, que comprueba los meses que tiene un valor en "año seleccionado", y luego sólo cuenta los del año anterior?
2 REPLIES 2
amitchandak
Super User
Super User

@JessVinsteen , En caso de que tenga la fecha y el uso de la inteligencia de fecha y hora, estos deben funcionar

// When you have slicer or calendar that end at april 2020
YTD QTY = TOTALYTD(Sum('order'[Qty]),'Date'[Date])
LYTD QTY = TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year))

// Force to stop at today

YTD QTY forced= 
var _max = today()
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced= 
var _max = date(year(today())-1,month(today()),day(today()))
return
CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

////// Force to stop max date of the fact

YTD QTY forced= 
var _max = maxx('order',[Order date])
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced= 
var _max1 =maxx('order',[Order date])
var _max = date(year(_max1)-1,month(_max1),day(_max1))
return
CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

explicado en mi seminario web : https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...

negi007
Community Champion
Community Champion

Puede realizar el cálculo YTD siempre que tenga el campo de fecha en los datos. Debe seguir estos pasos:

Creo que puedes usar el cálculo de YTD. Funcionará en el mes seleccionado, solo tendrá que seleccionar el último mes de la segmentación de datos. En tu caso podría ser abril.

Para el año en curso:

CY_Value puede utilizar el cálculo YTD generado por el sistema (si tiene datos de campo de fecha)

Para el año anterior

PY_Value calculate(SUM(Query1[Reduktion i alt]),SAMEPERIODLASTYEAR('date_table'[Fecha].[ Fecha]))

Una vez que tenga el valor CY y PY, puede usar estos valores para llegar al porcentaje. Por favor, hágamelo saber en caso de que usted está tratando de lograr algo más.




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



Proud to be a Super User!


Follow me on linkedin

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.