Excel PowerPivot Measure For cumulative total (of only the visible cells in a Pivot Table) for underlying OLAP data - excel

I am trying to provide on of our FHF fundraising campaign managers with a tool they can use to help them pick postcodes to send a campaign to.
Spoecifcally, I'm seeking help writing an Excel PowerPivot Measure for a cumulative total that counts only the visible cells in a Pivot Table and wherein the source data is OLAP (i.e. an Excel Data Model - which seems to carry some constraints to possible solutions)
The linked worksheet is a simplified example of the excel worksheet tool I want to give to the Campaign Manager in a Fundraising setting https://www.dropbox.com/scl/fi/3pfc8ix2ekduoocsa90zs/minReprodExample_share1.xlsx?dl=0&rlkey=m6gqf5zbjxhl6dzkjq653it3d
We have two predictive models both giving different predicted response rates per postcode
The 'data' tab contains the raw data
The 'modelA_pivot' tab contains a pivot table ranking the raw data according to the predicted response rates from ModelA
'model_pivotB' does the identical pivot for ModelB
Focussing just on the 'modelA_pivot' tab for now
you can see a slicer that allows the campaign manager to exclude postcodes with only 3,000 addresses
(or some other threshold level of their choosing)
The slicer's exclusion of a single postcode with 3,000 addresses in this example is why you see the rank column in the pivot run; 1, 3, 4, 5
(i.e. missing rank 2 postcode with 3,000 addresses)
In the pivot, the last column - 'addressCount_postcodeCumulative_modelA' - is based on an excel Power Pivot 'Measure'
And the current formula of the measure is
=VAR rankCurrent = MAX([rank_modelA])
RETURN
CALCULATE(
SUM([addressCount_postcodePer]),
FILTER(
ALL(data),
[rank_modelA] <= rankCurrent
)
)
You can see in the 'modelA_pivot' tab the 'addressCount_postcodeCumulative_modelA' column
doesn't work or make sense. As it includes the cumulative total of ALL addresses (including the 3,000 addresses that are excluded from the pivot)
Can anyone help me with a 'Measure' formula that sums only the addresses of the postcodes that are visible and included in the pivot table
FYI and in case anyone is wondering, why a 'Measure'; I am using excel Power Query and Power Pivot so if/when the data upstream changes, the data team will be able to refresh this worksheet with a single click (more or less), and the campaign manager still gets to use excel (the tool they know and like)
But, the use of excel Power Query and Power Pivot and setting this up as an excel Data Model (which uses OLAP structured data)
is also injecting constraints which I'm hoping to fit the answer to this puzzle inside
Constraints such as;
I can't seem to put calculated fields onto the pivot table, and
I don't want to just add conventional excel columns on the side of the pivot table as the size of the pivot table is dynamic depending on choices of the Campaign Manager (like their choice of threshold # addresses in the slicer)

Related

Excel table filters not recognised in PowerPivot measures

I'm trying to create a parameter table to change the units the figures in my pivot table are presented in. I have:
TransTBL table with my transactions.
Units table with 1; 1,000; 1,000,000 in column A and Units; K's; M's in column B.
Both tables are in my data model.
I added the Units Column B as a slicer to TransTBL, despite the fact they have no connections.
I then tried to create a measure in the Units table on the PowerPivot side to recognise which slicer option was chosen. My measure won't recognise the slicer selection. However it will recognise the filter if I apply it directly to the table in PowerPivot.
I'm using the HASONEVALUE function as described here.
The measure works fine as expected.
AmountDisplay =
IF(
HASONEVALUE(Units[B]),
SUM(TransTBL[Amount]) / VALUES(Units[A]),
SUM(TransTBL[Amount])
)
Can you provide more details on your data or model to see if there are any specific problems associated?

How to add calculated column to a pivot table connected to SSAS tabular model?

Or in another words the question is - how to add some calculation in the pivot table based on columns which do not exist in model level.
I've reproduced my problem using AdventureWorksDW2014 sample database.
Let's say I want to calculate difference between Actual and Budget scenario amounts in the FactFinance table for each Organisation and present it in a form of pivot table.
To achieve that I've created a simple model (screen above) and added SumOfAmount measure to the FactFinance table SumOfAmount:=SUM([Amount])
Next, I've opened my model in Excel and created very simple pivot table (shown below)
So, (the question part) now I want to add an extra column to my pivot table, which should calculate something (for example difference) between columns Actual and Budget. And I want this new column been a part of the pivot table so I could filter it or\and add new grouping levels without necessity to change something "outside" the pivot table.
TRIED SO FAR
I tried to add Calculated Field but it seems like I can only use "real" columns for calculations. Columns which appeared in a pivot table based on values from COLUMNS quadrant can't be used as sources for calculations.
FINAL SOLUTION
I got it finally combined two pivot tables: the old one and the one with Diff measure, defined as Diff:=[Actual Amount]-[Budget Amount], where
Actual Amount:=Calculate([SumOfAmount];'DimScenario'[ScenarioName] = "Actual")
Budget Amount:=Calculate([SumOfAmount];'DimScenario'[ScenarioName] = "Budget")
as #WimV suggested
First calculated measure is good:
SumOfAmount:=SUM('FactFinance'[Amount])
Add the following Calculated measures (if needed mark as hidden):
Budget Amount:=Calculate([SumOfAmount],'DimScenario'[Scenariokey] = "Budget")
Actual Amount:=Calculate([SumOfAmount],'DimScenario'[Scenariokey] = "Actual")
You can use the new calculations for example in a difference calculations

Excel 2013 PowerPivot Table - Many Fact Tables along with a Calculated Field

I am pretty new on creating POWERPIVOT tables. I have searched for a bit of time now to resolve this problem but I have been unsuccessful so far. Here is my problem. As you can see below, I have created a POWERPIVOT table in Excel 2013 that is composed of two FACT tables, which are based on: 1) a sheet where the clients can insert initial budget entries; and, 2) another sheet where the clients can insert the post-initial budget entries. Also, a DIMENSION table has been added to the combination in order to add the following relationships:
Based on these relationships, I have clicked on Insert a PivotTable to create the following POWERPIVOT table that will be used to display the Initial Budget and Adjustments entries for analysis purposes. However, this table does not give me the total of both columns. I have thought that a calculated field would make it happen but this is where I am stucked as nothing let me sum the two columns like I was used to do with regular pivot tables in Excel 2007. The calculation of the two columns would logically equal the Current Budget as shown attached.
Thank you for your help on this.
With Power Pivot you don't use the calculated field feature of pivot table.
You have to put a measure in your data Modell, which you can then add in the value part of the PT. Relationships alone are not enough.
currentBudget := CALCULATE (
SUM ( fInitialBudget[Initial Budget] ) + SUM ( fAdjustement[Adjustements] )
)
if you are new with Power Pivot, I warmly recommend the book of Rob Collie "DAX Formulas for Power Pivot". I got a very good introduction of the PP capability with it. The 2nd Edition is on the way.

Combine pivot tables with different but compatible measures?

I have a pivot table that displays agencies in rows, products in columns and sales units as values. I have to make up a report in this format:
Data is coming from an SQL Server Analysis Services and the "Estimate 2015" measure is a different measure (but uses the same dimensions and granularity so it is in fact possible to display the values side by side).
I could add a separate pivot table for the estimates, but then filtering or sorting the two tables will make them loose sync.
Is it possible to somehow align or combine pivot tables with different measures nicely?
if you are using Excel 2013, then you can use the data-model feature with standard pivot tables.
You need on your workbook:
3 dimension tables for agencies, products and year. All rows must contain distinct values (Agency A-C, Product A-B, Year 2013-2015)
2 fact tables: the one with historical data (from SSAS), the second one with your forecast datas
then you just create a Pivot table from any of the Dimension table. At this step, check the box "Add this data to the Data Model".
You then pull the Dimension field from the three dimension table on the Pivot column and rows. Choose both value fields from the 2 fact table (Quantity).
Excel detect missing relationships. You have to build them manually between the two Facts tables and the three dimensions (total 6 relationships)
In this Excel-file you can see an example with your sample datas.
You can find on the web some step-by-step explanations like How to Build PivotTables Using Excel's Data Model Feature

PowerPivot - How to Filter Dimension to Get Value

I am working on a PowerPivot report that has the following tables/relationships:
FactTable:
SponsorId
OfficeId
Type
Color
Quantity
DimSponsor:
SponsorId
SponsorName
ProjectName
DimOffice:
OfficeId
Region
Country
Manager
NumberEmployees
Relationships exist FactTable to each of the two dimension tables.
I wish to create a calculated measure that is the SUM(Quantity)/SUM(NumberEmployees) which represents the average number of items processed by number of employees.
I believe I am having the problem listed here at PowerPivotPro FAQ
When I create a pivot table that has an X-Axis of [Region] with [NumberEmployees] as the only value it always displays the sum of ALL [NumberEmployees] regardless of any slicer selection (in this case, I created a horizontal slicer of [SponsorName]).
I am new to DAX and have struggled to find a formula to meet my needs. Is there any solution to this problem?
I found working examples of what I needed to accomplish on Marc Russo's blob. It is a matter of creating a custom measure that filters the Office table by the already filtered rows of FactTable.
As some of the comments on the page mention, it isn't as easy as drag-n-drop but it works.

Resources