Power Bi - Competitor Average Price Measure - excel

Attached is the data I have the question for. I want to create a Measure in Power Bi that gives me the average price of a competitor's farm product. (If looking at Beth's product I want to see the average of Amy's product) If a filter is applied (Example: Product type = Fruit) then I want to see the average price of Amy's fruits). The goal of this is to find the % difference each product is from its filtered competition.
SpreadSheet Data
My unsuccessful attempt:

Related

Power BI RankX function

I have a simple table ,Sales with just product,Quantity , and totalsales.
I am trying to rank product based on total sales.
m1=rankx('sales','sales'[totalsales])
It is giving me all sort of errors.
To get the products based on order of total sales use the following steps:
Create a Total Sales measure :
TotalSalesMeasure = Sum('Product'[TotalSales])
Use the above measure in your DAX to calculate RANK
RankProduct = RANKX(ALLSELECTED('Product'[Product]),[TotalSalesMeasure],,DESC,Skip)
Hope this solves your issue.
Best Regards,
Shani Noorudeen

Weighted average price of a product per day in Pivot Table

I am having issues translating the following formula to a pivot table; either through a regular pivot table, or through DAX and powerpivot.
=SUMPRODUCT((C$2:C$11)*(D$2:D$11)*(A$2:A$11=A2)*(B$2:B$11=B2))/SUMIFS(D$2:D$11,A$2:A$11,A2,B$2:B$11,B2)
The background is, I have a number of products that appear on an e-commerce site, and I need to find out their price per day. However, these prices change daily, based on things like promo codes, visitor location etc. Therefore, I need their weighted price based on the number of visitors that saw a particular price.
Can anyone help with this translation, or alternatively, offer a better way to approach this problem?
PS- I need it in a pivot table due to the volume of data. At 250,000 rows, standard Excel cannot handle this formula.
The following is in Excel 2010 sans Powerpivot. However, the general approach should work:
Explanation:
I added a column that multiplies the Prices and Visits. The pivot table uses Dates, then Product SKU as the row labels. Then I added a calculated field that divides the Price*Visits by the Visits.

Powerview drop filter context on a column

I'm currently working on a power view project where I need to display the numbers of the gross market and compare these to the numbers of a certain customer.
In this particular example, the market has sales in clothing, food, entertainment and electronics. However, in the dataset, the customer only has records for clothing and food (so they didn't sell in the other fields, this isn't missing data).
When I now make a pivot table in power pivot with this data (with the customer as a filter, but with DAX formulas to drop the filter to display the gross market sales) , I correctly get what I want. Quick example:
CLOTHING 11654$ 2541$
FOOD 325477$ 4356$
ENTERTAINMENT 22234$
ELECTRONICS 70124$
Now, when I try to do this exact thing in Powerview, the matrix (with again the customer as filter) doesn't show the numbers for entertainment and electronics, because the matrix is filtered.
Is there a way to drop a filter on rows or columns? I already tried 'show items with no data' but to no prevail.
Thanks in advance!
Try either of these and see if it works:
in the data model --> [Column]-->Advanced --> Summerize By --> Do Not Summerize
add gross market to view filter in power view.

Excel PowerPivot DAX Calculated Field

I think I've got a relatively easy problem here on my hands, just having trouble getting it to work. Let me preface this by saying I'm new to DAX.
Consider the following PowerPivot Data Model :
It consists of a Sales Records table, which is joined to a Date lookup table, as well as a "Daily Expenses" table. The "Daily Expenses" table stores a single value which represents the averaged cost of running a specific trading location per day.
It's extremely easy to produce a PivotTable that provides me with the total Sales Amount per store per [insert date period]. What I'm after is a DAX formulation that will calculate the profit per store per day - ie. Total Sales minus DailyExpenses (operating cost):
In theory, this should be pretty easy, but I'm confused about how to utilise DAX row context.
Failed attempts:
Profit:=CALCULATE(SUM(SalesInformation[SaleAmount] - DailyStoreExpenses[DailyExpense]))
Profit:=CALCULATE(SUM(SalesInformation[SaleAmount] - DailyStoreExpenses[DailyExpense]), DailyStoreExpenses[StoreLocation])
Profit:=SUM(SalesInformation[SaleAmount] - RELATED(DailyStoreExpenses[DailyExpense])
etc
Any help appreciated.
Zam, unfortunately your failed attempts are not close :-)
The answer, and best practice, is use a 4th table called 'Stores' which contains a unique record per store - not only is this useful for bringing together data from your two fact tables but it can contain additional info about the stores which you can use for alternative aggregations e.g. Format, Location etc.
You should create a relationship between each of the Sales and Expenses tables and the Store table and then use measures like:
[Sales] = SUM(SalesInformation[SaleAmount])
[Expenses] = SUM(DailyStoreExpenses[DailyExpense])
[Profit] = [Sales] - [Expenses]
Provided you have the Date and Store tables correctly linked to the two 'Fact' tables (ie Sales and Expenses) then the whole thing should line up nicely.
Edit:
If you want to roll this up into weeks, years etc. and you have no kind of relationship between expenses and the calendar then you'll need to adjust your expenses measure accordingly:
[Expenses] = SUM(DailyStoreExpenses[DailyExpense]) * COUNTROWS(DateTable)
This will basically take the number of days in that particular filter context and multiply the expenses by it.

