I have a somewhat complicated scenario that I'm trying to build out in Excel using PowerPivot. We have sales pipeline items that each represent a sales opportunity and, associated with each of those pipelines, a number of events. I have history tables for both pipelines and events and would like to use them to construct a model of how a given sales executive's entire pipeline set has changed over time.
The result set from my SQL query might look like this:
pipeline_id | date_last_mod | pipeline_event_id | amount |
---|---|---|---|
P-01 | 1/1/2020 | PE-01 | 100 |
P-02 | 1/1/2020 | PE-02 | 500 |
P-02 | 1/2/2020 | ||
P-02 | 1/2/2020 | PE-02 | 1000 |
P-03 | 1/1/2020 | PE-03 | 200 |
P-03 | 3/1/2020 | PE-03 | 200 |
P-03 | 4/1/2020 | PE-04 | 300 |
P-03 | 5/1/2020 | PE-03 | 400 |
P-03 | 5/15/2020 | PE-03 | 300 |
I also have a date table with the usual fields. What I'm trying to produce is a PivotTable that looks like the following. You can see it takes the most recent 'amount' value of each pipeline event and sums those up as of the end of each month.
Year | Month | amount |
---|---|---|
2020 | 1 | 800 |
2020 | 2 | 800 |
2020 | 3 | 800 |
2020 | 4 | 1100 |
2020 | 5 | 1200 |
It seems like the solution should be something with SUMX and LASTNONBLANK. I have a measure that looks like this:
TestRev:=VAR MaxDate =
MAX ( qryPipelineUS[date_last_mod] )
RETURN
SUMX( ADDCOLUMNS( SUMMARIZE( qryPipelineUS, qryPipelineUS[pipeline_id], qryPipelineUS[pipeline_event_id] ), "temp",
CALCULATE (
SUM ( qryPipelineUS[amount] ),
LASTNONBLANK( qryPipelineUS[date_last_mod], CALCULATE( SUM( qryPipelineUS[amount] ) ) ),
ALL( qryDateTable ),
ALLEXCEPT( qryPipelineUS, qryPipelineUS[pipeline_event_id] ),
qryPipelineUS[date_last_mod] <= MaxDate ) ), [temp] )
The problem with it seems to be that the SUMMARIZE function won't generate rows for pipeline_event_id's in months that don't have entries for them. Makes sense, really. Even when I try to do something with CROSSJOIN, I can generate a table with the ID's I need, but can't get it to generate data.
I'd really appreciate any suggestions as to how I should go about this. I've been beating my head against the problem for a couple weeks now and I'm not getting anywhere. Thanks in advance.