Recently, I worked on a project where the client provided daily sales data in Excel. Alongside the actual sales figures, they had a forecasted sales amount for each week and month. The task was to create a dashboard in Power BI that would display monthly sales, the monthly forecast, and the difference between actuals and forecasts. Additionally, the client wanted to track these comparisons both by week and by month, which introduced a unique challenge: how to incorporate the monthly forecast into the daily and weekly breakdowns.
To achieve this, I created a separate forecast table similar to a calendar table. This table, named “Forecast Amount,” held the monthly forecast amounts for each month of the year. Then, I divided the monthly forecast by the number of days in each month to generate a daily forecast. By aggregating this daily forecast, I could easily analyze both weekly and monthly performance in Power BI, allowing for a seamless comparison between actual sales and forecasted amounts.
A Possible Improvement
One way to enhance this approach could be to automate the forecast breakdown by using Power Query. Power Query can dynamically calculate the daily forecast based on the monthly forecast, updating automatically if the monthly forecast values change. This way, you could avoid manually updating the forecast table for each month and allow the data model to be more flexible and responsive to changes in forecast figures.
Here’s a detailed breakdown of the steps for setting up a dynamic monthly and weekly sales forecast in Power BI using Power Query and DAX.
Step 1: Import Sales Data and Forecast Data
- Import Sales Data: Load your daily sales data from the Excel file into Power BI, ensuring that each row contains at least a date and a sales amount.
- Import Forecast Data: Load the forecast data. If the forecast is provided monthly (one row per month with the forecasted amount), it should contain:
- Month and Year
- Monthly Forecast Amount
Step 2: Create a Date Table
- Go to Modeling > New Table and create a calendar table if you don’t already have one. DAXCopy code
DateTable = CALENDAR(MIN(Sales[Date]), MAX(Sales[Date]))
- Add calculated columns for Month, Year, Week Number, and Day to enable monthly and weekly aggregations.
Step 3: Transform Monthly Forecast into Daily Forecast
- In Power Query, go to the forecast data table and perform the following steps:
- Expand to Daily Level: Duplicate each row for the number of days in the month so that each month’s forecast can be spread across individual days.
- Add Column > Custom Column: Use a formula to generate a list of dates based on each month, e.g.,
List.Dates
. - Expand this list to create a row for each date.
- Add Column > Custom Column: Use a formula to generate a list of dates based on each month, e.g.,
- Divide Monthly Forecast by Days in Month:
- Create a custom column that divides the monthly forecast amount by the number of days in the month (e.g.,
ForecastAmount / DaysInMonth
). - This gives a daily forecast amount for each day of the month.
- Create a custom column that divides the monthly forecast amount by the number of days in the month (e.g.,
- Expand to Daily Level: Duplicate each row for the number of days in the month so that each month’s forecast can be spread across individual days.
- Load the transformed forecast table back into Power BI.
Step 4: Link Forecast Table to Date Table
- In the Model View, create a relationship between the Date column in your DateTable and the date column in your Forecast table.
- Make sure you have relationships in place between Sales and DateTable as well, enabling comparisons on common date values.
Step 5: Create Measures for Forecast and Actual Sales Comparison
- Monthly Forecast:
- Create a measure to calculate the monthly forecast sum:DAX code
MonthlyForecast = SUM(Forecast[DailyForecastAmount])
- Create a measure to calculate the monthly forecast sum:DAX code
- Actual Sales:
- Create a measure for the actual monthly sales: DAX code
MonthlySales = SUM(Sales[SalesAmount])
- Create a measure for the actual monthly sales: DAX code
- Difference:
- Calculate the variance between the forecast and actual sales:DAXCopy code
MonthlyVariance = [MonthlySales] - [MonthlyForecast]
- Calculate the variance between the forecast and actual sales:DAXCopy code
- Weekly Forecast and Actual:
- If weekly comparisons are needed, create similar measures, using
SUMX
orCALCULATE
withWEEKNUM
to filter and aggregate data by week.
- If weekly comparisons are needed, create similar measures, using
Step 6: Build the Dashboard
- Use line and bar charts to display actual sales and forecasted sales for each month.
- Add a variance column chart to visualize the difference between actual and forecasted values.
- Add slicers for month and year, allowing users to drill down to specific periods.
Automate Updates
When using Power Query, your forecast table will automatically update if the client updates the monthly forecast values in the Excel sheet. This avoids manual adjustments and keeps your dashboard flexible.
By following these steps, you’ll have a robust setup in Power BI to dynamically track monthly and weekly performance against forecasted sales, and your dashboard will remain up-to-date as new forecast data is provided.