How to access non-pivot data in a pivot measure in Excel - excel

Excel - I have built a pivot table showing the number of projected transactions. I have changed my screenshot to make it a little easier to understand. I have total projected vehicle sales in a pivot table. I have another section of data which shows how many reps we have for each vehicle type. I have set up a relationship between these 2 objects. I want to create a measure (which I can then add to the pivot table) which divides the various numbers by the rep count... In effect I want each number in the cars section divided by 62, each number in the Trucks section divided by 39, and each number in the Motorcycles section divided by 34.
The code I am using is
=[Distinct Count of Opportunities] / LOOKUPVALUE(Table1[Reps], Table1[Vehicle Type]], [Vehicle Type])
To try to simplify, I am just using the 2nd part of the calculation...
=LOOKUPVALUE(Table1[Reps], Table1[Vehicle Type]], [Vehicle Type])
I am getting the error: The value for Vehicle Type cannot be determined. Either Vehicle Type doesn't exist or there is no current row for a column named 'Vehicle Type'.
What am I doing wrong here?

Related

Excel - Monthly Average

I'm creating a pivot table that looks at per person analysis vs group average. Trying to create a pivot table, to do a comparison analysis (each person vs the group average) on a month over month analysis. As you can see i have a 4th column titled average, as im not sure how to get the average for the group though per month seeing how the data is spread out.
my test data;
http://www.mediafire.com/file/3yyriggqduw6ldw/file
You can do a sumif/countif on the range for only the year & month
(if would be year=row year and month=row month)
You basically need 2 measure as below-
1.
person_wise_average = AVERAGE(your_table_name[sale])
overall_average =
AVERAGEX(
ALL(your_table_name),
your_table_name[sale]
)
Now just add three column to your table visual - "person name", "person_wise_average" and "overall_average". You should now have all your values in the presentation.

Excel Power Pivot aggrating data through a many to 1 then 1 to many relationsips

I have 2 large tables in power pivot and I am trying to reconcile stockpile build grades to crushed stockpile grades. Please see example. I can create pivot table that contains the crushed grades but I am unable to find the right way to bring the stockpile grades though for the reconciliation high lighted in green in the attached example.
Thanks for any help or direction on where to look
In Power Query, create your lookup tables.
1) unique crushers, ID
2) Dates, ID
Here is a function to create a dates table, if you need one. After you invoke the function to get the column of dates, add another column for the ID.
/*--------------------------------------------------------------------------------------------------------------------
PQ Create a Dates Table, returning a single column of dates.
Inputs:
Start Date | Enter the year as yyyy, month as mm, day as dd
End Date | Enter the year as yyyy, month as mm, day as dd
Increments | One row will be returned per increment.
Author: Jenn Ratten
Edits:
07/16/18 | Modified query copied from the internet.
10/01/19 | Converted to a function.
--------------------------------------------------------------------------------------------------------------------*/
let
fDatesTable = (StartYear as number, StartMonth as number, StartDay as number, EndYear as number, EndMonth as number, EndDay as number, IncrementDays as number, IncrementHours as number, IncrementMin as number, IncrementSec as number) as table =>
let
StartDate = #date(StartYear,StartMonth,StartDay),
EndDate = #date(EndYear,EndMonth,EndDay),
Increments = #duration(IncrementDays,IncrementHours,IncrementMin,IncrementSec),
DatesTable = Table.FromColumns({List.Dates(StartDate, Number.From(EndDate) - Number.From(StartDate), Increments)}, type table[Date]),
ChangeType = Table.TransformColumnTypes(DatesTable,{{"Date", type date}})
in
ChangeType
in
fDatesTable
Load all of the tables to the data model.
Go to Power Pivot, diagram view, and create your relationships.
Lookup Crusher to data tables 1 and 2
Lookup Date to data tables 1 and 2
Go to Data View on data tables 1 and 2, add 2 new columns for the lookup IDs. You can specify the column header and the formula at one time by clicking in first cell and using this syntax, then either press enter or click the check mark in the formula bar.
Dates Lookup ID:=RELATED(lookup_dates[ID])
Crusher Lookup ID:=RELATED(lookup_crusher[ID])
Optional, but a good practice....
Right-click the new fields you just created and select "hide from client tools". Also hide the date and crusher fields on both data tables, and the ID field on both lookup tables. When you are creating pivots to summarize data from more than one table, the text fields that you place on your pivot table should be the fields that are shared (aka the lookup tables). This helps to minimize pivots in which the grand totals don't match the sum that you actually see on the table. If you hide the fields, it reminds you of that. There are exceptions of course, but this is a good rule of thumb.
Now create measures to sum the tons and any other math calculations you'd like. With the measures, start simple and let the pivot do the slicing. Put the measures in the values section of the pivot table.
Sum of Source Tons:=sum(Table1[Tons])
Sum of Destination Tons:=sum(Table2[Tons])

Calculate median of aggregated values for a category using pivot table

