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.
Dear Community,
I would like to calculate the sum of spendigs for every year until the last existing month in my datetable to compare the spendings.
Example:
Last date in my Datetable is the 5th of Feb, so I need the Spendings until Feb for every Year existing in my Datetable.
This works fine:
Spend latest Month =
VAR LM=TOTALYTD(
SUM(Spend[GrossSpend]),
dDate[Date],
MONTH(dDate[Date])<=2
)
RETURN LM
PROBLEM: I have to manually enter the <=2 (Feb) in this Expression.
Something like this does not bring the correct results:
MONTH(dDate[Date])<=MONTH(MAX(dDate[Date]))
Any Idea?
Thanks and regards,
Michael
Solved! Go to Solution.
Ah, you need to remove the local filter context when computing the last month.
Spend latest Month =
VAR _LastMonth = CALCULATE ( MONTH ( MAX ( dDate[Date] ) ), ALL ( dDate ) )
VAR LM =
CALCULATE (
SUM ( Spend[GrossSpend] ),
KEEPFILTERS ( MONTH ( dDate[Date] ) <= _LastMonth )
)
RETURN
LM
Since you aren't using TOTALYTD quite how it's designed, you probably don't want that exact function.
See if something like this works for you:
Spend latest Month =
VAR _LastMonth = MONTH ( MAX ( dDate[Date] ) )
VAR LM =
CALCULATE (
SUM ( Spend[GrossSpend] ),
KEEPFILTERS ( MONTH ( dDate[Date] ) <= _LastMonth )
)
RETURN
LM
Note: I'm assuming you already have the year in your filter context.
Thank you very much! The Expression works fine, when I set _LastMont to a fixed value (March):
KEEPFILTERS ( MONTH ( dDate[Date] ) <= 3 )
But when I use a dynamic Value _LastMonth:
KEEPFILTERS ( MONTH ( dDate[Date] ) <= _LastMonth )
the Result is completely different and for me wrong. I don't understand this.
Example File here.
Ah, you need to remove the local filter context when computing the last month.
Spend latest Month =
VAR _LastMonth = CALCULATE ( MONTH ( MAX ( dDate[Date] ) ), ALL ( dDate ) )
VAR LM =
CALCULATE (
SUM ( Spend[GrossSpend] ),
KEEPFILTERS ( MONTH ( dDate[Date] ) <= _LastMonth )
)
RETURN
LM
Now I learned again! Thanks a lot for this solution!
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 |
---|---|
106 | |
93 | |
75 | |
62 | |
50 |
User | Count |
---|---|
147 | |
107 | |
105 | |
87 | |
61 |