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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Combine two Tables (Actual and Forecast) into third table

I have what seems to me like a complicated problem in Power BI and just want to see if this is possible because going out to look for another solution. I'm trying to combine information from two different tables into one table to show the current production path of a product with the forecasted pathway appended to the end. 

 

My actual results updated each day showing which production line was used and what the start and end date are. The end date of the final line is always listed as today (See Table 1 below). The forecast just shows the planned start and end dates for each line on the production path. 

 

What I'm looking to do is add the pathway from the forecast as additional rows in the Actuals data for the remaining days (Even if it's currently showing the product was somewhere other than the original forecasted plan -- We update the forecasts when we see divitations to create new forecasts). 

 

I was thinking I may need to use a union of some sort but wondered if someone has already done something similar. 

 

Thanks

 

Table 1 - Actuals: 

NameStart DateEnd DateIDProduction Line
Product X10/1/201810/7/201811Line 1
Product X10/7/201810/17/201811Line 2
Product X10/17/201810/19/201811Line 4
Product X10/19/201811/20/201811Line 2
Product Y10/6/201810/16/201822Line 3
Product Y10/16/201811/20/201822Line 4

 

Table 2 - Forecast: 

 

NameStart DateEnd DateIDProduction Line
Product X10/1/201810/7/201811Line 1
Product X10/7/201810/17/201811Line 2
Product X10/17/201812/29/201811Line 4
Product Y10/6/201810/16/201822Line 3
Product Y10/16/201812/31/201822Line 4

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Looks good but I actually think I figured out a solution that produced the same table (Everything done in Power Query): 

 

1- I added the Type column to both tables (Actual or Forecast). 

2- In the forecast table I filtered the End Date to remove everything prior to today

 

