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.
Hello,
Please can you tell me if it's possible to have variables within a loop?
Below I am calculating Output and Net Production twice whereas I thought it would be more efficient to use variables, and re-use them.
Thank you for any help,
PW
Solved! Go to Solution.
Yes, you can use variables in a loop (iterator). Here's an example. I used the DIVIDE function instead of "/" (avoids division by 0 errors).
Output =
// loop through all customers
SUMX (
'Customers, by Fiscal Year',
VAR vOutput =
ROUND ( [Output (using calculated field)], 2 )
VAR vNetProd =
ROUND ( [Net Production (USING CALCLATED FIELD)], 2 )
RETURN
IF (
CALCULATE (
IF ( vOutput <> 0, DIVIDE ( vNetProd, vOutput ), SIGN ( vNetProd ) ),
ALL ( 'Dim_Calendar'[Fiscal Period] ),
ALL ( 'Dim_Calendar'[Fiscal Quarter] )
) < 0.39999999999,
'Calculations'[Output (using calculated field)],
0
)
)
Proud to be a Super User!
Yes, you can use variables in a loop (iterator). Here's an example. I used the DIVIDE function instead of "/" (avoids division by 0 errors).
Output =
// loop through all customers
SUMX (
'Customers, by Fiscal Year',
VAR vOutput =
ROUND ( [Output (using calculated field)], 2 )
VAR vNetProd =
ROUND ( [Net Production (USING CALCLATED FIELD)], 2 )
RETURN
IF (
CALCULATE (
IF ( vOutput <> 0, DIVIDE ( vNetProd, vOutput ), SIGN ( vNetProd ) ),
ALL ( 'Dim_Calendar'[Fiscal Period] ),
ALL ( 'Dim_Calendar'[Fiscal Quarter] )
) < 0.39999999999,
'Calculations'[Output (using calculated field)],
0
)
)
Proud to be a Super User!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
97 | |
84 | |
67 | |
60 |
User | Count |
---|---|
150 | |
120 | |
99 | |
87 | |
68 |