Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Avg Days on the Shelf

How could I calculate the avg days on the shelf from a table like this (rows with PO number is receiving, the ones with SO number are shipments) The way I approached this, I calculated the ave...
  • v-yueyunzh-msft's avatar
    4 years ago

    Hi, Anonymous 

    According to your description, you want to judge whether all the things of a product have been shipped according to the [qty] field and. If the delivery is completed, the number of days between [date] and today () is taken; if the delivery is not completed, the number of days between the current [date] and the date value of the largest so number is taken. Right?

    Here are the steps you can follow:

    (1)This is my test data:

     

    (2)We can create a calculated column : “Days Since”

    Days Since =
    VAR _current_id = 'Table'[Product ID]
    VAR _current_PO = 'Table'[PO Number]
    VAR _current_SO = 'Table'[SO Number]
    VAR _pro_PO =
        SUMX (
            FILTER (
                'Table',
                'Table'[Product ID] = _current_id
                    && 'Table'[PO Number] <> BLANK ()
            ),
            [QTY]
        )
    VAR _pro_SO =
        SUMX (
            FILTER (
                'Table',
                'Table'[Product ID] = _current_id
                    && 'Table'[SO Number] <> BLANK ()
            ),
            [QTY]
        )
    VAR _pro_max_SO =
        MAXX (
            FILTER (
                'Table',
                'Table'[Product ID] = _current_id
                    && 'Table'[SO Number] <> BLANK ()
            ),
            [Date]
        )
    RETURN
        IF (
            'Table'[PO Number] = BLANK (),
            DATEDIFF ( 'Table'[Date], TODAY (), DAY ),
            IF (
                _pro_PO = _pro_SO,
                DATEDIFF ( 'Table'[Date], TODAY (), DAY ),
                DATEDIFF ( 'Table'[Date], _pro_max_SO, DAY )
            )
        )
    

     

    (3)Then we can meet your need , the result is as follow:

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly