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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
PVO3
Impactful Individual
Impactful Individual

Multiple contexts within iterator

Hello all,

 

I would like some help with a measure.

See the screenshot below. I would like that the result of Measure2 would be 143 for every row.

In VAR _Result I already have the result and they should only be summed.

Only problem is that I can't find the right context within _Result. It basicly just does (Measure1 - 6.5 (_Avg) ) ^2

Tried different SUMX variants, but because of the context within the expression, I can't figure it out.

Example PBIX 

 

Can someone please provide some help? Thanks a lot!

Measure2.PNG

 

 

 

 

Measure1 = 
var MinDate = CALCULATE(MIN('Orders'[Date]),ALLSELECTED('Date')) 
Var MaxDate = CALCULATE(MAX('Orders'[Date]),'Orders'[Date] < DATE(YEAR(TODAY()), MONTH(TODAY()), 1))
RETURN

IF(
    ISFILTERED('Date'[YearMonth]),
        CALCULATE(DISTINCTCOUNT('Date'[YearMonth]),   
            FILTER(ALL('Date'[Date]),[Date] <= MaxDate && [Date] >= MinDate)
        )
)

 

 

 

 

 

 

 

Measure2 = 
VAR _MaxR = CALCULATE(MAXX(VALUES('Date'[YearMonth]),[Measure1]),REMOVEFILTERS())
VAR _Avg = DIVIDE(CALCULATE(SUMX(VALUES('Date'[YearMonth]),[Measure1]),REMOVEFILTERS()),_MaxR)
VAR _Result = ([Measure1] - _Avg)  ^2
RETURN

IF(
    [Measure1] < 1,BLANK(),
    _Result 
)

 

 

 

 

10 REPLIES 10
PVO3
Impactful Individual
Impactful Individual

Nobody has a clue how to do this? Would be great to find a solution.

PVO3
Impactful Individual
Impactful Individual

So, no solution yet. I doubt that this is not possible. Help would be greatly appreciated!

v-henryk-mstf
Community Support
Community Support

Hi @PVO3 ,

 

Try the measure as below:

Measure2 =
VAR _MaxR =
    CALCULATE (
        MAXX ( VALUES ( 'Date'[YearMonth] ), [Measure1] ),
        REMOVEFILTERS ()
    )
VAR _Avg =
    DIVIDE (
        CALCULATE (
            SUMX ( VALUES ( 'Date'[YearMonth] ), [Measure1] ),
            REMOVEFILTERS ()
        ),
        _MaxR
    )
VAR _Result = ( [Measure1] - _Avg ) ^ 2
VAR a =
    IF ( [Measure1] < 1, BLANK (), _Result )
RETURN
    SUMX (
        FILTER ( ALLEXCEPT ( 'Date', 'Date'[Date], 'Date'[MonthNumber] ), _Result ),
        a
    )

If the problem is still not resolved, please point it out. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PVO3
Impactful Individual
Impactful Individual

Thanks a lot for your effort @v-henryk-mstf 

Unfortunatly it didnt give the expected result. Tried it in the example file and if gave the result below.

Or perhapse I'm missing something?

HendryK Measure.PNG

smpa01
Community Champion
Community Champion

@PVO3  can you please explain what you are trying to do with Measure2? 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
PVO3
Impactful Individual
Impactful Individual

Hi @smpa01 ultimately this should be a part of a slope calculation.

amitchandak
Super User
Super User

@PVO3 , try like

 

 

Measure2 = 
VAR _MaxR = CALCULATE(MAXX(VALUES('Date'[Month Year]),[Measure1]),allselected())
VAR _Avg = DIVIDE(CALCULATE(SUMX(VALUES('Date'[Month Year]),[Measure1]),allselected()),_MaxR)
VAR _Result = power(([Measure1] - _Avg)  ,2)
RETURN

IF(
    [Measure1] < 1,BLANK(),
    _Result 
)

 

 

or

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
PVO3
Impactful Individual
Impactful Individual

Thanks!

I changed the REMOVEFILTERS to ALLSELECTED & ^2 to POWER(,2)

Unfortunatly the result remained the same. 

 

But perhapse this is an improvement in general.

 

@PVO3 , Please share sample in table format , need to try this in power bi

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
PVO3
Impactful Individual
Impactful Individual

Thanks a lot for your effort.

I created an example. Link in first post.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.