Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Continous line chart, previous value for blank data

Hello, 

 

With the following data, I want to show on a continuous line chart the value per SKU during september. It's a stock value so basicaly, between the 25/09 and 29/09 for the SKU A, I want the value to remain at 8 (before a drop to 3 the 29/09).

So I don't want blank value to be 0, I would like to get the previous value if blank.

DateSKUIndexValue
29-septA13
25-septA28
19-septB39
18-septA41
06-septB53
01-septB60


Thank you for your help !! Best regards
Marie

  • Anonymous's avatar
    Anonymous
    2 years ago

    HI Anonymous,

    Did these blank parts real include in your table records? If that is the case, you can check the current value if it equal to zero and use expression to look up the previous data values.
    If the blank part means record not existed in table, you may need to use a new calendar table date field as axis and write measure expression to lookup current table to get previous result.

    formula =
    VAR currDate =
        MAX ( DateTable[Date] )
    VAR exist =
        CALCULATE (
            COUNTROWS ( Table1 ),
            FILTER ( ALLSELECTED ( Table1 ), [Date] = currDate ),
            VALUES ( Table1[SKU] )
        )
    VAR prevDate =
        CALCULATE (
            MAX ( Table1[Date] ),
            FILTER ( ALLSELECTED ( Table1 ), [Date] < currDate )
        )
    RETURN
        IF (
            exist > 0,
            SUM ( Table1[Value] ),
            CALCULATE (
                SUM ( Table1[Value] ),
                FILTER ( ALLSELECTED ( Table1 ), [Date] = prevDate ),
                VALUES ( Table1[SKU] )
            )
        )
    

    Regards,

    Xiaoxin Sheng

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Any help ? thank

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous,

    Did these blank parts real include in your table records? If that is the case, you can check the current value if it equal to zero and use expression to look up the previous data values.
    If the blank part means record not existed in table, you may need to use a new calendar table date field as axis and write measure expression to lookup current table to get previous result.

    formula =
    VAR currDate =
        MAX ( DateTable[Date] )
    VAR exist =
        CALCULATE (
            COUNTROWS ( Table1 ),
            FILTER ( ALLSELECTED ( Table1 ), [Date] = currDate ),
            VALUES ( Table1[SKU] )
        )
    VAR prevDate =
        CALCULATE (
            MAX ( Table1[Date] ),
            FILTER ( ALLSELECTED ( Table1 ), [Date] < currDate )
        )
    RETURN
        IF (
            exist > 0,
            SUM ( Table1[Value] ),
            CALCULATE (
                SUM ( Table1[Value] ),
                FILTER ( ALLSELECTED ( Table1 ), [Date] = prevDate ),
                VALUES ( Table1[SKU] )
            )
        )
    

    Regards,

    Xiaoxin Sheng