Forum Discussion

netanel's avatar
netanel
Icon for Post Prodigy rankPost Prodigy
4 years ago
Solved

Dont Bring Blank

Hi All!   i have this Measure: Net USD AVG = CALCULATE( DIVIDE( SUM( 'DB 2022'[Net USD] ), COUNTROWS( 'Date' ) ), keepfilters( 'Date'[Date] < TODAY()))   My data does not always reach the ...
  • bcdobbs's avatar
    bcdobbs
    4 years ago

    This is a better measure replacing the >0

    Net USD AVG = 
    
    VAR NumDays=
        CALCULATE (
            DISTINCTCOUNT ('DB 2022'[Date] ),
            KEEPFILTERS( 'Date'[Date] < TODAY() ),
            NOT ISBLANK ( 'DB 2022'[Net USD] ),
            REMOVEFILTERS ( 'SORT GL' )
        )
    
    VAR SumNet =
        CALCULATE (
            SUM ( 'DB 2022'[Net USD] ),
            KEEPFILTERS( 'Date'[Date] < TODAY() )
            )
    
    RETURN DIVIDE (SumNet, NumDays)

     

    In your 'DB 2022' table you have rows for every date whether there is a value for [Net USD] or not. My original measure went for >0 just to make sure it was picking days with values. The above version is better in case you did get negative values.

     

    The reason it wasn't working when the sort field is added in is there are days in each month when there are no values for that particular sort. It was therefore not including that day in the division for that section. By using the REMOVEFILTERS ( 'Sort GL' ) it says no matter what sort is selected divided by the total number of days in the whole period.