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 ,
Could you please share the expected output from the sample data you provided? This will help us investigate further and work on the measure effectively. Apologies that the issue still persists, and thank you for your patience.
Regards,
Dinesh
Hi v-dineshya ,
thanks for assistance, below is expected output.
| Direct | Indirect | Total | |
| A.K | 1,587,374 | 7,878 | 1,595,252 |
| AB | 105,856 | - | 105,856 |
| 1 | 105,856 | 105,856 | |
| AC | 1,481,519 | - | 1,481,519 |
| 1 | 1,481,519 | 1,481,519 | |
| KG | - | 7,878 | 7,878 |
| 2 | 7,878 | 7,878 | |
| B.J | 1,481,519 | - | 1,481,519 |
| AC | 1,481,519 | - | 1,481,519 |
| 1 | 1,481,519 | 1,481,519 | |
| G.L | 1,843,742 | 43,342 | 1,887,084 |
| AB | 317,567 | 43,342 | 360,909 |
| 1 | 317,567 | 43,342 | 360,909 |
| AC | 1,481,519 | - | 1,481,519 |
| 1 | 1,481,519 | 1,481,519 | |
| AF | 44,656 | - | 44,656 |
| 1 | 44,656 | 44,656 |
- v-dineshya11 months ago
Community Support
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
- Ilija8911 months ago
Helper I
Weight table
Customer Category Customer code Sales Representative Weight Category-Customer Code AB 1 1ab A.K 25% 1_1ab AB 2 1ab B.J 100% 2_1ab AB 1 1ab G.L 75% 1_1ab AC 1 1ac A.K 33% 1_1ac AC 1 1ac B.J 33% 1_1ac AC 1 1ac G.L 33% 1_1ac AF 2 1af A.K 50% 2_1af AF 2 1af B.J 50% 2_1af AF 1 1af G.L 100% 1_1af KG 1 1kg A.K 50% 1_1kg KG 2 1kg B.J 100% 2_1kg KG 1 1kg G.L 50% 1_1kg Sales table
Customer Sales Type Category Date Customer code Sales amount Sales Rep Category-Customer Code AB Direct 1 Jan-25 1ab 423,423 Direct 1_1ab AB Indirect 1 Feb-25 1ab 43,342 G.L 1_1ab AC Direct 1 Jan-25 1ac 4,444,556 Direct 1_1ac AF Direct 1 Feb-25 1af 44,656 Direct 1_1af KG Indirect 2 Feb-25 1kg 7,878 A.K 2_1kg Bridge Table
Customer Category Customer code Category-Customer Code AB 1 1ab 1_1ab AB 2 1ab 2_1ab AC 1 1ac 1_1ac AC 2 1ac 2_1ac AF 1 1af 1_1af AF 2 1af 2_1af KG 1 1kg 1_1kg KG 2 1kg 2_1kg - v-dineshya11 months ago
Community Support
Hi Ilija89 ,
Thanks for the update, Could you please elaborate the logic behind the expected output or Please explain your query in detail. I have tried all the options, but i am not getting the expected output.
Regards,
Dinesh
- v-dineshya11 months 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
- Ilija8911 months ago
Helper I
Hi v-dineshya ,
Logic is explained below:
Direct Indirect Total Logic A.K 1,587,374 7,878 1,595,252 AB 105,856 - 105,856 1 105,856 105,856 Direct sales from customer AB, we are multypling direct sales of AB with weight - 25% out of 423.423 AC 1,481,519 - 1,481,519 1 1,481,519 1,481,519 Direct sales from customer AC, we are multypling direct sales of A.C with weight - 33% out of 4.444.556 KG - 7,878 7,878 2 7,878 7,878 This is indirec tsales from A.K. so it is 7.878 it is wo using weights B.J 1,481,519 - 1,481,519 AC 1,481,519 - 1,481,519 1 1,481,519 1,481,519 Direct sales from customer AC, we are multypling direct sales of A.C with weight - 33% out of 4.444.556 G.L 1,843,742 43,342 1,887,084 AB 317,567 43,342 360,909 1 317,567 43,342 360,909 Direct sales from customer AB, we are multypling direct sales of AB with weight - 75% out of 423.423 while indirect sales corresponds to indirect sales of G.L which is 43.342 AC 1,481,519 - 1,481,519 1 1,481,519 1,481,519 Direct sales from customer AC, we are multypling direct sales of A.C with weight - 33% out of 4.444.556 AF 44,656 - 44,656 1 44,656 44,656 Direct sales from customer AF, we are multypling direct sales of AF with weight - 100%(1) out of 44.656