= Table.SelectRows(#"Changed Type", each [End Date] >= Date.From(DateTime.LocalNow())  )

3- I removed the Start Date from the forecast and then added a custom Start Date column that is equal to Today's date:

 

 

= Table.AddColumn(#"Removed Columns", "Start Date", each DateTime.LocalNow())

4- Then I went back to the Actuals and appended the forecast. 

 

IDNameProduction LineStart DateEnd DateSource
11Product XLine 110/1/201810/7/2018Actual
11Product XLine 210/7/201810/17/2018Actual
11Product XLine 410/17/201810/19/2018Actual
11Product XLine 210/19/201811/20/2018Actual
22Product YLine 310/6/201810/16/2018Actual
22Product YLine 410/16/201811/20/2018Actual
11Product XLine 411/20/201812/29/2018Forecast
22Product YLine 411/20/201812/31/2018Forecast

 

 

Thanks for the help. I am curious is you did it much differently but seems rather close as I see you created a separate start date. 

 

 

 

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

 Recently i worked on the similar data structure for the construction business. Take look at this steps:

 

Actual:

Table.AddColumn(#"Changed Type", "Merged", each Text.Combine({[Name], Text.From([Start Date], "en-US"), Text.From([ID], "en-US"), [Production Line]}, ""), type text)

 

Forecast:

= Table.AddColumn(#"Renamed Columns", "Merged", each Text.Combine({[Name], Text.From([Start Date], "en-US"), Text.From([ID], "en-US"), [Production Line]}, ""), type text)

 

This way you can have a mutual calumn to create relationship between tables. I am assuming that only difference butween these tables is the End Date.

 

Please let me know how it goes for you.

 

Hasan

Anonymous
Not applicable

Thanks, but there are other differences. The production line could change between the actual and forecast, as we have reworks that could cause it to go back to another line for a bit and then jump back to the forecasted line. 

 

My goal right now is the just have the forecast append starting at the last day of the Actuals and then run through the end of the forecast. 

Anonymous
Not applicable

Here's how I tackled this.

 

1) Import both table into Power Query.  Added a Type column for each ( Actual or Forecast)

2) Used the append feature.  So  have a new table :

Appended table.png

 

From there, create a merged column of ID, Production Line, Start Date, End Date.

Sorted those by that Type column (ascending, so we have actuals above Forecast)

Then deleted the duplicates from the Merged Column

Removed the merged column (which is one of the coolest things that you can do in Power Query as whenever the tables are uploaded it will still use that column).

 

Final table:

Table.png

Anonymous
Not applicable

Hey Nick, 

 

Almost but not quite there, just appending and removing duplicates doesn't work because there is overlaping information that needs to be excluded. 

 

Example, Product X in the actuals was on Line 2 from 10/19 - 11/20. The forecast lists it as being on Line 4 from 10/17-10/29. I need that forecast to adjust to only consider information starting 11/20. So, it should go from Line 2 ending on 11/20 as shown in Actuals and then start Line 4 with a start date of 11/20 (Forecast). 

 

This is what is making this one so complicated. 

 

Capture.PNG

 

 

 

Anonymous
Not applicable

how does this look ? If good, ill type out what I did here

 

New Start Col:

Append with new start.png

Anonymous
Not applicable

Looks good but I actually think I figured out a solution that produced the same table (Everything done in Power Query): 

 

1- I added the Type column to both tables (Actual or Forecast). 

2- In the forecast table I filtered the End Date to remove everything prior to today

 

= Table.SelectRows(#"Changed Type", each [End Date] >= Date.From(DateTime.LocalNow())  )

3- I removed the Start Date from the forecast and then added a custom Start Date column that is equal to Today's date:

 

 

= Table.AddColumn(#"Removed Columns", "Start Date", each DateTime.LocalNow())

4- Then I went back to the Actuals and appended the forecast. 

 

IDNameProduction LineStart DateEnd DateSource
11Product XLine 110/1/201810/7/2018Actual
11Product XLine 210/7/201810/17/2018Actual
11Product XLine 410/17/201810/19/2018Actual
11Product XLine 210/19/201811/20/2018Actual
22Product YLine 310/6/201810/16/2018Actual
22Product YLine 410/16/201811/20/2018Actual
11Product XLine 411/20/201812/29/2018Forecast
22Product YLine 411/20/201812/31/2018Forecast

 

 

Thanks for the help. I am curious is you did it much differently but seems rather close as I see you created a separate start date. 

 

 

 

Anonymous
Not applicable

Still new to M, so using power query for this type of thing is still a little cumbersome.  But the more and more I do this I see how valuable it really is, as you demonstrated.  

 

Anyhow, here's how i accomplished it:

  1. Add a Type ( Forecast or Actual) to each table
  2. Append those two tables
  3. Create a merged column of ID, Start Date, End Date
  4. Sort the table first by Name and tehn by Type ( this will ensure Actual is before Forecast)
  5. Remove duplicates from the merged column
  6. Add a custom column Index on this table
  7. Remove the Merged columns
  8. Load this table into Power BI
    1. Create a new column called "New Start" using the index column from above, which would be the start date to use
    2. New Start = 
      VAR CurrentIndex = Append1[Index]
      RETURN 
      
      Var NewEndDate =
      CALCULATE(
      	MAX( Append1[End Date]),
      	FILTER(
      		ALL( Append1),
      		CurrentIndex =  Append1[Index] +1
      	)
      )
      RETURN 
      SWITCH( TRUE(),
      Append1[Type] = "Actual",Append1[Start Date],NewEndDate)
      
      
      Basically says if the  Type is "Actual" give me the original start date, if it says anythign else besides "Actual" give me the previous row's ( which is why we needed the index column) end date as the new starting date.  The original end date can stay
    3. :Append with new start.png
LivioLanzo
Solution Sage
Solution Sage

Hi @Anonymous

 

could you show me what the end result should be in your case?

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

Sure, Not a problem. 

I threw together the table below that shows how the info would look when combined. If you can see, for Product X it was on Line 2 today but should have been on line 4. I want to switch back to the forecast version going forward as shown. 

 

I didn't think about it but I would likely label the source as shown in the table below. 

 

Hope this helps. 

 

NameStart DateEnd DateIDProduction LineSource
Product X10/1/201810/7/201811Line 1Actual
Product X10/7/201810/17/201811Line 2Actual
Product X10/17/201810/19/201811Line 4Actual
Product X10/19/201811/20/201811Line 2Actual
Product X10/20/201812/29/201811Line 4Forecast
Amy10/6/201810/16/201822Line 3Actual
Amy10/16/201811/20/201822Line 4Actual
Amy11/20/201812/31/201822Line 4Forecast

Helpful resources

Announcements
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.