Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
p-cantu
Regular Visitor

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

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @p-cantu ,

 

I suggest you to create Dimtables to help calculation.

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

Data model:

vrzhoumsft_0-1695364635421.png

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.

vrzhoumsft_1-1695365145814.png

 

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.

 

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @p-cantu ,

 

I suggest you to create Dimtables to help calculation.

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

Data model:

vrzhoumsft_0-1695364635421.png

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.

vrzhoumsft_1-1695365145814.png

 

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.

 

Thank you Rico Zhou

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.