Forum Discussion
Time Intelligence Function (Latest Month Sales Calculation)
Hi there,
I am working with a dataset, which has sales data starting from January 2022 to March 2024. I was trying to calculate latest month sales, i.e. March 2024. I want to make it dynamic so that if I add sales of upcoming months, it will show latest month.
I have a sales table and a calender table.
When I using dates from sales table, it kind of work:
Revenue (CM) =
CALCULATE(
[Total Revenue],
FILTER(
Data,
EOMONTH(Data[Date of Purchase],0) >= EOMONTH(MAX(Data[Date of Purchase]),0) &&
EOMONTH(Data[Date of Purchase],0) <= TODAY()
)
)
Revenue (Latest Month) =
CALCULATE(
[Total Revenue],
FILTER(
Calender,
Calender[End of Month] >= MAX(Calender[End of Month]) &&
Calender[End of Month] <= TODAY()
)
)
Any help will be highly appreciated. Thanks
2 Replies
- lbendlinSuper User
yes, in this case you need to use the latest [Date of Purchase] from the fact table. But you need to define that as a variable outside of CALCULATE.
- minhasRegular Visitor
Hi Ibendlin, thanks for your reply.
It actually works when I use latest [Date of Purchase] from fact table but doesn't work when using dimension table, i.e. Calendar table. And it seems like there is an issue with Calendar table. I tried several things to debug, such as importing fresh calendar table in different formats, creating new calendar table using Dax it doesn't work.
I more thing I have noticed, whenever I create or import new calendar table, it's hierarchy disappears as soon as I mark it as date table or after data modeling and connecting to fact table. Any idea what's going on?