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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

DAX - FX Rate - Use previous month value until current month gets closed

Hi guys,

 

Title of the post says it all.

 

Would it be possible to write a measure in DAX that uses the FX rate of the previous month until the current month gets closed ?

FX rate for the current month is currently NULL in my table and only gets populated until month-end.

In the meantime, we use the rate of the previous month.

 

FX Rate.PNG

 

Thank in advance for the help.

 

Jason.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Couple of ways to do this, but here's the DAX version ( well mostly Dax..)

 

1. Need a calendar table.  In the attached PBIX file in Power Query there is a function that will produce the table after you enter in the start and end year. 

 

2. Load that, and mark that as a Date table. Then be sure to relate that to the Currency Table ( 1 to many )

 

3. From there, use the Dates from the DimCalendar table for your matrix. There's a column I added in that is marked as End of Month so that i only pulls in end of the month ( since now we have every single date in the years)

 

4. Then these measures:

CurrencyRate = SUM ('Currency'[Rate] )
Prev Month = 
Var __CurrencyRate = SUM ( Currency[Rate])
Return 

Var __PrevMonth= CALCULATE( [CurrencyRate], PREVIOUSMONTH(DimCalendar[Date]))
Return

IF(
    NOT ( ISBLANK( __CurrencyRate)),
    __CurrencyRate,
    __PrevMonth
)

Final outut:

Input vs Final Table.png

here is the pbix file:

https://1drv.ms/u/s!Amqd8ArUSwDSzz8NKI8SdFZuxoc5

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Couple of ways to do this, but here's the DAX version ( well mostly Dax..)

 

1. Need a calendar table.  In the attached PBIX file in Power Query there is a function that will produce the table after you enter in the start and end year. 

 

2. Load that, and mark that as a Date table. Then be sure to relate that to the Currency Table ( 1 to many )

 

3. From there, use the Dates from the DimCalendar table for your matrix. There's a column I added in that is marked as End of Month so that i only pulls in end of the month ( since now we have every single date in the years)

 

4. Then these measures:

CurrencyRate = SUM ('Currency'[Rate] )
Prev Month = 
Var __CurrencyRate = SUM ( Currency[Rate])
Return 

Var __PrevMonth= CALCULATE( [CurrencyRate], PREVIOUSMONTH(DimCalendar[Date]))
Return

IF(
    NOT ( ISBLANK( __CurrencyRate)),
    __CurrencyRate,
    __PrevMonth
)

Final outut:

Input vs Final Table.png

here is the pbix file:

https://1drv.ms/u/s!Amqd8ArUSwDSzz8NKI8SdFZuxoc5

Anonymous
Not applicable

Thank you Sir !

Works like a charm !

Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try this mEASURE

 

Measure =
IF (
    ISBLANK ( SELECTEDVALUE ( Table1[Histo Rate] ) ),
    CALCULATE (
        MAX ( Table1[Histo Rate] ),
        LASTNONBLANK ( ALL ( Table1[Month] ), CALCULATE ( MIN ( Table1[Histo Rate] ) ) )
    ),
    SELECTEDVALUE ( Table1[Histo Rate] )
)

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors