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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Calculate within greater than and less than time frame

Hello! I'm stuck with a rather easy problem. Just can't figure out the right syntax for the formula. Problem: I need to get an average quote (exchange rate) calculated for the period starting on the 25th day two months prior and ending on 24th day one month prior and apply that measure to the measure in current month. The formula I came up with:

 

 

AD_EURO =
CALCULATE (
    AVERAGEX ( 'CBR EURO', 'CBR EURO'[EURO-RUR] ),
    FILTER (
        Dates,
        Dates[Date]
            >= DATE ( YEAR ( DATEADD ( Dates[Date], -2, MONTH ) ), MONTH ( DATEADD ( Dates[Date], -2, MONTH ) ), 25 )
    ),
    FILTER (
        Dates,
        Dates[Date]
            <= DATE ( YEAR ( DATEADD ( Dates[Date], -2, MONTH ) ), MONTH ( DATEADD ( Dates[Date], -1, MONTH ) ), 24 )
    )
)

 

But I'm getting no results. Using && instead of second filter returns no result as well. All connections are active.

Said time frame is set and adding or substracting days wont do the trick.

 

The result I'm trying to get

Снимок экрана 2020-10-15 184019.png

 

Thank you!

 

 

Solution from here won't help https://community.powerbi.com/t5/Desktop/Building-a-Date-from-Year-Month-and-Day-columns/td-p/953265

since it won't solve the year start/end periods

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Found a workaround.

I've created additional columns FromDate and ToDate and used AVERAGEX with DATESBEWEEN

 

screen2.png

For the expression to work as measure just added min and max

AD_EURO = 
CALCULATE (
    AVERAGEx ( Dates,Dates[EURORUR_intermed]),
DATESBETWEEN(Dates[Date],MIN(Dates[FromDate]),MAX(Dates[ToDate])
))

bpn1973_0-1602847985473.png

 

Self service at its finest 😋

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Added two columns to the dates table

bpn1973_0-1602837328244.png

 

FromDate =
DATE ( YEAR ( DATEADD ( Dates[Date], -2, MONTH ) ), MONTH ( DATEADD ( Dates[Date], -2, MONTH ) ), 25 )

ToDate =
DATE ( YEAR ( DATEADD ( Dates[Date], -1, MONTH ) ), MONTH ( DATEADD ( Dates[Date], -1, MONTH ) ), 24 )

 

To get a corresponding average for the date added another column

 

 

Average_USD = 
CALCULATE (
    AVERAGE ( Dates[USDRUR_intermed] ),
    FILTER (
        Dates,
        Dates[Date] >= Dates[FromDate]
            && Dates[Date] <= Dates[ToDate]
    )
)

 

Returns blank

 

When i use single condition - either >=FromDate or <=ToDate - average exchange rate is returned either for all the dates greater than first entry of FromDate or less than last entry of ToDate 

 

STILL NEED HELP

Anonymous
Not applicable

Found a workaround.

I've created additional columns FromDate and ToDate and used AVERAGEX with DATESBEWEEN

 

screen2.png

For the expression to work as measure just added min and max

AD_EURO = 
CALCULATE (
    AVERAGEx ( Dates,Dates[EURORUR_intermed]),
DATESBETWEEN(Dates[Date],MIN(Dates[FromDate]),MAX(Dates[ToDate])
))

bpn1973_0-1602847985473.png

 

Self service at its finest 😋

Anonymous
Not applicable

Any ideas? Anyone...

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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