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.
How do you calculate the last 4 months from month was choice on month slicer ?
if choice month 10 in slicer I want to see sum amount for per month of 10,9,8,7 only
My solution does not work because it shows me a cumulative amount for the last selected month:
last_4_month_sum =
VAR start_of_selected_month = STARTOFMONTH('Dates'[Date])
VAR start_of_4_month = EDATE(start_of_selected_month,-3)
VAR end_of_selected_month = ENDOFMONTH('Dates'[Date])
RETURN
CALCULATE(
SUM('Table1'[Sum]),
DATESBETWEEN
(
'Dates'[Date],
start_of_4_month,
end_of_selected_month
)
)
Solved! Go to Solution.
To do this, you first need to make a DAX calculated table with just your Month values to be used in the slicer (e.g., with SlicerMonths = VALUES('Date'[MonthNumber])
Then you can use a measure like this to get your desired result (bar chart should use MonthNumber column from the Date table, and there is no relationship needed between Date and SlicerMonths table.
Just Last 4 Months =
VAR thismonth =
SELECTEDVALUE ( SlicerMonths[Monthnumber] )
RETURN
CALCULATE (
[Total Sales],
KEEPFILTERS ( 'Date'[Monthnumber] <= thismonth
&& 'Date'[Monthnumber] >= thismonth - 3 )
)
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Thanks friends,
With your help I understood where there was a problem
A filter with an unlinked external table should be used.
I have not encountered it until today))
Can you give a short explanation of why I need an external and unlinked table for filtering ??
It did not open for me 4 previous months .....
After thinking for 10 minutes I basically came up with the somewhat same solution as Mahoney, but now that I had spent time on this so thought of sharing it with the file, you can access the file from here. https://drive.google.com/file/d/1WlcVuytdqxbT1ndyu-Bwn0tz-AjEdgED/view?usp=sharing
Measure =
VAR MaxDate =
CALCULATE (
MAX ( DisconnectedDates[Month Number] ),
ALLSELECTED ( DisconnectedDates )
)
VAR PreviousMonths =
FILTER (
ALL ( Dates[Month Number] ),
Dates[Month Number] <= MaxDate
&& Dates[Month Number] >= MaxDate - 3
)
VAR Result =
CALCULATE ( [Total Sales], KEEPFILTERS ( PreviousMonths ) )
RETURN
Result
@Galat , refer to this
https://www.youtube.com/watch?v=duMSovyosXE
To do this, you first need to make a DAX calculated table with just your Month values to be used in the slicer (e.g., with SlicerMonths = VALUES('Date'[MonthNumber])
Then you can use a measure like this to get your desired result (bar chart should use MonthNumber column from the Date table, and there is no relationship needed between Date and SlicerMonths table.
Just Last 4 Months =
VAR thismonth =
SELECTEDVALUE ( SlicerMonths[Monthnumber] )
RETURN
CALCULATE (
[Total Sales],
KEEPFILTERS ( 'Date'[Monthnumber] <= thismonth
&& 'Date'[Monthnumber] >= thismonth - 3 )
)
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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 |
---|---|
47 | |
23 | |
20 | |
15 | |
13 |
User | Count |
---|---|
51 | |
42 | |
39 | |
19 | |
19 |