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
Anonymous
Not applicable

Percentage of order type measure / calculation per week

Dear all,

 

I've been googling for quite a while but have not really found a solution yet for a problem I'm trying to resolve. I was hoping somebody could help me out to get a better understanding how to setup specific calculations in PowerBI.

 

I have a dataset for which I would like to calculate the following things:

 

1.  Per week the percentage of ordertype count with the following formula:

     Total of ordertype a / (total ordertype b + c + a)

     e.g. wk 1 = (3a)/(b+c+3a) = 60%;

            wk 2 = a / (b+c+a) = 33.3%

2.  Per week the percentage of ordercost with the following formula:

     Total of ordercost a / (total ordercost b + c + a)

     e.g.  wk 1 = 430 / (50+20+10+400+20) = 86%;
             wk 2 = 130 / (140 +154 + 130)  = 31%

 

Dataset:

WeekOrdertypeCost
1a $        10.00
1b $        50.00
1c $        20.00
1a $      400.00
1e $        40.00
1a $        20.00
2a $      130.00
2b $      140.00
2c $      154.00
2e $      50.00
2d $      35.00
2d $      62.00
3a $      198.57
3b $      210.00
3c $        50.00
3c $      232.86
3d $      244.29
3e $        60.00
4f $      267.14
4a $      278.57
4b $      290.00
4b $      301.43
4c $      312.86
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try a measure like

divide(calculate(sum(Table[Cost]), filter(Table, table[Ordertype] ="a")), calculate(sum(Table[Cost]), filter(Table, table[Ordertype] in {"a","b","c")))

 

or


divide(calculate(sum(Table[Cost]), filter(all(Table), table[Ordertype] ="a")), calculate(sum(Table[Cost]), filter(all(Table), table[Ordertype] in {"a","b","c")))

 

 

for WOW, use these measure with code WOW in this blog

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

View solution in original post

3 REPLIES 3
Msta
Helper I
Helper I

If you want to display in one Table both measures (current type/ total of all type from this week) slicing by week/type:

percentage of ordertype =
var __currentType = SELECTEDVALUE(Sheet2[Ordertype])
var __CountOfCurrent = CALCULATE(COUNTROWS(Sheet2), Sheet2[Ordertype] = __currentType)
var __CountOfAll = CALCULATE(COUNTROWS(Sheet2), ALL(Sheet2[Ordertype]))

return

DIVIDE(__CountOfCurrent, __CountOfAll)


SUM of Cost % =
var __currentType = SELECTEDVALUE(Sheet2[Ordertype])
var __CountOfCurrent = CALCULATE(SUM(Sheet2[Cost]), Sheet2[Ordertype] = __currentType)
var __CountOfAll = CALCULATE(SUM(Sheet2[Cost]), ALL(Sheet2[Ordertype]))

return

DIVIDE(__CountOfCurrent, __CountOfAll)

 

Msta_0-1623141200471.png

 

amitchandak
Super User
Super User

@Anonymous , Try a measure like

divide(calculate(sum(Table[Cost]), filter(Table, table[Ordertype] ="a")), calculate(sum(Table[Cost]), filter(Table, table[Ordertype] in {"a","b","c")))

 

or


divide(calculate(sum(Table[Cost]), filter(all(Table), table[Ordertype] ="a")), calculate(sum(Table[Cost]), filter(all(Table), table[Ordertype] in {"a","b","c")))

 

 

for WOW, use these measure with code WOW in this blog

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

Anonymous
Not applicable

Thanks, this was exactly what I was looking for!

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.