Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Cómo obtener los últimos 3 años

Hola a todos

Esto puede ser bastante simple, pero tengo dificultades para lograrlo.

Necesito los últimos 3 años (2020, 2019, 2018) en la tabla visual cuando elijo 2020 de una tabla "año" que tengo.

la tabla Year contiene una columna como Year con valores (2020, 2019, ...... 2010)

Cuando selecciono 2020 del filtro Año, necesito mostrar sólo 2020, 2019, 2018 en la tabla visual que tenemos en powerBI.

Actualmente cuando elijo 2020, muestra sólo 2020.

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hola, @LP280388

Según su descripción, creé datos para reproducir su escenario. El archivo pbix se adjunta al final.

Mesa:

a1.png

año:

a2.png

Puede crear una medida como se indica a continuación.

Visual Control = 
var _selectedyear = SELECTEDVALUE('Year'[Year])
var _cyear = YEAR(SELECTEDVALUE('Table'[Date]))
return
IF(
    HASONEVALUE('Year'[Year]),
    IF(
        _cyear>=_selectedyear-2&&
        _cyear<=_selectedyear,
        1,0
    ),
    1
)

A continuación, debe colocar la medida en el filtro de nivel visual para obtener el resultado.

a4.png

a3.png

Saludos

Allan

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

View solution in original post

5 REPLIES 5
v-alq-msft
Community Support
Community Support

Hola, @LP280388

Según su descripción, creé datos para reproducir su escenario. El archivo pbix se adjunta al final.

Mesa:

a1.png

año:

a2.png

Puede crear una medida como se indica a continuación.

Visual Control = 
var _selectedyear = SELECTEDVALUE('Year'[Year])
var _cyear = YEAR(SELECTEDVALUE('Table'[Date]))
return
IF(
    HASONEVALUE('Year'[Year]),
    IF(
        _cyear>=_selectedyear-2&&
        _cyear<=_selectedyear,
        1,0
    ),
    1
)

A continuación, debe colocar la medida en el filtro de nivel visual para obtener el resultado.

a4.png

a3.png

Saludos

Allan

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Ashish_Mathur
Super User
Super User

Hola

Vea si mi solución aquí ayuda - Flexionar una tabla dinámica para mostrar los datos durante x meses terminado un determinado mes def...


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

@LP280388 - Suena como si quisiera usar un selector complejo, pero no puede estar seguro a menos que comparta datos de ejemplo.

https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Complex-Selector/m-p/1116633#M534

El ejemplo es casi idéntico a lo que está tratando de lograr. Es casi seguro que querrá una tabla desconectada para su segmentación. Puede crearlo utilizando

SlicerTable = DISTINCT('Table'[Year])


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

@LP280388 , si selecciona 1 desea mostrar tres

referir este https://www.youtube.com/watch?v=duMSovyosXE

Balanceo

Rolling 3 - CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-3,Year))
Rolling 3 á CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-3,Year))

Tres años - Necesidad de tener un año o tabla de fechas

Ventas YTD á CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales á CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Este año Ventas: CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))

Ventas del año pasado: CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales - CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

Puede trabajar con la tabla Year

Este año: CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]-max('Date'[Year])))
Last Year ? CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]-max('Date'[Year])-1))

Last to Last Year ? CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]-max('Date'[Year])-2))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak

Hola Amit, no necesito calcular ninguna venta o Cantidad. Sólo necesito mostrar los últimos 3 años nombres como "2020", "2019", "2018"

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors
Top Kudoed Authors