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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ShNBl84
Helper II
Helper II

Merge tables with all data despite longer date ranges

Hey heros,

 

I have two large tables that I am trying to combine. I have a table that shows the history of items sold (historical only) and the forecasted sales (includes past and future dates).

Sold:

Sales.jpg

Forecasted (notice that it also includes future dates):

Forecast.jpg

My goal is to combine the two to look like this:

Goal.jpg

My current challenges are:

1) if I merge the two tables, the dates stop at the "Sold" dates (so no forecasted sales after today's date) and the forecasted sales are not crossjoined to each of the stores (empty store name data)

2) if I crossjoin the forecast table with all my stores in my real data so I can merge them from there, the forecast table goes from 52k rows to 83M rows (which I am trying to avoid)

 

Preferably all this occurs in power query so my measures etc. remain in my report. 

Thanks!

1 ACCEPTED SOLUTION
ShNBl84
Helper II
Helper II

It isn't the prettiest solution, but it is the best I could do.

 

I duplicated the Forecast table and filtered one to be any date before today (to match the dates in the Sales table) and the other to be today or later.

To make the filter I used: #"Past Only" = Table.SelectRows(#"(previous line)", each [Date] < Date.From(DateTime.LocalNow()))

I then LeftOuter joined the Forecast (Past) table with Sales.

I crossjoined Forecast (Future) with a table that is a unique list of store names by adding the store table as a column to the Forecast (Future) table. 

I then appended the Forecast (Future) with store names table to the Sales table.

 

That leaves me with a Forecast (Future) table with many more rows than I wanted, but it is far less than crossjoining the entire table.

View solution in original post

3 REPLIES 3
ShNBl84
Helper II
Helper II

It isn't the prettiest solution, but it is the best I could do.

 

I duplicated the Forecast table and filtered one to be any date before today (to match the dates in the Sales table) and the other to be today or later.

To make the filter I used: #"Past Only" = Table.SelectRows(#"(previous line)", each [Date] < Date.From(DateTime.LocalNow()))

I then LeftOuter joined the Forecast (Past) table with Sales.

I crossjoined Forecast (Future) with a table that is a unique list of store names by adding the store table as a column to the Forecast (Future) table. 

I then appended the Forecast (Future) with store names table to the Sales table.

 

That leaves me with a Forecast (Future) table with many more rows than I wanted, but it is far less than crossjoining the entire table.

artemus
Employee
Employee

Use a left outer join when merging, picking Date and Item column as your join columns (use Ctrl to multi select).

Thanks for your input. That solution works great until the dates reach beyond the Sold dates. The Forecasted sales do not get distributed to the Store names after that.

Sol1.jpg

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors