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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Hariharan_R
Solution Sage
Solution Sage

DAX - Avoid Context transition in iterator

Hi,

I am trying to optimize a DAX measures. I have following measure (just added partial - only the virtual table section) where I could see "Context transition in iterator" problem and I was trying to avoid but not able to do.

 

VAR tab1 =
ADDCOLUMNS (
SUMMARIZE (
ALLSELECTED ( 'FT' ),
'FT'[C1_RGN],
'FT'[C2_RGN_RTLR],
'FT'[B1_VALUE],
'FT'[S1_VALUE],
'FT'[PCK],
'FT'[C_PACKS]
),
"y", ( [test])
)

 

and 

test = CALCULATE (
SUM ( 'FT'[Y_AMT] ),
ALLSELECTED (
'FT'[PCK_VALUE],
'FT'[S1_VALUE],
'FT'[S2_VALUE],
'FT'[B1_VALUE],
'FT'[S1_VALUE],
'FT'[LCL_PCK],
'FT'[C_PACKS]
)

 

Here "y" is referring another measure which has different context and scope. How to avoid Context transition in iterator in this case?

 

 

1 ACCEPTED SOLUTION
ahadkarimi
Solution Specialist
Solution Specialist

Try using variables to store the results before the context transition occurs.

VAR testValue =
CALCULATE (
SUM ( 'FT'[Y_AMT] ),
ALLSELECTED (
'FT'[PCK_VALUE],
'FT'[S1_VALUE],
'FT'[S2_VALUE],
'FT'[B1_VALUE],
'FT'[S1_VALUE],
'FT'[LCL_PCK],
'FT'[C_PACKS] ))

VAR tab1 =
ADDCOLUMNS (
SUMMARIZE (
ALLSELECTED ( 'FT' ),
'FT'[C1_RGN],
'FT'[C2_RGN_RTLR],
'FT'[B1_VALUE],
'FT'[S1_VALUE],
'FT'[PCK],
'FT'[C_PACKS]),
"y", testValue)

If you have any questions or need more info, just hit me up!

View solution in original post

1 REPLY 1
ahadkarimi
Solution Specialist
Solution Specialist

Try using variables to store the results before the context transition occurs.

VAR testValue =
CALCULATE (
SUM ( 'FT'[Y_AMT] ),
ALLSELECTED (
'FT'[PCK_VALUE],
'FT'[S1_VALUE],
'FT'[S2_VALUE],
'FT'[B1_VALUE],
'FT'[S1_VALUE],
'FT'[LCL_PCK],
'FT'[C_PACKS] ))

VAR tab1 =
ADDCOLUMNS (
SUMMARIZE (
ALLSELECTED ( 'FT' ),
'FT'[C1_RGN],
'FT'[C2_RGN_RTLR],
'FT'[B1_VALUE],
'FT'[S1_VALUE],
'FT'[PCK],
'FT'[C_PACKS]),
"y", testValue)

If you have any questions or need more info, just hit me up!

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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