Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
So looking through the syntax of PREVIOUSMONTH(dates) function, you would need to specify a dates column and it would return the previous month based on the first value of the dates column. Problem is, I have a "Year" slicer which selects current year, 2023, 2022, etc... and if I filter any of the years, the previousmonth function will return the number of sales in December of the prior year.
That is because the dates column is returning values from Jan 1-December 31 of the selected year, and the function will always base it on January 1 as that is the first value of the column and thus calculate December numbers.
Is there a way I can apply a filter on the previousmonth function, or somewhere in my measure?
I am using the USERELATIONSHIP function that links the sale date column with my date calendar.
We are in February right now, and the measure is still returning December 2023 numbers. If only I can apply a filter on the column that is being used in the previousmonth function, such as only start the first value from today's date? Is there a way to do this as I've used datesbetween and filter functions, and it does not return the correct values
Solved! Go to Solution.
Hi @beepboop
Please try this:
First of all, I create a set of sample data:
Then create a measure:
Measure =
IF(
MONTH(TODAY()) - 1 = 0,
CALCULATE(
SUM('Table'[value]),
FILTER(
ALLSELECTED('Table'),
MONTH('Table'[date]) = 12 && YEAR('Table'[date]) = YEAR(TODAY() - 1)
)
),
CALCULATE(
SUM('Table'[value]),
FILTER(
ALLSELECTED('Table'),
MONTH('Table'[date]) = MONTH(TODAY()) - 1 && YEAR('Table'[date]) = YEAR(TODAY())
)
)
)
The result is as follow:
Best Regards,
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @beepboop
Please try this:
First of all, I create a set of sample data:
Then create a measure:
Measure =
IF(
MONTH(TODAY()) - 1 = 0,
CALCULATE(
SUM('Table'[value]),
FILTER(
ALLSELECTED('Table'),
MONTH('Table'[date]) = 12 && YEAR('Table'[date]) = YEAR(TODAY() - 1)
)
),
CALCULATE(
SUM('Table'[value]),
FILTER(
ALLSELECTED('Table'),
MONTH('Table'[date]) = MONTH(TODAY()) - 1 && YEAR('Table'[date]) = YEAR(TODAY())
)
)
)
The result is as follow:
Best Regards,
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Is there a way to return only one calculate expression and do an IF expression within the dates itself? Such as CALCULATE(SUM(TABLE)), IF(MONTH()=....,FILTER(DATE)..,FILTER))
Sorry, i didnt quite understand what is the requirement,
if you are in feb 2023, what do you want your measure to return ?
Hi @beepboop ,
As always, please share a usable sample data that fully encompasses your use case (not an image) and your expected result from that data. You may also share a pbix with confidential info removed. You can post a link to Google Drive, OneDrive or DropBox.
Proud to be a Super User!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
119 | |
83 | |
47 | |
42 | |
33 |
User | Count |
---|---|
190 | |
79 | |
72 | |
52 | |
46 |