Forum Discussion

LFM's avatar
LFM
Helper III
2 years ago
Solved

Finding delta between certain dates while filtering the dates

I want to find the change of values between dates while filtering between dates on the slicer. F.eks I want to choose the dates 01.02.2024 and 15.02.2024 on the slicer and then see the delta value between those dates.
I have tried the DAX measure shown below, but it will only show values for certain days back in time, and I cannot filter between different dates. 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi LFM 

     

    Please try this:
    First of all, I create a set of sample:

    Then add a measure:

    Diff = 
    	VAR _currentDate = CALCULATE(
    		MAX('Table'[Date]),
    		ALLSELECTED('Table')
    	)
    	VAR _previousDate = CALCULATE(
    		MIN('Table'[Date]),
    		ALLSELECTED('Table')
    	)
    	RETURN
    		CALCULATE(
    			SUM('Table'[Values]),
    			FILTER(
    				ALLSELECTED('Table'),
    				'Table'[Date] = _currentDate
    			)
    		) - CALCULATE(
    			SUM('Table'[Values]),
    			FILTER(
    				ALLSELECTED('Table'),
    				'Table'[Date] = _previousDate
    			)
    		)

    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.

     

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi LFM 

     

    Please try this:
    First of all, I create a set of sample:

    Then add a measure:

    Diff = 
    	VAR _currentDate = CALCULATE(
    		MAX('Table'[Date]),
    		ALLSELECTED('Table')
    	)
    	VAR _previousDate = CALCULATE(
    		MIN('Table'[Date]),
    		ALLSELECTED('Table')
    	)
    	RETURN
    		CALCULATE(
    			SUM('Table'[Values]),
    			FILTER(
    				ALLSELECTED('Table'),
    				'Table'[Date] = _currentDate
    			)
    		) - CALCULATE(
    			SUM('Table'[Values]),
    			FILTER(
    				ALLSELECTED('Table'),
    				'Table'[Date] = _previousDate
    			)
    		)

    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.