Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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!
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
113 | |
99 | |
85 | |
35 | |
35 |
User | Count |
---|---|
150 | |
100 | |
78 | |
61 | |
56 |