Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Missing Stock information data

Hi, 

 

I am getting some data regarding the stock information with the different distributors where I sell some products. Unfortunately, is over 15,000 different products and sometimes, some data of one distributor is missing. I would like to be able to pull the last available data in order not to show a reduction in the stock unless there is really a reduction in stock reported. 

 

The data looks like this...

DateProduct DistributorStock info
01/05/2023Brushesa10
01/05/2023Brushesb15
01/05/2023Brushesc8
02/05/2023Brushesa10
02/05/2023Brushesc8
03/05/2023Brushesa10
03/05/2023Brushesc8
04/05/2023Brushesa10
04/05/2023Brushesb

15

TotalBrushes 

94

 

The final and correct data is: 
 

DateProduct DistributorStock info
01/05/2023Brushesa10
01/05/2023Brushesb15
01/05/2023Brushesc8
02/05/2023Brushesa10
02/05/2023Brushesb15
02/05/2023Brushesc8
03/05/2023Brushesa10
03/05/2023Brushesb15
03/05/2023Brushesc8
04/05/2023Brushesa10
04/05/2023Brushesb15
04/05/2023Brushesc8
TotalBrushes 132


This can help me to identify distributors that require more product because they are running low even before the distributors notice. 

Any help will be appreciated and thank you for the support

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

     

    I suggest you to create Dimtables to help calculation.

    DimDate = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))
    DimDistributor = VALUES('Table'[Distributor])

    Data model:

    Measure:

    Measure = 
    VAR _CORSSJOIN =
        GENERATE (
            CALCULATETABLE (
                VALUES ( DimDistributor[Distributor] ),
                ALLSELECTED ( DimDistributor )
            ),
            CALCULATETABLE ( VALUES ( DimDate[Date] ), ALLSELECTED ( DimDate ) )
        )
    VAR _ADD =
        ADDCOLUMNS ( _CORSSJOIN, "Stock", CALCULATE ( SUM ( 'Table'[Stock info] ) ) )
    VAR _ADD1 =
        ADDCOLUMNS (
            _ADD,
            "Filldown",
                VAR _MAXDATE =
                    MAXX (
                        FILTER (
                            _ADD,
                            [Distributor] = EARLIER ( [Distributor] )
                                && [Date] <= EARLIER ( [Date] )
                                && [Stock] <> BLANK ()
                        ),
                        [Date]
                    )
                VAR _SUM =
                    SUMX (
                        FILTER ( _ADD, [Distributor] = EARLIER ( [Distributor] ) && [Date] = _MAXDATE ),
                        [Stock]
                    )
                RETURN
                    _SUM
        )
    RETURN
        IF (
            HASONEVALUE ( DimDistributor[Distributor] ),
            SUMX (
                FILTER (
                    _ADD1,
                    [Distributor] = MAX ( DimDistributor[Distributor] )
                        && [Date] = MAX ( DimDate[Date] )
                ),
                [Filldown]
            ),
            SUMX ( _ADD1, [Filldown] )
        )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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

     

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    I suggest you to create Dimtables to help calculation.

    DimDate = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))
    DimDistributor = VALUES('Table'[Distributor])

    Data model:

    Measure:

    Measure = 
    VAR _CORSSJOIN =
        GENERATE (
            CALCULATETABLE (
                VALUES ( DimDistributor[Distributor] ),
                ALLSELECTED ( DimDistributor )
            ),
            CALCULATETABLE ( VALUES ( DimDate[Date] ), ALLSELECTED ( DimDate ) )
        )
    VAR _ADD =
        ADDCOLUMNS ( _CORSSJOIN, "Stock", CALCULATE ( SUM ( 'Table'[Stock info] ) ) )
    VAR _ADD1 =
        ADDCOLUMNS (
            _ADD,
            "Filldown",
                VAR _MAXDATE =
                    MAXX (
                        FILTER (
                            _ADD,
                            [Distributor] = EARLIER ( [Distributor] )
                                && [Date] <= EARLIER ( [Date] )
                                && [Stock] <> BLANK ()
                        ),
                        [Date]
                    )
                VAR _SUM =
                    SUMX (
                        FILTER ( _ADD, [Distributor] = EARLIER ( [Distributor] ) && [Date] = _MAXDATE ),
                        [Stock]
                    )
                RETURN
                    _SUM
        )
    RETURN
        IF (
            HASONEVALUE ( DimDistributor[Distributor] ),
            SUMX (
                FILTER (
                    _ADD1,
                    [Distributor] = MAX ( DimDistributor[Distributor] )
                        && [Date] = MAX ( DimDate[Date] )
                ),
                [Filldown]
            ),
            SUMX ( _ADD1, [Filldown] )
        )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you Rico Zhou