Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Plot zero when there is no data in line chart

Month = month('Shiptracking history'[Date]) year = year('Shiptracking history'[Date]) MovingAverage = calculate(sum('Shiptracking history'[Production+0]),DATESINPERIOD('Shiptracking history'[Date],...
  • Sean's avatar
    Sean
    8 years ago

    And same for the MovingAverage

    MovingAverage =
    CALCULATE (
        SUM ( 'Shiptracking history'[Production] ),
        DATESINPERIOD (
            'Shiptracking history'[Date],
            LASTDATE ( 'Shiptracking history'[Date] ),
            -10,
            DAY
        )
    )
        / 10
        + 0

    Hope this helps! :smileyhappy:

    Works with the sample data!

  • Sean's avatar
    Sean
    8 years ago

    Okay hopefully this will solve it!

    First things first go back to the Query Editor

    1) Select the Date Column - Add Column tab - Time dropdown/button - select Time Only

    2) with Date Column still selected - Date dropdown/button - select Date Only

    3) Rename the original Date Column - Time and Date (or as you wish) and Date.1 rename just Date

    4) Home tab - Close and Apply

    Then

    5) Create a Calendar Table - Modeling tab - click New Table

    Calendar Table = CALENDAR ( MIN('Table'[Date]), MAX('Table'[Date]) )

    6) Set up the Relationship between the 2 tables based on the 2 date columns

    7) And this is your New Moving Average Measure

    MovingAverage Measure Calendar =
    CALCULATE (
        SUM ( 'Table'[Production] ),
        DATESINPERIOD (
            'Calendar Table'[Date],
            LASTDATE ( 'Calendar Table'[Date] ),
            -10,
            DAY
        )
    )
        / 10
        + 0

    8) You can add a "Between" Date Slicer if you wish just make sure you use the Date from the Calendar

    9) Create a Line Chart - add the Date from the Calendar to the axis and deselect the Date Hierarchy if it defaults to it

    10) Add the New Moving Average to the Values

    Tell me this works! :smileyhappy:

  • Sean's avatar
    Sean
    7 years ago

    Wrap the calculation in CALCULATE to have Row Context

    Production Measure New = 
    SUMX (
        FILTER ( 'Calendar Table', 'Calendar Table'[Date] <= TODAY () ),
        CALCULATE ( SUM ( 'Table'[Production] ) + 0 )
    )