Forum Discussion

M_SBS_6's avatar
M_SBS_6
Helper V
2 years ago
Solved

% diff 2 values

Hi,    I have a matrix whereby I am looking at my values split by year and then day/month. Below is how the matrix is made up.    What I'd like to add in is the % difference between current year ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi M_SBS_6 

    Maybe you can try this:

    I create a set of sample data:

    Then create a measure:

    DIFF = 
    	VAR _currentMonth = MONTH(MAX('Table'[date]))
    	VAR _currentYear = YEAR(MAX('Table'[date]))
    	VAR _PreviousYear = CALCULATE(
    		YEAR(MAX('Table'[date])),
    		FILTER(
    			ALLSELECTED('Table'),
    			YEAR('Table'[date]) < _currentYear
    		)
    	)
    	VAR _perviousValue = CALCULATE(
    		SUM('Table'[value]),
    		FILTER(
    			ALLSELECTED('Table'),
    			YEAR('Table'[date]) = _PreviousYear && MONTH('Table'[date]) = _currentMonth
    		)
    	)
    	RETURN
    		IF(
    			_perviousValue <> BLANK(),
    			(_perviousValue - SUMX(
    				'Table',
    				'Table'[value]
    			)) / _perviousValue
    		)

    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.