简体   繁体   中英

PowerPivot, Data Model to select from a data entry table against a list of dates in a separate table

Apologizes for perhaps asking a too-simple question, but I'm unable to solve my problem.

I would like to display a running balance of scheduled production yields , lets just say in gallons of milk.

I have an entry table that I schedule my milk, and it has absolutely nothing unique about it, The names, start dates, end dates, batch numbers, everything are not unique.

And so now I want to forecast my yields here with dates, but I also want to see how much milk I might sell on a date that does not exist in the entry table.

My thought is to create a list of the dates I want to pick, and the table will go looking for the values. But, because my Data Entry Table is completely unique, the only thing I can do is associate the Data Entry Table with my Selected Dates, backwards in a way that does nothing.

我的数据模型,目前没有组织,没有按照我的意愿做

这是结果

Currently the data model is 'working' for what I told it to do, but what I really want to do is instead of using Packing Date (Scenario) , I want to use 'Date Picks'[Dates Between] , because I want to see dailies, every day, not just only my entry dates.

When I place 'Date Picks'[Dates Between] in the columns instead of Packing Date (Scenario) , I get #N/A and stuff obviously because my relationship is backwards.

The issue is, I can't change the relationship direction because it's an Entry table and there's nothing unique inside of it, let alone anything unique I can associate with 'Date Picks'

This is how I ended up organizing my data Model:

工作数据模型

Besides the successful change of the "filtering flow" or "relationship flow" of the data model, I created a whole new table named Will Sell that contains every date in Selected Dates , every name in Selected Names , and every daily sales in Will Start .

How I created Will Sell is not very clean,

I created a flattened pivot table with all of the aforementioned fields as Rows,

and then created the formula =IF(C2 <> 0, C2, "") to pull data from that flattened PivotTable into individual cells that make up a standard table. I then pull that standard table into PowerPivot as Will Sell

In case anyone may be interested my measures are the following:

Running Sales:

=CALCULATE(SUM('Will Sell'[Sales (Daily, Average)]),

FILTER(ALL('Selected Dates'[Controller Dates]), 'Selected Dates'[Controller Dates] <= MAX( 'Selected Dates'[Controller Dates])))

Running Have:

=CALCULATE(
SUM('Will Package'[Yield (Gallons)]),

FILTER(ALL('Selected Dates'[Controller Dates]), 
 'Selected Dates'[Controller Dates] <= MAX( 'Selected Dates'[Controller Dates])),

 FILTER(ALL('Will Package'[Packaged?]),
 'Will Package'[Packaged?] = FALSE)

 )+[Static Starting Gallons]

Running Balance:

=IF([Running Have] <= [Running Sales], 0, [Running Have]-[Running Sales])

Running Balance (Fixed):

=IF(COUNTROWS(VALUES('Selected Names'[Product Name]))=1,
   [Running Balance],
   SUMX(VALUES('Selected Names'[Product Name]), [Running Balance])
)

I'm using the Running Balance (fixed) instead of Running Balance because the fixed measure calculates the Grand Total properly whereas the other one does not.

Here are my results, which are desired:

工作结果!

The dates on the left are Week Ending dates, the meat in the middle is the predicted future inventory over time, and the far right darkest column is the grand total.

Very happy with my prediction model!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM