Forum Discussion
Calculating Weighted Sales
- 11 months ago
Hi Ilija89 ,
Thank you for the response, I have tried the solution based on your logic, but it is not giving exact result. you need to change your data and data model.
Please refer below two solutions.
1. Direct Sales Allocated :=
SUMX(
FILTER( Sales, Sales[Sales Type] = "Direct" ),
VAR CatCust = Sales[Category-Customer Code]
VAR Amount = Sales[Sales amount]
VAR CurrentRep = SELECTEDVALUE( Weights[Sales Representative] )
VAR WeightVal =
CALCULATE(
MAX( Weights[Weight] ),
FILTER(
Weights,
Weights[Category-Customer Code] = CatCust
&& Weights[Sales Representative] = CurrentRep
)
)
RETURN Amount * COALESCE( WeightVal, 0 )
)Indirect Sales Allocated :=
SUMX(
FILTER( Sales, Sales[Sales Type] = "Indirect" ),
IF( Sales[Sales Rep] = SELECTEDVALUE( Weights[Sales Representative] ),
Sales[Sales amount],
0
)
)please refer output snap and PBIX file.
2.
Direct Sales Allocated =VAR CurrentRep = SELECTEDVALUE ( Weights[Sales Representative] )RETURNSUMX (VALUES ( Weights[Category-Customer Code] ),VAR CatCust = SELECTEDVALUE ( Weights[Category-Customer Code] )VAR CustCode = SELECTEDVALUE ( Weights[Customer code] )VAR Cat = SELECTEDVALUE ( Weights[Category] )VAR TotalDirectForCust =CALCULATE (SUM ( Sales[Sales amount] ),Sales[Sales Type] = "Direct",Sales[Customer code] = CustCode)VAR WeightVal =CALCULATE (MAX ( Weights[Weight] ),Weights[Category-Customer Code] = CatCust,Weights[Sales Representative] = CurrentRep)RETURNTotalDirectForCust * COALESCE ( WeightVal, 0 ))Indirect Sales Allocated =VAR CurrentRep = SELECTEDVALUE ( Weights[Sales Representative] )RETURNCALCULATE (SUM ( Sales[Sales amount] ),Sales[Sales Type] = "Indirect",Sales[Sales Rep] = CurrentRep)I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
Hi Ilija89 ,
Thank you for reaching out to the Microsoft Community Forum.
You are expecting formula that will calculate weighted sales for direct sales for each sales rep per customer per category.
Please refer below output snap and attached PBIX file.
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
Hi Ilija89 ,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.
Regards,
Dinesh
- v-dineshya1 year ago
Community Support
Hi @Ilija89 ,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.
Regards,
Dinesh
- Ilija891 year ago
Helper I
Hi v-dineshya ,
Sorry for late reply. Thank you for solution, but I have one remark. In pbix file all sales reps have the same indirect sales but it shouldnt be. Formula is summing indirect sales and it is the same for all sales reps. G.L. should have 43,342 and A.K. 7,878 indirect sales while other sales reps should have 0.
- Selva-Salimi1 year ago
Solution Sage
Hi Ilija89
Thanks to v-dineshya , I think you need to update the measure as follows:
Weighted Sales =SUMX (Sales,SWITCH (TRUE(),Sales[Sales Type] = "Indirect",CALCULATE(sum(Sales[Sales amount]),FILTER(Sales,Sales[Sales Rep]=SELECTEDVALUE(Weights[Sales Representative]))),Sales[Sales Type] = "Direct",Sales[Sales amount] *CALCULATE (MAX ( Weights[Weight] ),TREATAS ( { Sales[Category-Customer Code] }, Weights[Category-Customer Code] ),TREATAS ( VALUES ( Weights[Sales Representative] ), Weights[Sales Representative] ))))If this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.