I have a Demand table aggregated by Customer, Product and Time Periods. I'm trying to build a Pareto Minimum Demand Chart by Site with Product and Time Period filters. When applying a specific Product filter, I noticed that for Sites with the same value of Min Demand the Pareto Cumulative Percent is duplicating. So I add RANKX formulas to my DAX code to differentiate the rank of those customers, but even so the Pareto percent is not properly being calculated.
I've noticed that the rankings were duplicated for Sites with duplicated values, so I've added a random noise to each ranking, but still it did not work.
- First try without Rankings:
First I've created a measure with the Sum of the Min Demand column:
SumMinDemand =
CALCULATE(
SUM(Demand_For_Pareto[Min Demand])
)
And with the SumMinDemand I've created the Pareto:
Pareto_Test_1 =
VAR SiteMinDemand = [SumMinDemand]
VAR TotalMinDemand = CALCULATE( [SumMinDemand], ALLSELECTED( Demand_For_Pareto ) )
RETURN
DIVIDE(
SUMX(
FILTER(
SUMMARIZE(
ALLSELECTED(Demand_For_Pareto),
Demand_For_Pareto[Site],
"MinDemand",
[SumMinDemand]
),
[MinDemand] >= SiteMinDemand
),
[MinDemand]
),
TotalMinDemand,
0
)
- Second try with Rankings:
Created a percent measure to calculate the percent of min demand of each site:
MinDemandPercentForSite =
[SumMinDemand] /
CALCULATE(
[SumMinDemand],
ALL(Demand_For_Pareto[Site])
)
Calculated the ranking of each customer based on each percent:
RankMinDemand =
RANKX(
ALLSELECTED(Demand_For_Pareto[Site]),
[MinDemandPercentForSite],
,
DESC,
Dense
)
Pareto considering ranking of each site:
Pareto_Test_2 =
VAR SiteMinDemand = [SumMinDemand]
VAR TotalMinDemand = CALCULATE([SumMinDemand], ALLSELECTED(Demand_For_Pareto))
VAR RankMinDemand =
RANKX(
ALLSELECTED(Demand_For_Pareto[Site]),
[MinDemandPercentForSite],
,
DESC,
Dense
)
RETURN
DIVIDE(
CALCULATE(
SUMX(
FILTER(
SUMMARIZE(
ALLSELECTED(Demand_For_Pareto),
Demand_For_Pareto[Site],
"MinDemand", [SumMinDemand],
"RankMinDemand", RankMinDemand
),
[RankMinDemand] <= RankMinDemand && [MinDemand] >= SiteMinDemand
),
[MinDemand]
),
ALLSELECTED(Demand_For_Pareto[Site])
),
TotalMinDemand,
0
)
As the rankings for duplicated values were the same, I've added a random noise to each ranking to differentiate each site min demand value on the next try.
- Third try adding noise to Rankings:
- Adding noise to each ranking
RankMinDemandWithNoise =
RANKX(
ALLSELECTED(Demand_For_Pareto[Site]),
[MinDemandPercentForSite],
,
DESC,
Dense
) + (RANDBETWEEN(1, 1000) / 1000000)
- Pareto measure considering each ranking noise
Pareto_Test_3 =
VAR SiteMinDemand = [SumMinDemand]
VAR TotalMinDemand = CALCULATE([SumMinDemand], ALLSELECTED(Demand_For_Pareto))
VAR RankMinDemand =
RANKX(
ALLSELECTED(Demand_For_Pareto[Site]),
[MinDemandPercentForSite],
,
DESC,
Dense
) + (RANDBETWEEN(1, 1000) / 1000000)
RETURN
DIVIDE(
CALCULATE(
SUMX(
FILTER(
SUMMARIZE(
ALLSELECTED(Demand_For_Pareto),
Demand_For_Pareto[Site],
"MinDemand", [SumMinDemand],
"RankMinDemand", RankMinDemand
),
[RankMinDemand] <= RankMinDemand && [MinDemand] >= SiteMinDemand
),
[MinDemand]
),
ALLSELECTED(Demand_For_Pareto[Site])
),
TotalMinDemand,
0
)
So even adding noise to each ranking the pareto was not abble to properly calculate the cumulative percents.