March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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.
Solved! Go to Solution.
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?)
Proud to be a Super User! | |
Mike,
Apologies, I made two subtle but important changes early on that I forgot to mention.
When you do, you should see the below:
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?)
Proud to be a Super User! | |
THANKS FOR EVERYTHING and thanks for the course i start to study asap 🙂
Hi Mike,
It sounds like what you might be looking for is:
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?)
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?)
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,
----------------------------------
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?)
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?)
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
Mike,
Apologies, I made two subtle but important changes early on that I forgot to mention.
When you do, you should see the below:
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?)
Proud to be a Super User! | |
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
91 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
72 | |
68 |