Forum Discussion
DAX - FX Rate - Use previous month value until current month gets closed
- Anonymous7 years ago
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:
here is the pbix file:
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:
here is the pbix file:
- Anonymous7 years agoNot applicable
Thank you Sir !
Works like a charm !