Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
avcr29
Frequent Visitor

Create cumulative weighted average measure with changing weight

Hello!

 

I really need help, i don't know how can i solve this, i've got a measure X and i need to get the cumulative weighted average of it. There are categories and per each category there's a determinated weight, now, so far i get the result but now there is one category that it will be considered only in some months (the data is trimestrals march, june, september and december, this new category will be considered on june and december) but because of that, the weights change in those months (june and december) so here is what i have:

 

Weigths:

CategoryMarchJuneSeptemberDecember
CB 0.2 0.2
CC0.20.10.20.1
CM0.40.350.40.35
CV0.40.350.40.35

 


this is what i have:

 

MonthCategorymeasure xweigth
JuneCB33.33%0.2
MarchCC100.00%0.2
JuneCC0%0.1
MarchCM20.00%0.4
JuneCM20.00%0.35
MarchCV100.00%0.4
JuneCV33.33%0.35


but what i really want is this:

 

MonthCategorycumulative measure xweigthcumulative weighted average
JuneCB33.33%0.26.67%
MarchCC100.00%0.220.00%
JuneCC60.00%0.16.00%
MarchCM20.00%0.48.00%
JuneCM20.00%0.357.00%
MarchCV100.00%0.440.00%
JuneCV66.67%0.3523.33%


so if i want to get a total i'll get these results:

 

MonthTOTAL
March68.00%
June43.00%


the formulas i worked were these:

 

to get the weighted measure x:

 

weighted measure x=
VAR __CATEGORY_VALUES = VALUES('table'[Category])
RETURN
DIVIDE(
SUMX(
KEEPFILTERS(__CATEGORY_VALUES),
CALCULATE([measure x] * LASTNONBLANK('table'[weigth],1))
),
SUMX(
KEEPFILTERS(__CATEGORY_VALUES),
CALCULATE(LASTNONBLANK('table'[weigth],1))
)
)

 

to get the cumulative weigthed measure x:

 

cumulative weigthed measure x =
IF(
ISFILTERED('table'[Date]),
ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
VAR __LAST_DATE = ENDOFMONTH('table'[Date].[Date])
VAR __DATE_PERIOD =
FILTER(DATESBETWEEN(
table'[Date].[Date],
STARTOFMONTH(DATEADD(__LAST_DATE, -COUNT('table'[Date].[Date]), MONTH)),
ENDOFMONTH('table'[Date].[Date])
),YEAR(__LAST_DATE)=YEAR('table'[Date].[Date]))
var resultado= CALCULATE(table[weighted measure x],
CALCULATETABLE(
SUMMARIZE(
VALUES('table'),
'table'[Date].[Year],
'table'[Date].[QuarterNo],
'table'[Date].[Quarter],
'table'[Date].[MonthNo],
'table'[Date].[Month]
),
__DATE_PERIOD
)

)
RETURN
if(ISBLANK(table[weighted measure x]),0,resultado)
)

 

these formulas worked well because the weights were the same each month but now they don't so i don't know exacly how can i modify the formulas or if there's another way to get that result. 

 

I would appreciate the help,

Thanks!

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @avcr29 ,

 

I have a little confused about your scenario.

 

If I understand your scenario correctly that you weighted table is your sample data and your desired output is the third table in your post?

 

If it is, could you share your formula of the measure x so that I could understand your logic better.

 

weighted measure x=
VAR __CATEGORY_VALUES = VALUES('table'[Category])
RETURN
DIVIDE(
SUMX(
KEEPFILTERS(__CATEGORY_VALUES),
CALCULATE([measure x] * LASTNONBLANK('table'[weigth],1))
),
SUMX(
KEEPFILTERS(__CATEGORY_VALUES),
CALCULATE(LASTNONBLANK('table'[weigth],1))
)
)

 

In addition, I cannot understand the logic why cumulative measure x for June of CC is 60%?

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-piga-msft !

 

 

DateMonthCategoryTypeWeight
01/03/2019MarchCMDetractor0.4
01/06/2019JuneCMPromoter0.35
04/06/2019JuneCBDetractor0.2
01/03/2019MarchCVPromoter0.4
04/06/2019JuneCVDetractor0.35
01/03/2019MarchCCPromoter0.2
04/06/2019JuneCCDetractor0.1
01/03/2019MarchCMPromoter0.4
04/06/2019JuneCMDetractor0.35
02/03/2019MarchCMPromoter0.4
02/06/2019JuneCMDetractor0.35
06/06/2019JuneCBPromoter0.2
09/03/2019MarchCVPromoter0.4
05/06/2019JuneCVPromoter0.35
03/03/2019MarchCCPromoter0.2
09/06/2019JuneCCPromoter0.1
09/03/2019MarchCMDetractor0.4
05/06/2019JuneCMPromoter0.35
06/03/2019MarchCMPromoter0.4
07/06/2019JuneCMPromoter0.35
03/06/2019JuneCBPromoter0.2
09/03/2019MarchCVPromoter0.4
21/06/2019JuneCVPromoter0.35
22/03/2019MarchCCPromoter0.2

 

 

 

the weighted table is just for explanatory purposes (how the weight change by month)  but it's not my sample data it's just one of the columns.

 

In addition, about your last question, june is that percent because that's the result if you apply the measure x since march till june.

 

category CC:

march  100.00%

june  60.00%

 

that's why in the third table (in my first post) when in the column "cumulative measure x"   says that value, is because i want that the cumulated results by month (march, (march+june), (march+june+september), (march+june+september+december)) are the ones i want to be ponderated with the weights.

 

i hope i have resoult your questions, thanks for the help.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.