Excel PowerPivot Average Calculation

I am having some difficulty determining how to produce a calculation of averages that can be plotted on a PivotChart.
Specifically, I wish to compare a Sales Rep's performance (gross profit by month/year) against all other reps (using an average) who are in a comparable role (the same workgroup) for a given period.
Let's just say the data structure is as follows:
SaleID SaleLocation SaleType SalesRep SaleDate WorkGroup SalesGP
1 Retail1 Car John A 01/01/2014 Sales $301
2 HQ Bike John A 01/01/2014 Sales $200
3 Retail1 Car Sam L 02/01/2014 Sales $1300
4 Retail2 Plane Sam L 02/01/2014 Sales $72
5 Retail2 Plane Vince T 03/01/2014 Admin $55
6 Retail2 Bike John A 04/01/2014 Sales $39
7 HQ Car Vince T 05/01/2014 Admin $2154
....etc
In the excel data model I've added calculated fields (that use a lookup table) for the sale date so that sales can be plotted by Month or Year (eg. =YEAR([SaleDate]) and =MONTH([SaleDate]))
As an example, let's say I want to plot someone's GP (Gross Profit) for a period of time:
My question is this......
How can I calculate an "average gross profit" that I can plot on the PivotChart? This "average gross profit" should be the average of all sales for the same period for the same workgroup.
In the example above, in the PivotChart I am wanting to plot an "average" series which plots the average GP by month for all SalesReps that are in the same Workgroup as John A ("Sales").
If my request isn't clear enough please let me know and I'll do my best to expand.
Zam, this should be quite easy. You just need to create a new calculated field that calculates the average for ALL sales rep.
Let me walk you through it:
I used your data table and then added it to my PowerPivot (Excel 2013). Then I created those calculated measures:
1. Sales Average:
=AVERAGE(SalesData[SalesGP])
2. Sales Average ALL -- this will calculate the average for ALL rows in the table and will be used in other calculations. Notice I used the first calculated field as the first parameter to make this flexible:
=CALCULATE([Sales Amount Average],ALL(SalesData))
3. Sales Comparison to Average. I wasn't sure what is your goal, but I made this one a bit more complex as I wanted to display the performance in percentage:
=IF([Sales Amount Average] > 0, [Sales Amount Average] / [Sales Average ALL] -1)
Basically, what this does is that first it checks if their an existing calculation for a sales representative, if so then it divides Sales Average for a given sales representative by the average sale amount for ALL sales representatives. And then I subtract 1 so the performance can be easily grasped just by looking at the percentages.
To make it easy-to-understand, I decided to use bar charts in conditional formatting instead of stand-alone pivotchart -- I believe it does exactly what you need:
In the picture above, the first table represents your data. The second table is the actual powerpivot table and shows what I have described.
Hope this helps!
EDIT
I didn't want to make things over-complicated, but should you want to remove the percentage total from Grand Totals row, use this calculation instead for the percentage comparison:
=IF(HASONEVALUE(SalesData[SalesRep]),
IF([Sales Amount Average] > 0,
[Sales Amount Average] / [Sales Average ALL] -1),
BLANK()
)
EDIT - ADDED AVERAGE COMPARISON FOR WORKGROUPS
To calculate the performance per workgroup instead of ALL sales representative, add those two measures:
4. Sales Average per Workgroup
=CALCULATE(AVERAGE(SalesData[SalesGP]),ALL(SalesData[SalesRep]))
This will calculate the average sale per workgroup (don't get confused with using SalesRep in ALL function, it's related to filter context).
5. Sales Diff to Average per Workgroup
=IF(HASONEVALUE(SalesData[SalesRep]),IF([Sales Amount Average] > 0, [Sales Amount Average] - [Sales Average per Workgroup]),BLANK())
This simply calculates the difference between average sale of given sales rep and the average sale per workgroup. The result could then look like this:
I have uploaded the source file to my public Dropbox folder.

Resources