Forum Discussion

Shravan16's avatar
Shravan16
New Member
2 years ago
Solved

How to calculate a difference between 2 column.

Hello. I am trying to calculate the difference between 2 columns for the month from the matrix option on power BI but am unable to do it correctly. For example - Difference between Feb and Jan for t...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Shravan16 

     

    Please try this:

    As what you want, I create a new sample:

    The measure could be like:

    Measure 3 = 
    	VAR _currentbook = SELECTEDVALUE('Table'[Book])
    	VAR _currentSub = SELECTEDVALUE('Table'[Sub])
    	VAR _previousMonth = MINX(
    		ALL('Table'),
    		MONTH('Table'[Month])
    	)
    	VAR _currentMonth = MONTH(MAX('Table'[Month]))
    	RETURN
    		IF(
    			_currentMonth <> _previousMonth,
    			IF(
    				HASONEVALUE('Table'[Sub]),
    				SUMX(
    					FILTER(
    						ALLSELECTED('Table'),
    						MONTH('Table'[Month]) = _currentMonth && 'Table'[Sub] = _currentSub && 'Table'[Book]=_currentbook
    					),
    					'Table'[Open Nominal]
    				) - SUMX(
    					FILTER(
    						ALLSELECTED('Table'),
    						MONTH('Table'[Month]) = _previousMonth && 'Table'[Sub] = _currentSub && 'Table'[Book]=_currentbook
    					),
    					'Table'[Open Nominal]
    				),
    				SUMX(
    					FILTER(
    						ALLSELECTED('Table'),
    						MONTH('Table'[Month]) = _currentMonth && 'Table'[Book] = _currentbook
    					),
    					'Table'[Open Nominal]
    				) - SUMX(
    					FILTER(
    						ALLSELECTED('Table'),
    						MONTH('Table'[Month]) = _previousMonth && 'Table'[Book] = _currentbook
    					),
    					'Table'[Open Nominal]
    				)
    			)
    		)

    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.