I am trying to get percentage difference with month and year using DAX function
Month Year records
Jan 2015 100
Feb 2015 120
Mar 2015 140
Apr 2015 160
and I am trying to calculate percentage diff in a new column
Month Year records %change
Jan 2015 100 0%
Feb 2015 120 20%
Mar 2015 140 17.02%
Apr 2015 180 22%.03
In your current setup, something like this could work. Using a datetable would be better and easier though.
%change =
VAR StartLastMonth =
( DATE ( 'table'[Year], 'table'[Month] - 1, 1 ) )
VAR RecordsLastMonth =
CALCULATE (
MAX ( 'table'[Records] ),
FILTER (
'table',
'table'[Year] = YEAR ( StartLastMonth )
&& 'table'[Month] = MONTH ( StartLastMonth )
)
)
RETURN
IF (
ISBLANK ( RecordsLastMonth ),
BLANK (),
'table'[Records] - RecordsLastMonth
)
/ RecordsLastMonth
How about using below code:
SUM(Sheet1[records]) /CALCULATE(SUM('Sheet1'[records]), ALL('Sheet1'[Month]))
来源:https://stackoverflow.com/questions/52598381/percentage-difference-with-month-and-year-and-count-in-table-using-dax