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
Franco
Frequent Visitor

Measure Alert if not between two values

Hello everybody,
i have the following problem.

 

The data model is as follows

image.png

 

I need to find a measure that indicates whether the Rolling Avg Sales 3 Months is out of range (fields from/to from table Models)

 

The Measure "Rolling Avg Sales 3 Months" is

Rolling Avg Sales 3 Months = 
VAR _lastDate = 
    LASTDATE(DimDate[Date])
RETURN
    CALCULATE(
        AVERAGEX(VALUES(DimDate[Month]), [Total Sales]),
        FILTER(
            ALL(DimDate),
            DimDate[Date] <= _lastDate &&
            DimDate[Date] >= DATEADD(_lastDate,-3,MONTH)
        )
    )

 

image.png

 

thanks for your attention
Franco

1 ACCEPTED SOLUTION

Hi @Franco 
Please use

NewMeasure =
VAR From =
    CALCULATE (
        SELECTEDVALUE ( Medels[From] ),
        CROSSFILTER ( Models[ModelID], Items[ModelID], BOTH )
    )
VAR To =
    CALCULATE (
        SELECTEDVALUE ( Medels[To] ),
        CROSSFILTER ( Models[ModelID], Items[ModelID], BOTH )
    )
VAR RollingAvg = [Rolling Avg Sales 3 Months]
RETURN
    IF (
        NOT ISBLANK ( RollingAvg ),
        IF ( RollingAvg >= From && RollingAvg <= To, "IN RANGE", "OUT OF RANGE" )
    )

View solution in original post

6 REPLIES 6
tamerj1
Super User
Super User

Hi @Franco 

please try

NewMeasure =
VAR From =
    CALCULATE (
        SELECTEDVALUE ( Medels[From] ),
        CROSSFILTER ( Models[ModelID], Items[ModelID], BOTH )
    )
VAR To =
    CALCULATE (
        SELECTEDVALUE ( Medels[To] ),
        CROSSFILTER ( Models[ModelID], Items[ModelID], BOTH )
    )
VAR RollingAvg = [Rolling Avg Sales 3 Months]
RETURN
    IF ( RollingAvg >= From && RollingAvg <= To, "IN RANGE", "OUT OF RANGE" )

Hi @tamerj1 ,

thanks for the answer but if i put your measure in the table, each row is multiplied by each model

image.png

 

Hi @Franco 
Please use

NewMeasure =
VAR From =
    CALCULATE (
        SELECTEDVALUE ( Medels[From] ),
        CROSSFILTER ( Models[ModelID], Items[ModelID], BOTH )
    )
VAR To =
    CALCULATE (
        SELECTEDVALUE ( Medels[To] ),
        CROSSFILTER ( Models[ModelID], Items[ModelID], BOTH )
    )
VAR RollingAvg = [Rolling Avg Sales 3 Months]
RETURN
    IF (
        NOT ISBLANK ( RollingAvg ),
        IF ( RollingAvg >= From && RollingAvg <= To, "IN RANGE", "OUT OF RANGE" )
    )

works great!
Thanks!!!!!

Greg_Deckler
Community Champion
Community Champion

@Franco Maybe:

Measure =
  VAR __From = MAX('Table'[From])
  VAR __To = MAX('Table'[To])
  VAR __RollingAvg = [Rolling Avg Sales 3 Months]
RETURN
  IF( __RollingAvg >= __From && __RollingAvg <= __To, "IN RANGE", "OUT OF RANGE")


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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler 

but even with your measure, the records are repeated for each model.

 

I only need the green lines....

image.png

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.