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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Mike921
New Member

How to calculate Future Sales

Hi all, i hope someone can help me to understand to do same in Power Bi, actually in my Bi model use the follow table:
Calendar,

actual sales.

 

I calculate the variation between period and geometric average.

 

i try different way but without results, i hope someone can help me to resolve my problem.

 

Mike921_0-1709906796175.png

 

2 ACCEPTED SOLUTIONS

Hi Mike,

 

Ah, I see you're also filtering by product and your fact table doesn't have the date, only the YearWeek.

 

In that case, the below should work for your Forecast measure instead. (Mainly I've added a variable to capture the max date of the row in the visual.)

Forecast = 
VAR MaxDate = CALCULATE ( MAX ( 'Date'[Date] ), REMOVEFILTERS ( Preorder ) )
VAR AvgVariation = [Avg Variation]
VAR FirstActualSalesDate = CALCULATE ( FIRSTNONBLANK ( 'Date'[Date], [preorder] ), REMOVEFILTERS ( 'Date' ) )
VAR LastActualSalesDate = CALCULATE ( LASTNONBLANK ( 'Date'[Date], [preorder] ), REMOVEFILTERS ( 'Date' ) )
VAR LastActualSales = CALCULATE ( [preorder], REMOVEFILTERS ( 'Date' ), 'Date'[Date] = LastActualSalesDate )
VAR NumWeeksAfterLastActualSalesDate = DATEDIFF ( LastActualSalesDate, MaxDate, WEEK )
VAR Result = COALESCE ( [preorder], LastActualSales * (1 + [Avg Variation] ) ^ NumWeeksAfterLastActualSalesDate)

RETURN 
IF ( MaxDate >= FirstActualSalesDate, Result )

 

Something to consider in the future:

While the above measure works for your data model, I strongly encourage you to learn more about data modeling, so you can avoid many-to-many relationships in the future (and also write measures more easily!). For example, in your scenario where the preorders are captured at a weekly level, instead of capturing the WeekYear in the Preorder table, I would suggest having a WeekStart column instead for example. That way, you can have a one-to-many relationship instead.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

Mike,

 

Apologies, I made two subtle but important changes early on that I forgot to mention.

 

  • The Catalog to Preorder relationship should not be bi-directional. In general, relationships should only filter from dimensions (ie: Catalog) to facts (ie: Preorder).
  • Replace Preorder[Product] with Catalog[Product] in your product slicer. Again, in general, you should default to using columns from dimension tables in your slicers.

When you do, you should see the below:

 

Wilson__0-1710177839990.png

 

 

This free course on data modeling from SQLBI should be tremendously helpful for you if you will be working with Power BI and DAX (and data analysis in general!) often. I hope it is as beneficial for you as it was for me! 🙂


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

10 REPLIES 10
Mike921
New Member

THANKS FOR EVERYTHING and thanks for the course i start to study asap 🙂

Wilson_
Super User
Super User

Hi Mike,

 

It sounds like what you might be looking for is:

  1. To checks if there are actuals for the week of the year
  2. If a future period, multiply by a constant value (ie: the average variation) for every additional week in the future.

If so, the three measures (Sales Amount, Average Variation and Forecast) below might work:

 

Sales Amount = SUM ( 'Actual Sales'[Amount] )
Average Variation = ???

Forecast =
VAR AvgVariation = [Average Variation]
VAR LastActualSalesDate = LASTNONBLANKVALUE ( Calendar[Date], [Sales Amount] )
VAR LastActualSales = CALCULATE ( [Sales Amount], LastActualSalesDate )
VAR NumWeeksAfterLastActualSalesDate = DATEDIFF ( LastActualSalesDate, MAX ( Calendar[Date] ), WEEK )

RETURN
COALESCE ( [Sales Amount], LastActualSales * (1 + [Average Variation] ) ^ NumWeeksAfterLastActualSalesDate

 

Note: Fill in your own average variation calculation for the Average Variation measure; I'm not entirely following the variation column or the average variation of 20.19% you're showing. If this doesn't work, I may not be picturing your data in my head correctly. It might help if you created a mock sample pbix file and linked to it here so I can play with it and send it back to you. (If you're not sure how to do that, please check out the pinned thread in this forum.)

----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi Wilson, how are you? thanks for the help i try to adapt your dax to my report but maybe i do something wrong. Follow the link with my pbix, last thing i need calculate the future sales from last data preorder to release week for the product i filter. Documenti

Hi Mike,

 

Ah, I see you're also filtering by product and your fact table doesn't have the date, only the YearWeek.

 

In that case, the below should work for your Forecast measure instead. (Mainly I've added a variable to capture the max date of the row in the visual.)

Forecast = 
VAR MaxDate = CALCULATE ( MAX ( 'Date'[Date] ), REMOVEFILTERS ( Preorder ) )
VAR AvgVariation = [Avg Variation]
VAR FirstActualSalesDate = CALCULATE ( FIRSTNONBLANK ( 'Date'[Date], [preorder] ), REMOVEFILTERS ( 'Date' ) )
VAR LastActualSalesDate = CALCULATE ( LASTNONBLANK ( 'Date'[Date], [preorder] ), REMOVEFILTERS ( 'Date' ) )
VAR LastActualSales = CALCULATE ( [preorder], REMOVEFILTERS ( 'Date' ), 'Date'[Date] = LastActualSalesDate )
VAR NumWeeksAfterLastActualSalesDate = DATEDIFF ( LastActualSalesDate, MaxDate, WEEK )
VAR Result = COALESCE ( [preorder], LastActualSales * (1 + [Avg Variation] ) ^ NumWeeksAfterLastActualSalesDate)

RETURN 
IF ( MaxDate >= FirstActualSalesDate, Result )

 

Something to consider in the future:

While the above measure works for your data model, I strongly encourage you to learn more about data modeling, so you can avoid many-to-many relationships in the future (and also write measures more easily!). For example, in your scenario where the preorders are captured at a weekly level, instead of capturing the WeekYear in the Preorder table, I would suggest having a WeekStart column instead for example. That way, you can have a one-to-many relationship instead.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi Wilson, thx a lot i try to apply your solution to my original pbix and came back to you with a feedback. in the future if i need any advice can text you directly? 

Mike,

 
I forgot to mention that one of the other things I changed in your sample file is your date table. It currently only goes through 2024/1/31. Expand that out to the rest of the year. Otherwise, there are no future weeks in your data model to forecast to. That should allow you to forecast out further.
 
To your other question of whether you can message me directly for help in the future, thank you for asking. However, the answer is no. If I'm helping somebody for free, I want it to be publicly so that other members of the community can also benefit from the discussion if they run into the same issue in the future. Thank you for understanding! 🙂


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thx a lot for the help you are a master of Bi, i expanded the calendar to reach end of year 2024, but forecast the data from the last preorder to max calendar date, i need to stop the forecast when the date reach the relase date. how can i do? update. i edit the sample i think i'm near the solution but something not work properly. sample.pbix

Mike,

 

Try this updated forecast measure:

 

Forecast = 
VAR MaxDate = CALCULATE ( MAX ( 'Date'[Date] ), REMOVEFILTERS ( Preorder ) )
VAR MaxWeekYear = CALCULATE ( MAX ( 'Date'[YearWeek] ), REMOVEFILTERS ( Preorder ) )
VAR ReleaseWeek = INT ( [release week] )
VAR AvgVariation = [Avg Variation]
VAR FirstActualSalesDate = CALCULATE ( FIRSTNONBLANK ( 'Date'[Date], [preorder] ), REMOVEFILTERS ( 'Date' ) )
VAR LastActualSalesDate = CALCULATE ( LASTNONBLANK ( 'Date'[Date], [preorder] ), REMOVEFILTERS ( 'Date' ) )
VAR LastActualSales = CALCULATE ( [preorder], REMOVEFILTERS ( 'Date' ), 'Date'[Date] = LastActualSalesDate )
VAR NumWeeksAfterLastActualSalesDate = DATEDIFF ( LastActualSalesDate, MaxDate, WEEK )
VAR Result = COALESCE ( [preorder], LastActualSales * (1 + [Avg Variation] ) ^ NumWeeksAfterLastActualSalesDate)
VAR Display = IF ( MaxDate >= FirstActualSalesDate && MaxWeekYear <= ReleaseWeek, Result )

RETURN Display

 

 

Added another variable to calculate the selected WeekYear and a variable to calculate the release week. Note: I also had to convert release week to an integer because Catalog[Release Week] is a text field. For multiple reasons, this should probably be an integer field.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi wilson, i apply your dax but get stuck, forecast 2 it's your old dax, forecast is the new one.
Sorry Wilson, please don't hate me.... follow the pbix. sample.pbix

Mike921_0-1710174038667.png

 

Mike,

 

Apologies, I made two subtle but important changes early on that I forgot to mention.

 

  • The Catalog to Preorder relationship should not be bi-directional. In general, relationships should only filter from dimensions (ie: Catalog) to facts (ie: Preorder).
  • Replace Preorder[Product] with Catalog[Product] in your product slicer. Again, in general, you should default to using columns from dimension tables in your slicers.

When you do, you should see the below:

 

Wilson__0-1710177839990.png

 

 

This free course on data modeling from SQLBI should be tremendously helpful for you if you will be working with Power BI and DAX (and data analysis in general!) often. I hope it is as beneficial for you as it was for me! 🙂


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.