Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I am having challenges getting this measure to work as expected. I have to adjust costs in the current month by calculating the cost in the past months closed and then averaging them.
Adjusted costs = VAR closedmonth = ClosedMth[ClosedMth Value] -- What-if parameter VAR selectedyear = MAX(Financials[Year]) VAR selectedmonth = MAX(Financials[Month]) VAR currentmonth = MONTH(NOW()) VAR currentyear = YEAR(NOW()) VAR previousyear = YEAR(NOW())-1 RETURN CALCULATE( CALCULATE( SUM(Financials[Amount]), FILTER(Financials, Financials[Account] IN {"50900", "50910"})), FILTER( ALL(Financials[Month],Financials[Year]), Financials[Month]<=closedmonth && Financials[Year]=previousyear))
The measure works properly if I add a slicer for the year and one for the month and have the current month manually selected.
However, I would like to remove those slicer and have that dynamically set so I wrote a calculated column for the current year/month and added it as a page filter.
Current = VAR presentMonth = MONTH(NOW()) VAR presentYear = YEAR(NOW()) RETURN IF(Financials[Month]=presentMonth && Financials[Year]=presentYear, "Current", "Past")
Unfortunately, once I add this Filter to the Page level filters, the row context overpowers the filter context from the measure. I also tried using a Relative Slicer but couldn't solve the problem. In my case, editing interactions wouldn't work either. I would still want to use a page level filter but somehow have the measure display the correct result.
Can someone help me rewrite the measure in order to achieve my goal of only displaying the results for that month by calculating past months costs? How can I get around this problem?
Thank you,
C
Hi @IoanCosmin
Could you show an screenshot of your expected output?
Based on my understanding, you want to remove the slicer where you have the current month manually selected.
then the visual dynamically show the current month's data.
If so, you could create a measure to define whether Financials[Month]=Month(now( )) and Financials[Year]=Year(now( )),
eg. measure=if (max(Financials[Month])=Month(now( )) &&max( Financials[Year])=Year(now( )),1,0)
then add this measure to page level filter and select "show items when values is 1",
If i don't understand correctly or my reply doesn't solve your problem, please let me know.
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @v-juanli-msft
I am attaching a sample workbook. If you toggle the Page level filter (to Current) you will understand exactly where the problem lies.
When the Page filter is set to (All) the result of the measure is correct. Once you set it to the current month (Current), instead of displaying the same result, it overwrites the logic in the measure. How can I avoid this and still get the correct result with a page level filter?
Thank you very much,
Cosmin
Hi @IoanCosmin
Do you like this
year | month | sales | measure |
2017 | 9 | 1 | 1 |
2017 | 10 | 2 | (1+2)/2 |
2017 | 11 | 3 | (1+2+3)/3 |
2017 | 12 | 4 | (1+2+3+4)/4 |
2018 | 1 | 5 | (1+2+3+4+5)/5 |
Best regards
Maggie
Thanks for the suggestion, Maggie. To be honest, I don't really like this approach because I would rather stick with a measure than a calculated column.
Is there another way around this?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
100 | |
76 | |
74 | |
49 |
User | Count |
---|---|
145 | |
108 | |
107 | |
89 | |
61 |