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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
turcelaygoy
Helper I
Helper I

What happens with the [Value] variable inside two different GENERATESERIES

Quality variation_COCHE2 = 
AVERAGEX (
CROSSJOIN (
VALUES ( 'Tabla Proyecto'[PROYECTO] ),VALUES('Tabla Area'[AREA]) ),
VAR T =
CALCULATETABLE ( Hoja1 )
RETURN
AVERAGEX (
GENERATESERIES ( MIN(Hoja1[ORDEN COCHE PROYECTO]), MAX(Hoja1[ORDEN COCHE PROYECTO]) -1 , 1 ),
var Z= [Value]
AVERAGEX(
GENERATESERIES ( Z , MAX(Hoja1[ORDEN COCHE PROYECTO]) - 1 , 1 ),
VAR W = [Value]
VAR CurrentFaults = SUMX ( FILTER ( T, Hoja1[ORDEN COCHE PROYECTO]= Z), Hoja1[FALTAS TOTALES (QA)] )
VAR NextFaults = SUMX ( FILTER ( T, Hoja1[ORDEN COCHE PROYECTO]= W + 1 ), Hoja1[FALTAS TOTALES (QA)] )
RETURN
DIVIDE ( NextFaults - CurrentFaults, CurrentFaults ) * 100 )
)
)

Hello everyone, I was trying to calculate this measure but I realised that I need to calculate two GENERATESERIES functions one inside the other. I would like to know if there is any option of making the variables Z and W work. Right now the measure doesn't work due to those two variables. I would be really grateful if anyone has a possible solution for this problem. Thanks a lot in advance ;)!!

3 REPLIES 3
rubayatyasmin
Super User
Super User

HI, @turcelaygoy 

 

Your usage of GENERATESERIES function looks fine but the issue may be with the variable scopes. In DAX, a variable maintains its value only within the context of the specific expression where it's defined (in this case, the context of the GENERATESERIES function). That means the variable Z is not recognized by the second GENERATESERIES function.

 

reorganised code:

 

Quality variation_COCHE2 =
AVERAGEX (
CROSSJOIN (
VALUES ( 'Tabla Proyecto'[PROYECTO] ),
VALUES ( 'Tabla Area'[AREA] )
),
VAR T = CALCULATETABLE ( Hoja1 )
VAR MinOrder = MIN(Hoja1[ORDEN COCHE PROYECTO])
VAR MaxOrder = MAX(Hoja1[ORDEN COCHE PROYECTO])
RETURN
AVERAGEX (
GENERATESERIES ( MinOrder, MaxOrder -1 , 1 ),
VAR Z = [Value]
RETURN
AVERAGEX(
GENERATESERIES ( Z , MaxOrder - 1 , 1 ),
VAR W = [Value]
VAR CurrentFaults = SUMX ( FILTER ( T, Hoja1[ORDEN COCHE PROYECTO] = Z ), Hoja1[FALTAS TOTALES (QA)] )
VAR NextFaults = SUMX ( FILTER ( T, Hoja1[ORDEN COCHE PROYECTO] = W + 1 ), Hoja1[FALTAS TOTALES (QA)] )
RETURN
DIVIDE ( NextFaults - CurrentFaults, CurrentFaults ) * 100
)
)
)

 

 

See if it works. 

If my post helps you in any way, hit 👍

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


And if I want to do a nested loop how should I do it?

try removing the min order max order variables. Then the calculation of NextFaults should be nested inside generateseries where w is defined. 

 

Quality variation_COCHE2 =
AVERAGEX (
CROSSJOIN (
VALUES ( 'Tabla Proyecto'[PROYECTO] ),VALUES('Tabla Area'[AREA]) ),
VAR T =
CALCULATETABLE ( Hoja1 )
RETURN
AVERAGEX (
GENERATESERIES ( MIN(Hoja1[ORDEN COCHE PROYECTO]), MAX(Hoja1[ORDEN COCHE PROYECTO]) -1 , 1 ),
VAR Z = [Value]
VAR NextFaults =
AVERAGEX(
GENERATESERIES(Z, MAX(Hoja1[ORDEN COCHE PROYECTO]) - 1, 1),
VAR W = [Value]
RETURN SUMX ( FILTER ( T, Hoja1[ORDEN COCHE PROYECTO]= W + 1 ), Hoja1[FALTAS TOTALES (QA)])
)
VAR CurrentFaults = SUMX ( FILTER ( T, Hoja1[ORDEN COCHE PROYECTO]= Z), Hoja1[FALTAS TOTALES (QA)])
RETURN DIVIDE(NextFaults - CurrentFaults, CurrentFaults) * 100
)
)

 

see if it works. 

 

If my assistance helps you in any way, hit 👍

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.