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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Talal141218
Helper III
Helper III

Cumulative sales previous year in Stock running

Hi Pofis, 

I am still struggling to calculate the running stock - I've almost achived ir , but i am still having  trouble calculating the cumulative sales for the  pervious year, please find my formula  and a screen shot to clarify the issue : 

Purchases up to date = CALCULATE(Fact_PurchOrderLine[CM_PurchOrderline_Qty_piec], Fact_PurchOrderLine[PurchOrderlineDateEstimatedArrival] <= MAX(Dim_DateDue[DateDue_NK]) && Fact_PurchOrderLine[PurchOrderlineDateEstimatedArrival] >= TODAY()).
Sales up to date = CALCULATE([CM_SalesOrderLine_CountOpen],  Fact_SalesOrderLine[ShippingDateRequested_NK] <= MAX(Dim_DateDue[DateDue_NK]) && Fact_SalesOrderLine[ShippingDateRequested_NK] >= TODAY())
Absatz VJ =
VAR LastYear =  TREATAS(SAMEPERIODLASTYEAR(VALUES(Dim_DateDue[DateDue_NK])), Dim_SalesOrderPackageDate[Date_NK])

  VAR SalesLY = CALCULATE(Fact_SalesOrderPackage[CM_Fact_SalesOrderPackage_ItemQuantity],LastYear)
  RETURN IF(SalesLY = BLANK(), BLANK(), CALCULATE(SalesLY, FILTER(ALLSELECTED(Dim_DateDue[DateDue_NK]), Dim_DateDue[DateDue_NK] <= MAX(Dim_DateDue[DateDue_NK]))))
Running Stock =

VAR Stock = [Lager Bestand exlu.Rev.]
VAR Incoming = Fact_PurchOrderLine[Purchases up to date]

VAR sales =  Fact_PurchOrderLine[Sales up to date]
VAR Absatzplan = [Absatz VJ]

RETURN
    Stock + Incoming - sales - Absatzplan
Talal141218_0-1762169791445.png

Thanks in Advance 

 

 

1 ACCEPTED SOLUTION

Hi @Talal141218 ,

 

Explore Visual calcualtions they can help you to get values from the same visual without any complex logic.

https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-visual-calculations-overview 

 

Please give kudos or mark it as solution once confirmed.

 

Thanks and regards,

Praful

View solution in original post

7 REPLIES 7
v-pgoloju
Community Support
Community Support

Hi @Talal141218,

 

Just following up to see if the Response provided by community members were helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.

 

Best regards,
Prasanna Kumar

v-pgoloju
Community Support
Community Support

Hi @Talal141218,

 

Thank you for reaching out to the Microsoft Fabric Forum Community, and special thanks to @Praful_Potphode and @parry2k  for prompt and helpful responses.

Just following up to see if the Response provided by community members were helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.

 

Best regards,
Prasanna Kumar

 

Praful_Potphode
Super User
Super User

Hi @Talal141218 

based on the snapshot , i could not undertand the desired output .can you clarify that to me?

Also on the intial analysis , it looks like there is an issue in Absatz VJ Measure.can your break the measure into two parts i.e. one base measure and one time intelligence measure.try creating below 3 measures and let me know.

Base Sales Count = SUM(Fact_SalesOrderPackage[CM_Fact_SalesOrderPackage_ItemQuantity])
Absatz VJ (Cumulative LY) =
VAR MaxDate = MAX(Dim_DateDue[DateDue_NK])
VAR DatesLY =
    // 1. Get the range of dates from the start of the year
    //    UP TO the date one year PRIOR to the current MaxDate.
    DATESBETWEEN(
        Dim_DateDue[DateDue_NK],
        STARTOFYEAR(SAMEPERIODLASTYEAR(Dim_DateDue[DateDue_NK])),
        SAMEPERIODLASTYEAR(MaxDate)
    )
RETURN
    // 2. Calculate the total sales within that specific date range (DatesLY)
    CALCULATE(
        [Base Sales Count], // Use your simple sales count measure here
        DatesLY,
        REMOVEFILTERS(Dim_DateDue) // Clear all existing date filters to apply the custom range
    )
Running Stock =
VAR Stock = [Lager Bestand exlu.Rev.]
VAR Incoming = [Purchases up to date] // Needs to be a measure, not a column reference
VAR Sales = [Sales up to date]        // Needs to be a measure, not a column reference
VAR CumulativeSalesLY = [Absatz VJ (Cumulative LY)] // The FIXED cumulative measure

RETURN
    Stock + Incoming - Sales - CumulativeSalesLY

try these measures and if it doesn't work please explain the desired outcome and how its supposed to filter.

 

Please give kudos or mark it as solution once confirmed.

 

Thanks and Regards,

Praful

 

@parry2k  I realy appreciate your response, but unfortunately your measure didn't work " I can't use Maxdate as a date in Function sameperiodlastyear. I want to ask you now  another soultion. Forthermore: I want for make the ending stock  of week , quarter, month as  openning stock for next week, quarter etc.. and dedect it from the sales or purchase in the same period, week, quarter .. As you see in the screeen shot below : 

Talal141218_0-1762425939621.png

Can you help in this issue ? Thanks in Advance 🙂

Hi @Talal141218 ,

 

Explore Visual calcualtions they can help you to get values from the same visual without any complex logic.

https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-visual-calculations-overview 

 

Please give kudos or mark it as solution once confirmed.

 

Thanks and regards,

Praful

Talal141218
Helper III
Helper III

@parry2k  Thanks for your reply, but unfortunatly the video did't help me in this issue. 

parry2k
Super User
Super User

@Talal141218 I did a video on something similar a long time ago, hope it gives you some clue 

 

On what date product will run out of stock - a use case of CROSSJOIN in Power BI



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.