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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
lmcpinto
Frequent Visitor

Calculating stock pendancy

Hi everyone!

 

Hi need help with a formula to calculate the amount of days a product was in stock. 

 

So i use a formula to calculate the stock so i know in a line chart how much there was based on a created date and closed date. I have something like this:

Stock of Open Complaints =
VAR OpeningStock = CALCULATE(COUNTROWS('Reclamações'), FILTER('Reclamações''Reclamações'[DataCriacao] <= MAX('Calendário'[Data])))
VAR NewComplaints = CALCULATE(COUNTROWS('Reclamações'), FILTER('Reclamações''Reclamações'[DataCriacao] > MAX('Calendário'[Data]) && 'Reclamações'[DataCriacao] <= MAX('Calendário'[Data])))
VAR ClosedComplaints = CALCULATE(COUNTROWS('Reclamações'), FILTER('Reclamações''Reclamações'[DataEncerramento] > MIN('Calendário'[data]) && 'Reclamações'[DataEncerramento] <= MAX('Calendário'[Data])))
RETURN OpeningStock + NewComplaints - ClosedComplaints
 
now i want to know the average time every reclamacao was on stock. Having example:

I know that something has datacriacao = 1/01/2023 and dataencerramento 1/03/2022. It should contribute to the average of january with one month in stock, in february with two months on stock. the time in stock should change with the time selected.
 
 
 StockAverage Stock Pendency
Jan3000x
Feb4000x
Mar5000x
Apr3000x
May2000x
June5000x
July6000x

......

 

 

an example if only one complaint existed

 

Data criacaodata encerramento(closure)time in stock end of januarytime in stock end of february
1/01/20211/03/202230 days

60 days

 

 

 

and then i want to calculate the average time in stock (pendancy) for every month and year. in this case it would be 30 days in january and 60 days in february

 

thank you so much!

2 REPLIES 2
lmcpinto
Frequent Visitor

@Anonymous  i dont think it is the correct measure. i have two tables, calendario and reclamacoes. the first one has all the dates until today and a calculated column to calculate the stock based on table reclamacoes. on the other table i have an id, date of creation and date of encerramento. this means that if a reclamacao had the data encerramento after a certain date, it was on stock on wvery dates until the encerramento. 

 

What i want to calculate is the average time a reclamacao is on stock for every date in the calendar.

 

table reclamacoes

lmcpinto_0-1681829019231.png

 table calendario

lmcpinto_1-1681829053821.png

 

thanks so much in advance!

Anonymous
Not applicable

Hi @lmcpinto ,

 

Due to I don't know your data model, here I create a sample to have a test.

Table:

vrzhoumsft_0-1681807183920.png

Table(2):

vrzhoumsft_1-1681807200011.png

Measure:

Average Stock Pendency = 
VAR _DATE =
    ADDCOLUMNS (
        CALENDAR (
            MIN ( 'Table (2)'[Data criacao] ),
            MAX ( 'Table (2)'[data encerramento(closure)] )
        ),
        "Year", YEAR ( [Date] ),
        "Month", FORMAT ( [Date], "MMM" ),
        "MonthSort", MONTH ( [Date] )
    )
VAR _DAY =
    COUNTAX (
        FILTER (
            _DATE,
            [Year] = MAX ( 'Table'[Year] )
                && [MonthSort] <= MAX ( 'Table'[MonthSort] )
        ),
        [Date]
    )
RETURN
    DIVIDE ( SUM ( 'Table'[Stock] ), _DAY )

Result is as below.

vrzhoumsft_2-1681807254280.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.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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