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

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.

Reply
Anonymous
Not applicable

Monthly Average of a column (Exchange Rate)

Hi,

 

I have an exchange rate master in my model, with following columns:

  • Conversion Date
  • Currency From
  • Currency To
  • Conversion Rate

 

I want to create a calculated column using Dax that gives Monthly Average Conversion Rate (aggregated on Currency From and Currency To). Also please note that Conversion rates might not be available for every date in a month, hence average needs to be calculated accordingly i.e. based on available rates only. 

 

Please help!

 

Thanks in advance,

Shailee

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

I found the solution:

Monthly Average Conversion Rate =
Var _Month = MONTH('Exchange Rate Master'[Conversion Date])
Var _Year = YEAR('Exchange Rate Master'[Conversion Date])
Var _MinDate = DATE(_Year,_Month,1)
Var _MaxDate = ENDOFMONTH('Exchange Rate Master'[Conversion Date])
Return CALCULATE(AVERAGE('Exchange Rate Master'[Conversion Rate]),FILTER(all('Exchange Rate Master'),'Exchange Rate Master'[Conversion Date]>=_MinDate && 'Exchange Rate Master'[Conversion Date]<=_MaxDate && 'Exchange Rate Master'[Currency From]=EARLIER('Exchange Rate Master'[Currency From]) && 'Exchange Rate Master'[Currency To]=EARLIER('Exchange Rate Master'[Currency To])))
 
Let me know if there is any better solution!

View solution in original post

daxer-almighty
Solution Sage
Solution Sage

// There's always a better solution...
// You should know that you should avoid
// CALCULATE in calculated columns for
// performance reasons.

[Monthly Average Conversion Rate] =
var CurrentDate = 'Exchange Rate Master'[Conversion Date]
var CurrentFrom = 'Exchange Rate Master'[Currency From]
var CurrentTo = 'Exchange Rate Master'[Currency To]
Var MinDate = EOMONTH( CurrentDate, -1) + 1
Var MaxDate = EOMONTH( CurrentDate )
var Result =
    AVERAGEX(
        FILTER(
            'Exchange Rate Master', true
            && 'Exchange Rate Master'[Currency From] = CurrentFrom
            && 'Exchange Rate Master'[Currency To] = CurrentTo
            &&  MinDate <= 'Exchange Rate Master'[Conversion Date]
            &&  'Exchange Rate Master'[Conversion Date] <= MaxDate
        ),
        'Exchange Rate Master'[Conversion Rate]
    )
return
    Result

View solution in original post

3 REPLIES 3
daxer-almighty
Solution Sage
Solution Sage

// There's always a better solution...
// You should know that you should avoid
// CALCULATE in calculated columns for
// performance reasons.

[Monthly Average Conversion Rate] =
var CurrentDate = 'Exchange Rate Master'[Conversion Date]
var CurrentFrom = 'Exchange Rate Master'[Currency From]
var CurrentTo = 'Exchange Rate Master'[Currency To]
Var MinDate = EOMONTH( CurrentDate, -1) + 1
Var MaxDate = EOMONTH( CurrentDate )
var Result =
    AVERAGEX(
        FILTER(
            'Exchange Rate Master', true
            && 'Exchange Rate Master'[Currency From] = CurrentFrom
            && 'Exchange Rate Master'[Currency To] = CurrentTo
            &&  MinDate <= 'Exchange Rate Master'[Conversion Date]
            &&  'Exchange Rate Master'[Conversion Date] <= MaxDate
        ),
        'Exchange Rate Master'[Conversion Rate]
    )
return
    Result
Anonymous
Not applicable

Thanks, will keep that in mind!

Anonymous
Not applicable

I found the solution:

Monthly Average Conversion Rate =
Var _Month = MONTH('Exchange Rate Master'[Conversion Date])
Var _Year = YEAR('Exchange Rate Master'[Conversion Date])
Var _MinDate = DATE(_Year,_Month,1)
Var _MaxDate = ENDOFMONTH('Exchange Rate Master'[Conversion Date])
Return CALCULATE(AVERAGE('Exchange Rate Master'[Conversion Rate]),FILTER(all('Exchange Rate Master'),'Exchange Rate Master'[Conversion Date]>=_MinDate && 'Exchange Rate Master'[Conversion Date]<=_MaxDate && 'Exchange Rate Master'[Currency From]=EARLIER('Exchange Rate Master'[Currency From]) && 'Exchange Rate Master'[Currency To]=EARLIER('Exchange Rate Master'[Currency To])))
 
Let me know if there is any better solution!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors