Forum Discussion

J_R_Cribb's avatar
J_R_Cribb
Icon for Helper I rankHelper I
10 years ago
Solved

Can't show values under all Date Columns?! Help Please

I am trying to create a running stock total for a number of products over time. I am using two data values (qty), the first is associated with a date (Incoming deliveries), the second is a current st...
  • v-haibl-msft's avatar
    v-haibl-msft
    10 years ago

    J_R_Cribb

     

    If there are no incoming deliveries, the product data will not exist for that week in your dataset, right?

    In following test dataset, there is no incoming deliveries for “-62901” on 3/14, 3/28, 3/29 and 4/4.

    We can first create a new table with following formula. Relate this new table with stock table using product.

    FullTable = 
    GENERATE (
        SUMMARIZECOLUMNS ( Table2[Product] ),
        SUMMARIZECOLUMNS ( Table2[Date] )
    )

    Then create WeekNum column and Quantity column in this new table.

    WeekNum =
    WEEKNUM ( FullTable[Date] )
    Quantity = 
    CALCULATE (
        SUM ( Table2[Quantity] ),
        FILTER (
            Table2,
            Table2[Date] = FullTable[Date]
                && Table2[Product] = FullTable[Product]
        )
    )

    At last, create a measure with following formula. I’ve also upload my .pbix file here for reference.

    LastNoBlankTotal = 
    VAR LastNoBlankWeek =
        CALCULATE (
            MAX ( FullTable[WeekNum] ),
            FILTER (
                ALL ( FullTable ),
                FullTable[WeekNum] < MAX ( FullTable[WeekNum] )
                    && FullTable[Quantity] <> BLANK ()
            ),
            VALUES ( Table1[stp_product] )
        )
    RETURN
        (
            IF (
                [Incoming Qty] = BLANK (),
                [Stock Qty]
                    + CALCULATE ( [Incoming Qty], FullTable[WeekNum] = LastNoBlankWeek ),
                [Rolling Total]
            )
    )

     

    Best Regards,

    Herbert