I'm trying to create a data model in which there are sales people who sell a variety of different product's. The problem comes in with the Tier structure for each product. Some products will receive different points according to sales about. some may have two to three tiers of points depending on sales amount. Other product may just be a flat payout. the then end the sales person gets his finally bounds as a percentage of his points depending on the Tier of number of points he receives for example
Product 1
if volume 100 = 10 points
if volume 200 = 20 points
if volume 300+ = 30 points
employee payout
100 points = 20% of points payout
200 points = 50% of points payout
300 points = 150% if points payout.
I'm not sure how to structure this in the data model and calculate with DAX formula
Thanks for the help in advance
Create new calculated column
Lets Say,
Now you will have
Volume calculated column
(IF ( Volume>=100 then 10 Volume >= 200 then 20)
Person 1 Product 1 100
Person 2 Product 2 200
Person X Product X 300
Then add one more calculated column based on this calculated column to get percentage of volume.
Mark answer as correct if it helps.
Try the following approach:
Data structure
Products:
Sales:
Data model
Load both tables into the Data Model (I called them Products and Sales)
In the diagram view, create a relationship between Sales[Product] and Product[Product]
DAX
This is the ugly part: In the sales table, as a new calculated column with the name Points. Use this DAX formula:
=IF(Sales[Volume]<RELATED(Products[Volume Tier 1]),0,
IF(Sales[Volume]<RELATED(Products[Volume Tier 2]),RELATED(Products[Points Tier 1]),
IF(Sales[Volume]<RELATED(Products[Volume Tier 3]),RELATED(Products[Points Tier 2]),
IF(Sales[Volume]<RELATED(Products[Volume Tier 4]),RELATED(Products[Points Tier 3]),
IF(Sales[Volume]<RELATED(Products[Volume Tier 5]),RELATED(Products[Points Tier 4]),
IF(Sales[Volume]>=RELATED(Products[Volume Tier 5]),RELATED(Products[Points Tier 5])))))))
Add a new measure with this formula: TotalPoints:=SUM(Sales[Points])
Now you can determine the number of points per transaction/sales person/etc. and use this in the subsequent steps.
Instead of using the really Volume Tiers, you could also leave non-relevant tiers blank in the Product table and extend your formula using the ISBLANK function.
I don't know about DAX but this will handle the Excel formulae.
Assuming volume in column A, to calculate points in column B:
$B2 = MIN(10*INT($A2/100),30)
Then I'm assuming you are going to aggregate points somewhere else (let's say in column D) and calculate payout in column E. My preferred way of doing this is to create a small lookup table somewhere. It looks like this:
Points Payout Rate
0 0
100 0.2
200 0.5
300 1.5
Give the lookup table a name, e.g. PayoutRates. The formula to look up the payout rate, and calculate the payout is:
=$D2 * VLOOKUP($D2,PayoutRates,2,TRUE)
Alternatively, you can use nested IF statements to get the same result:
=$D2 * IF($D2<100,0,IF($D2<200,0.2,IF($D2<300,0.5,1.5)))
Related
I'm using dynamic array functions in Excel (SCAN, MAP, LET, BYCOL, etc); wihtout VBA or regular SUMIF formulas, to create a runway or burnrate-type table. So, I start with a $10,000 budget, month 1 $2,000 are spent, so $2,000 come out of the budget, month 2 $3,000, and so on until the cash available is 0 for the remaining months of the year. With a table showing how much cash was used from the budget per month, Desired outcome in the case below.
A
B
C
D
E
F
1
Budget
$10,000
2
Month
1
2
3
4
5
3
Expense
-$2,000
-$3,000
-$7,000
-$4,000
-$2,000
4
Desired outcome
-$2,000
-$3,000
-$5,000
$0
$0
Note that the Desired outcome amount is how much of the budget was used to cover the expenses.
Notice that Month 3 I spent $7,000, but from the budget, only $5,000 were left; so that's what I show.
Studied all the dynamic array (SPILL!) functions and lambda functions that I could find on the internet (this video by excelisfun is great) but I couldn't make it work. Some combination between SCAN or MAP would be the go-to solution I would think.
The solution should be one formula that leverage MS365 dynamic array functions.
I used REDUCE to get your result:
=LET(budget, -B1,
expenses, B3:F3,
DROP(REDUCE( 0, expenses,
LAMBDA( x, y,
HSTACK( x,
IF( SUM(x,y)>=budget,
y,
budget-SUM(x))))),
,1))
It creates a cumulative sum of expenses and checks if it's greater than or equal to the budget (since your expenses are negatives I converted budget to a negative).
If it is it, the value of expenses is shown, otherwise the remainder of the budget minus the cumulative sum of the expenses.
I am trying to find a formula that will generate the total profit for a number of cohorts that generate a different periodic profit per unit, without having to create a line item for each cohort.
In this example, the profit contributed by each widget over time is shown in row 3, and the number of widgets issued in each cohort is shown vertically in column B. Each unit will contribute $25 in the first period, $60 in the second period, and so on. So year 1 total profit would be 100 x $25 = $2,500. Then in year 2, the Y1 cohort would generate 100 x $60 and the Y2 cohort would generate 200 x $25 for a total year 2 profit of $11,000.
Does someone know of a method in Excel that would work to consolidate the total profit calculation each year into a single formula? I am trying to model multiple line items over many periods, so looking for a more efficient solution.
Edit: In case this helps clarify the question, below is an image showing an example of another inefficient way to solve the problem in one line for year 4 total profits, but this is still not scalable. Also shown in text below.
`Year 4 total profit =
Y1 units issued x P4 profit per unit +
Y2 units issued x P3 profit per unit +
Y3 units issued x P2 profit per unit +
Y4 units issued x P1 profit per unit`
inefficient solution
Office 365, in C17:
=SUM(INDEX($B7:$B15,SEQUENCE(COUNT($C3:C3)))*INDEX($C3:C3,SEQUENCE(COUNT($C3:C3),,COUNT($C3:C3),-1)))
and copied right.
Ah well, I've just written an answer compatible with lower versions of Excel:
=MMULT(TRANSPOSE(B7:B15)^0,IF(ROW(B7:B15)-ROW(B7)<=COLUMN(C3:K3)-COLUMN(C3),INDEX(C3:K3,COLUMN(C3:K3)-COLUMN(C3)-(ROW(B7:B15)-ROW(B7))+1)*B7:B15,0))
It could be done a bit more easily in Excel 365 using Sequence() instead of row() and column(), but the same principle - generate a 2D matrix by comparing row and column numbers, then obtain its column totals using a standard method with Mmult.
I've filled in the intermediate results in C7:K15, but you only need the formula in C17.
hope you are doing well and can help solve this puzzle in DAX for PowerBI and PowerPivot.
I'm having troubles with my measure in the subtotals and grand totals. My scene is the following:
I have 3 tables (I share a link below with a test file so you can see it and work there :robothappy:):
1) "Data" (where every register is a sold ticket from a bus company);
2) "Km" (where I have every possible track that the bus can do with their respective kilometer). Related to "Data";
3) and a "Calendar". Related to "Data".
In "Data" I have all the tickets sold from a period with their price, the track that the passenger bought and the departure time of that track.
Each track can have more than 1 departure time (we can call it a service) but only have a specific lenght in kilometers (their kilometers are specified in the "Km" table).
Basically what I need is to calculate the revenue per kilometer for each service in a period (year, month, day).
The calculation should be, basically:
Sum of [Price] (each ticket sold in the period) / Sum of [Km] (of the period considerating the services with their respective kilometers)
I managed to calculate it for the day granularity with the following logic and measures:
Revenue = SUM(Data[Price])
Unique dates = DISTINCTCOUNT(Data[Date])
Revenue/Km = DIVIDE([Revenue]; SUM(Km[Km])*[Unique dates]; 0)
I created [Unique dates] to calculate it because I tried to managed the subtotals of track granularity taking into account that you can have more than 1 day with services within the period. For example:
For "Track 1" we have registered:
1 service on monday (lunes) at 5:00am.
Revenue = $1.140.
Km = 115.
Tickets = 6.
Revenue/Km = 1.140/115 = 9,91.
1 service on tuesday (martes) at 5:00am.
Revenue = $67.
Km = 115.
Tickets = 2.
Revenue/Km = 67/115 = 0,58.
"Subtotal Track 1" should be:
Revenue = 1.140 + 67 = 1.207.
Km = 115 + 115 = 230.
Tickets = 6 + 2 = 8.
Revenue/Km = 1.207/230 = 5,25.
So at that instance someone can think my formula worked, but the problem you can see it when I have more than 1 service per day, for example for Track 3. And also this impact in the grand total of march (marzo).
I understand that the problem is to calculate the correct kilometers for each track in each period. If you check the column "Sum[Km]" is also wrong.
Here is a table (excel file to download - tab "Goal") with the values that should appear:
[goal] https://drive.google.com/file/d/1PMrc-IUnTz0354Ko6q3ZvkxEcnns1RFM/view?usp=sharing
[pbix sample file] https://drive.google.com/file/d/14NBM9a_Frib55fvL-2ybVMhxGXN5Vkf-/view?usp=sharing
Hope you can understand my problem. If you need more details please let me know.
Thank you very much in advance!!!
Andy.-
Delete "Sum of Km" - you should always write DAX measures instead.
Create a new measure for the km traveled:
Total Km =
SUMX (
SUMMARIZE (
Data,
Data[Track],
Data[Date],
Data[Time],
"Total_km", DISTINCT ( Data[Kilometers Column] )
),
[Total_km]
)
Then, change [Revenue/Km] measure:
Revenue/Km = DIVIDE([Revenue], [Total Km])
Result:
The measure correctly calculates km on both subtotal and total levels.
The way it works:
First, we use SUMMARIZE to group records by trips (where trip is a unique combination of track, date and time). Then, we add a column to the summary that contains km for each trip. Finally, we use SUMX to iterate the summary record by record, and sum up trip distances.
The solution should work, although I would recommend to give more thoughts to the data model design. You need to build a better star schema, or DAX will continue to be challenging. For example, I'd consider adding something like "Trip Id" to each record - it will be much easier to iterate over such ids instead of grouping records all the time. Also, more descriptive names can help make DAX clean (names like km[km] look a bit strange :)
I need to create a formula in excel that will kind of do a "buy one item, get the rest at 50% off".
I need excel to pick the most expensive item and charge it at full value, then charge the rest at 50% of their value:
Item A=$30
Item B=$21
If on day one, item A was bought 2 times, and then item B was used once, I need excel to pick out the most expensive item of the day (which would be item A) and charge it at 100% of its value ($30) and then the for the second item A, charge it at 50% of its value ($15) and item B would also be at 50% of its value ($10.5). So the total charge for the day would be $55.50.
I have set up names for each item that correlates to its price. If I put =sum(itemA) in a cell in excel, then it comes up with 30.
I have it set up so that I can put in the number of each item that was bought and excel can multiple it for me =sum(itemA*2)-->60. I just need to figure out the 50% discount for all of the items bought in one day.
Please help, and let me know if there is anymore info that I need to share!!!!
ADDITIONAL:
I have added three items using the name function under "define name". Item A is equal to 30, item B equal to 21, item C equal to 15. So this is what I have set up for example, for day one:
Item Quantity Total price
item A 2 60 =sum(itemA*2)
item B 1 21 =sum (itemB*1)
item C 0 0 =sum (itemc*0)
total daily charges: 81 =sum(C2:C4)
total daily charges with discount: 55.5 (THIS IS WHERE I NEED THE FORMULA!)
ADDITIONAL:
Ok, so after working with this formula, I have another question:
I have two set of this data, and excel will pick the most expensive of the two sets and charge 100% and then charge the rest at 50%. However, I now need a way to separate out the charges for the two sets of data and get their total. So example:
Item A=30, item B=21, item C=15
Set one: item A used 2x, item B used 1x
Set two: item B used 1x, item C used 1x
Excel picks item A (as this is the highest in both sets) and charges it at 100% (30), then charges the rest of the items at 50% (43.5). The total that is charged is 73.5
Now I need excel to separate out the charges by set.
So set one, the charge is 55.5
set two, the charge is 18.
Please let me know if additional details are needed.
Assuming a layout as A:e below, three added columns might suit, with:
in F2: =MAX(IF(A:A=G2,C:C))
in G2: =IF(A2<>A3,A2,"")
in H2: =IF(G2=0,"",0.5*SUMIF(A:A,G2,E:E))+F2/2
each copied down to suit.
The first an array formula so entered with Ctrl+Shift+Enter.
The first identifies the daily maximum unit price (before discount).
The second to identify the daily summary.
The third for the calculations (same approach as #Ron Rosenfeld).
Depends on how you set things up, and you don't show that. It might be simpler to use an algorithm that computes 50% of everything, then add back 50% of the most expensive item. So if you have three columns: Items Prices Quantity, (where Prices = Price/Item) you could use a formula like:
=0.5*MAX(Prices)+SUMPRODUCT(Prices,Quantity)*0.5
If some entries in your "Quantity" column might be zero or blank, then use this formula instead:
=SUMPRODUCT(MAX(Prices*(Quantity>0))+SUMPRODUCT(Prices,Quantity))*0.5
I have a table which describes "Products Per User" distribution.
It has 2 columns nProducts and nUsers:
First row has values nProducts = 1, nUsers = 60000, meaning 60000 users bought 1 product.
Second row has values nProducts = 2, nUsers = 20000, meaning 20000 users bought 2 products, and so on...
I want to calculate its STDEV. How do I do it in excel?
In addition, could you tell me how to calculate in excel how many users bought:
nProducts > thresh?
Thanks
Li
Do you mean you want to calculate the standard deviation of the number of products bought? Try this "array formula"
=STDEV(IF(B2:B10>=TRANSPOSE(ROW(INDIRECT("1:"&MAX(B2:B10)))),A2:A10))
confirmed with CTRL+SHIFT+ENTER
So in a small example if you have 1 product bought by 4 people and 2 products bought by 3 people that will give you the standard deviation of the following values
1,1,1,1,2,2,2
Is that what you need?
Note that you can also use this "non array" version
=(SUMPRODUCT((A2:A10-SUMPRODUCT(A2:A10,B2:B10)/SUM(B2:B10))^2,B2:B10)/(SUM(B2:B10)-1))^(1/2)
which calculates standard deviation by calculating the square root of the average of the squared differences of the values from their average value
Just select all the second column values.
Then on the Ribbon bar:
go to Forumulas
click More Functions
select Statistical
click on STDEV.P
At this point as parameters you should have your second column already selected, just clik OK and you will have your Standard Deviation calculated.
In case you can write it manually the formula is =STDEV.P(B2:B10)
I supposed you have values from the 2nd to the 10th row in column B.
Thanks,
Mucio