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
DebbieE
Community Champion
Community Champion

Tratar de crear una medida de varianza TYD con variables y no obtener un resultado

YTD Ventas Var - VAR CY - [Ventas totales]
VAR TYTD á TOTALYTD([Total Sales],DimDate[FullDateAlternateKey])
VAR LYTD á CALCULATE(TYTD,SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))
DEVOLUCIÓN TYTD-LYTD
esto está surgiendo como nada
YOY.JPG
Cuando pongo a prueba miro sólo a TYTD
YTD Ventas Var - VAR CY - [Ventas totales]
VAR TYTD á TOTALYTD([Total Sales],DimDate[FullDateAlternateKey])
VAR LYTD á CALCULATE(TYTD,SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))
RETURN TYTD
Y esto trae a la vista el año hasta la fecha valores sin problema
Y la siguiente prueba reemplazo la última parte con RETURN LYTD
Y de nuevo, se obtiene el showm de los totales del último año hasta la fecha para que tanto TYTD como LYTD devuelvan los valores correctos
Así que es sólo este RETORNO TYTD-LYTD
esto devuelve 0 y no puedo entender por qué en este momento. Estoy usando los datos de almacenamiento de datos de Adventureworks para probar
Cualquier ayuda sería apreciada
1 ACCEPTED SOLUTION
DebbieE
Community Champion
Community Champion

Ive got it

 

YTD Sales Var = VAR CY = [Total Sales]
VAR LYTD = CALCULATE(TOTALYTD([Total Sales],DimDate[FullDateAlternateKey]),SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))
RETURN TYTD-LYTD
 
I have to add the TYTD into LYTD to make that work because I cant use a variable within another variable like you said
 

View solution in original post

5 REPLIES 5
v-xicai
Community Support
Community Support

Hola @DebbieE ,

En DAX, las variables se calculan dentro del ámbito en el que se escriben y, a continuación, el resultado de ellas se almacena y se utiliza en el resto de la expresión. Consulte más información: Precaución al usar variables en DAX y Power BI.

Puede cambiar la fórmula como DAX a continuación.

YTD Sales Var =

VAR TYTD = TOTALYTD(SUM(Table1[Sales]), DimDate[FullDateAlternateKey])

VAR LYTD = CALCULATE(SUM(Table1[Sales]) ,SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))

RETURN TYTD-LYTD

Como referencia:

https://community.powerbi.com/t5/Desktop/var-different-result/td-p/283143

https://community.powerbi.com/t5/Desktop/VAR-different-result-than-without-it/td-p/518723

Saludos

Amy

Equipo de apoyo a la comunidad _ Amy

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

DebbieE
Community Champion
Community Champion

VAR LYTD = CALCULATE (SUM (Table1 [Sales]), SAMEPERIODLASTYEAR (DimDate [FullDateAlternateKey]))

 

But this isnt calculating the Year to date measure that Im basing last year on so this wouldnt work?

As in my TYTD variable

 

TOTALYTD (SELECTEDMEASURE (), DimDate [FullDateAlternateKey])

 

I should say, Im trying to do some work on calulated groups with Tabular Editor and Im trying to find ways of recreating my measures so they could be used for calculated groups and its proving really difficult

DebbieE
Community Champion
Community Champion

Ive got it

 

YTD Sales Var = VAR CY = [Total Sales]
VAR LYTD = CALCULATE(TOTALYTD([Total Sales],DimDate[FullDateAlternateKey]),SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))
RETURN TYTD-LYTD
 
I have to add the TYTD into LYTD to make that work because I cant use a variable within another variable like you said
 
amitchandak
Super User
Super User

@DebbieE, esto debería funcionar. DimDate se marca como tabla de fechas (Opción al hacer clic con el botón derecho)

FullDateAlternateKey es una fecha, no la clave numérica

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
Greg_Deckler
Super User
Super User

@DebbieE - Esto le puede resultar útil - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

También, ver si mi Inteligencia del Tiempo el Camino Duro proporciona una manera diferente de lograr lo que está buscando.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



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...

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.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors