Forum Discussion

wdbirch19's avatar
wdbirch19
New Member
2 years ago
Solved

Plotting difference in value between two date ranges

Hi PowerBI community!

 

I've been going round in circles for a couple of days trying to figure this one out so I decided to reach out for some help.

 

I'm working with some time series data (example below - my real data is a bit more complex) and want to be able to plot the difference between the first and last value for a given day range. However, I want this value to be on a bar chart that is updated depending on a filter that is on the page. 

 

For example for the data below if I am sepecting the range Day 1 > Day 4 then the value would be 5.7-1.5=4.2; if I am selecting the range Day 3 > Day 5 then it would be 3.2-1.7=1.5.

 

DayValue
11.5
22.4
31.7
45.7
53.2
6

4.8

7

5.3

86.9

 

I can easily calculate a difference in DAX between each value and the value on Day 0, but this doesn't update with filters etc. 

 

Any help with this would be hugely appreciated!

  • Hi wdbirch19 

     

    Would something like this help?

     

    zMeasure = 
    VAR _StartDate = MIN( 'Table1'[Date] )
    VAR _EndDate = MAX( 'Table1'[Date] )
    VAR _StartVal = 
        CALCULATE(
            MAX( 'Table1'[Value] ),
            'Table1'[Date] = _StartDate
        )
    VAR _EndVal = 
        CALCULATE(
            MAX( 'Table1'[Value] ),
            'Table1'[Date] = _EndDate
        )
    VAR _Diff = _EndVal - _StartVal
    RETURN
        _Diff
    
    OR
    
    zMeasure 2 = 
    CALCULATE(
        MAX( 'Table1'[Value] ),
        'Table1'[Date] = MAX( 'Table1'[Date] )
    )
    -
    CALCULATE(
        MAX( 'Table1'[Value] ),
        'Table1'[Date] = MIN( 'Table1'[Date] )
    )
    

     

     

    I hope this helps.

2 Replies

  • Hi wdbirch19 

     

    Would something like this help?

     

    zMeasure = 
    VAR _StartDate = MIN( 'Table1'[Date] )
    VAR _EndDate = MAX( 'Table1'[Date] )
    VAR _StartVal = 
        CALCULATE(
            MAX( 'Table1'[Value] ),
            'Table1'[Date] = _StartDate
        )
    VAR _EndVal = 
        CALCULATE(
            MAX( 'Table1'[Value] ),
            'Table1'[Date] = _EndDate
        )
    VAR _Diff = _EndVal - _StartVal
    RETURN
        _Diff
    
    OR
    
    zMeasure 2 = 
    CALCULATE(
        MAX( 'Table1'[Value] ),
        'Table1'[Date] = MAX( 'Table1'[Date] )
    )
    -
    CALCULATE(
        MAX( 'Table1'[Value] ),
        'Table1'[Date] = MIN( 'Table1'[Date] )
    )
    

     

     

    I hope this helps.