March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I have a fact table and a date table and would like to filter the fact table by using calculate table function and get data for the last month. I have some ideas as how to implement this but I need this to work at time when we are in january and want data for december the month before.
What I have already which will work for every month except january.
Last Month Orders =
CALCULATETABLE(
'Orders',
'Date'[Month No] = MONTH(TODAY()) - 1 && 'Date'[Year] = YEAR(TODAY())
)
But if we are in janurary it will show orders for december 2023 which I would not want but instead have orders for december 2022.
Solved! Go to Solution.
You can use the IF function to determine if the current month is January, if so, subtract 1 from the year, otherwise use the current year. Here is the revised code:
Last Month Orders =
CALCULATETABLE(
'Orders',
'Date'[Month No] = IF(MONTH(TODAY()) = 1, 12, MONTH(TODAY()) - 1) && 'Date'[Year] = IF(MONTH(TODAY()) = 1, YEAR(TODAY()) - 1, YEAR(TODAY()))
)
This way, no matter what the current month is, you can get the last month's data correctly.
You can use the IF function to determine if the current month is January, if so, subtract 1 from the year, otherwise use the current year. Here is the revised code:
Last Month Orders =
CALCULATETABLE(
'Orders',
'Date'[Month No] = IF(MONTH(TODAY()) = 1, 12, MONTH(TODAY()) - 1) && 'Date'[Year] = IF(MONTH(TODAY()) = 1, YEAR(TODAY()) - 1, YEAR(TODAY()))
)
This way, no matter what the current month is, you can get the last month's data correctly.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
16 | |
15 | |
7 | |
6 |
User | Count |
---|---|
33 | |
29 | |
16 | |
13 | |
12 |