I have hourly data about sales $ of certain categories (Fruits, snacks etc). I'd like to display the median of daily sales values over a month or an year using the hourly data in the table. So, for each category it needs to sum the hourly values and create a daily value first and then calculate the median
regular pivot does not provide median function. I am familiar with Power pivots but have not used Measures. i tried to create a measure using medianX function, but could not make it work
First, you will need to add a Calendar table to your data model:
Calendar Table Explained
The Calendar table must have fields you want to group your sales by, such as "Year-Month" and "Year-Quarter".
Then, connect the Calendar table to your Sales table via date fields, to get a structure like this:
With this data model in place, create 2 measures ( I will assume your sales table is called "Sales", and calendar table is called "Date"):
Measure 1:
Total Sale = SUM(Sales[Amount])
It will simply calculate sum of sale amounts.
Measure 2:
Median Monthly Sale = MEDIANX( VALUES(Date[Year-Month]), [Total Sale])
This measure will first sum up sales by Year-Month, and then calculate the median of the sums.
To get median sales by a different period, just replace Year-Month with the desired grouping level, for example:
Median Yearly Sale = MEDIANX( VALUES(Date[Year]), [Total Sale])
Ali,
When you create your measure you will want to use the MEDIAN funciton not MEDIANX
The MedianX would be if you were trying to calculate the median value for a column in your table that did not already exist.
For Example, lets say we have Table1 which has two columns Net Revenue and Net Expense. And the following 3 data points exist for each row in the column.
Net Revenue:
Jan-2019 100
Feb-2019 300
Mar-2019 300
Net Expense:
Jan-2019 50
Feb-2019 100
Mar-2019 50
Since we do not have a Net Profit column in the table we could use MEDIANX to specify the table we would like to use then write our expression for the column that doensn't exist. In the example above it would go =MEDIANX(Table1, [Net Revenue] - [Net Expense]. This would create a median measure for NetProfit even though the column itself doesn't exist in our table.
In your case, since you are aggregating a column that already exists you can just stick with =MEDIAN.
If you need more clarification let me know!
Best,
Brett

SSAS MDX Calculated Measure - COUNT of [ITEMS].[Item] grouped [Items].[Item Group]

In Excel connected to SSAS, I am trying to build a pivot table and add a custom Measure Calculation using "OLAP Tools" and/or "OLAP Pivot Table Exensions". I am trying to add a calculation that is really simple in my mind, but I cannot get it to work. The calc I need is:
GOAL: A record count of the [Items] dimension records grouped by any of the
[Items] dimension fields.
In particular I am trying to group by [Items].[Items Groups] and [Items].[Item]. Item is the lowest grain, so the count should return value "1". I have created a couple calculations that are kind of in the ballpark (see below). But the calcs don't appears to be working as desired.
What I have tried:
Attempt #1 -- [Measures].[Items Count (With net amount values)]
DISTINCTCOUNT( {[Items].[Item].MEMBERS} )
The calc 'Items Count (With net amount values)' appears to be
returning a decent count value, but it appears it only counts the Item
if there are transnational records found (not sure why). Also, when
at the lowest grain level the calc returns that value for the parent
group, not the dimension level selected on the rows.
Attempt #2 -- [Measures].[Items Count (All)]
[Items].[Item].[Item].Count
This calc returns the TOTAL item count for the entire dimension
regardless of the dimension level placed on the rows.
Attempt #3 -- [Measures].[Items Count]
COUNT ( { [Items].[Item].MEMBERS}, EXCLUDEEMPTY)
This calc freezes up Excel and I have to quit Excel. No idea why. I have seen this sytnax recommended on a few different sites.
Screenshot:
Help please? This seems really simple, but I am not very skilled with MDX. In DAX and SSAS TABULAR this would be very simple expression. But I'm struggling to count the rows with MDX in SSAS MD.
The "Outside Purchased Beef" group has 18 items with transactions, but 41 items in total. I do not know how to calculate the "41" value.
SSAS Excel-CalcMeasure-CountRows.png
Take a look at the following samples on AdventureWorks.
with member [Measures].[CountTest]
as
count(existing [Product].[Subcategory].members - [Product].[Subcategory].[All])
select
{
[Measures].[Internet Sales Amount],[Measures].[CountTest]
}
on columns,
{
([Product].[Category].[Category]
,[Product].[Subcategory].[Subcategory] -- comment this line for the second result
)
}
on rows
from [Adventure Works]
Now comment the indicated line for the parent view.

Level of Detail on the primary data sources in tableau

I have one excel that contains the demand for each part by city:
e.g: the demand for part a for New york is 100 and 1+7=8 for Atlanta
I have another excel containing the inventory level for two warehouses: rural and urban:
e.g: Warehouse "Rural" stocks 50 for part a and warehouse "Urban" stocks zero for part c.
First I joined these two excels with the demand excel being the primary:
I googled about LOD (level of detail) in order to find out the inventory fulfillment for each warehouse by City
-- count the number of unique parts by each city for the demand:
calculated field [a] = { fixed [City]: countd([Part Number demand]) }
-- count the number of parts that are in stock (inventory level>0) by each warehouse:
calculated field [b] = { fixed [City],[Warehouse Location],[Part Number volume]: countd (if [Inventory Level] > 0 then [Part Number demand] end )}
-- calculate the inventory fulfillment %:
calculated field [c] = calculated field [a] / calculated [b]
and I got the following table and I think it is showing the correct fulfillment % by warehouse for each city: e.g: Warehouse "Rural" stocks 33% of unique parts needed by Atlanta.
Question 1: as I include more part numbers into the excel, I only want to consider the top 10 parts by volume needed for each city. I was trying to do the same thing with LOD to first find the total quantity needed per part per city:
{fixed [City], [Part Number demand]: sum([Part Number volume]) }
But it counts the quantity from both excels and I am just wondering if it is possible to only count the quantity from the primary excel (demand not the inventory),
Question 2: once I could count the total quantity needed, how do I transfer it into a filter so that I could only select top 10 parts by demand.
Apologize if these questions are dumb and appreciate for any advice!!

Resources