Forum Discussion
Calculate Non-Rolling 13 Week SUM
- 7 years ago
Hi Anonymous ,
Your formula works fine with the filter on my side, this formula had considered the outer slicers.
Non-rolling 13 WK Confirmation Rate = Var t = ADDCOLUMNS ( ALLSELECTED( 'Table'), "WeekIndex", RANKX ( ALLSELECTED ( 'Table' ),[Week of Year],, DESC ) ) Var i = MAXX ( FILTER ( t , 'Table' [Week of Year] = MAX ('Table' [Week of Year] ) ), [WeekIndex] ) RETURN CALCULATE ( SUM ('Table'[Confirmed Quantity] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) ) / CALCULATE ( SUM ('Table'[Ordered Qty] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) )
BTW, pbix as attached.Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Based on the table you shared, we can use the following measure to meet your requirement:
13 WK Confirmation Rate 2 =
VAR t =
ADDCOLUMNS (
ALLSELECTED ( 'Table2' ),
"WeekIndex", RANKX ( ALLSELECTED ( 'Table2' ), [Week of Year],, DESC )
)
VAR i =
MAXX (
FILTER ( t, 'Table2'[Week of Year] = MAX ( 'Table2'[Week of Year] ) ),
[WeekIndex]
)
RETURN
CALCULATE (
SUM ( 'Table2'[Confirmed Quantity] ),
FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i )
)
/ CALCULATE (
SUM ( 'Table2'[Ordered Qty] ),
FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i )
)
BTW, pbix as attached.
Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi v-lid-msft ,
I've copied your formula to my PBI file and interestingly the 13 Week Confirmation Rate formula is calculating the same result as my YTD Confirmation Rate formula.. See below the formulas, and let me know if you see anything wrong with mine..
YTD Confirmation Rate =
DIVIDE(
SUM(‘table 2’[Confirmed Quantity]),
SUM(‘table 2’[Order Quantity])
)Non-rolling 13 WK Confirmation Rate =
Var t =
ADDCOLUMNS (
ALLSELECTED( ‘table 2’),
"WeekIndex", RANKX ( ALLSELECTED ( ‘table 2’ ),[Week of Year],, DESC )
)
Var i =
MAXX (
FILTER ( t , ‘table 2’ [Week of Year] = MAX (‘table 2’ [Week of Year] ) ),
[WeekIndex]
)
RETURN
CALCULATE (
SUM (‘table 2’ [Confirmed Quantity] ),
FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i )
)
/ CALCULATE (
SUM (‘table 2’ [Order Quantity] ),
FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i )
)
I think the problem might be because I have filters on the report that I didn't previously mention, since I didn't think they would effect the formula.. I have the below slicer filters used on this report.. to help clarify, blue is what the 13 Week Confirmation table should calculate for, and red is what the measure should not calculate for.
Material
Abc123 (filtered on)
Abc234 (filtered out)
Abc345 (filtered out)
Abc456 (filtered out)
Year
2018 (filtered out)
2019 (filtered on)
Are there any filter [material] or [year] formulas I need to add to your formula to make mine work? for example, see below. I thought I could get away with the simplified excel table example, but here it is more complicated.
| Row/Column | A | B | C | D | E |
| 1 | INPUT | ||||
| 2 | Material | Year | Week of Year | Ordered Qty | Confirmed Quantity |
| 3 | abc123 | 2019 | 38 | 1248 | 180 |
| 4 | abc123 | 2019 | 37 | 1008 | 1008 |
| 5 | abc123 | 2019 | 36 | 1308 | 1308 |
| 6 | abc123 | 2019 | 35 | 4839 | 3830 |
| 7 | abc123 | 2019 | 34 | 3926 | 3926 |
| 8 | abc123 | 2019 | 33 | 1572 | 1572 |
| 9 | abc123 | 2019 | 32 | 3380 | 2288 |
| 10 | abc123 | 2019 | 31 | 12 | 12 |
| 11 | abc123 | 2019 | 30 | 72 | 72 |
| 12 | abc123 | 2019 | 29 | 32 | 32 |
| 13 | abc123 | 2019 | 28 | 384 | 384 |
| 14 | abc123 | 2019 | 27 | 1080 | 1080 |
| 15 | abc123 | 2019 | 26 | 444 | 200 |
| 16 | abc123 | 2019 | 25 | 4536 | 1536 |
| 17 | abc123 | 2019 | 24 | 6480 | 432 |
| 18 | abc123 | 2019 | 23 | 8172 | 2124 |
| 19 | abc123 | 2019 | 21 | 333 | 321 |
| 20 | abc123 | 2019 | 17 | 6372 | 1692 |
| 21 | abc123 | 2019 | 16 | 1620 | 0 |
| 22 | abc123 | 2019 | 15 | 1884 | 716 |
| 23 | abc123 | 2019 | 14 | 1752 | 1752 |
| 24 | abc123 | 2019 | 13 | 1600 | 300 |
| 25 | abc123 | 2019 | 12 | 1368 | 1368 |
| 26 | abc123 | 2019 | 11 | 180 | 180 |
| 27 | abc123 | 2019 | 2 | 648 | 648 |
| 28 | abc123 | 2019 | 1 | 33 | 20 |
| 29 | ABc234 | 2018 | 38 | 568 | 526 |
| 30 | ABc234 | 2018 | 37 | 468 | 300 |
| 31 | ABc234 | 2018 | 36 | 686 | 552 |
| 32 | ABc234 | 2018 | 35 | 989 | 900 |
| 33 | ABc234 | 2018 | 34 | 4522 | 4500 |
Appreciate the help.. very close to solving this problem.
Kordel
- v-lid-msft7 years ago
Community Support
Hi Anonymous ,
Your formula works fine with the filter on my side, this formula had considered the outer slicers.
Non-rolling 13 WK Confirmation Rate = Var t = ADDCOLUMNS ( ALLSELECTED( 'Table'), "WeekIndex", RANKX ( ALLSELECTED ( 'Table' ),[Week of Year],, DESC ) ) Var i = MAXX ( FILTER ( t , 'Table' [Week of Year] = MAX ('Table' [Week of Year] ) ), [WeekIndex] ) RETURN CALCULATE ( SUM ('Table'[Confirmed Quantity] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) ) / CALCULATE ( SUM ('Table'[Ordered Qty] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) )
BTW, pbix as attached.Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - v-lid-msft7 years ago
Community Support
Hi Anonymous ,
How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?
Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- Anonymous7 years agoNot applicable
Hi v-lid-msft ,
Unfortunately your formula in the original and secondary post have not brought me to the same solution as you got in your .pbix file. I'm not sure what else could be the cause of my formula not working.. given that I copied every detail of your formula over to my own file.. I'm not sure what else could be wrong. Could you please walk me through the logic behind how you came to this formula as the answer? I don't understand how RANKX, ADDCOLUMNS, and ALLSELECTED are used to find the result.
Perhaps there's a different way to write the formula that I could try? apologies for the lack of detail on how to move forward..
Thanks,
Kordel
- v-lid-msft7 years ago
Community Support
Hi Anonymous ,
Sure, we will make explatnation of following formula:
Non-rolling 13 WK Confirmation Rate = Var t = ADDCOLUMNS ( ALLSELECTED( 'Table'), "WeekIndex", RANKX ( ALLSELECTED ( 'Table' ),[Week of Year],, DESC ) ) Var i = MAXX ( FILTER ( t , 'Table' [Week of Year] = MAX ('Table' [Week of Year] ) ), [WeekIndex] ) RETURN CALCULATE ( SUM ('Table'[Confirmed Quantity] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) ) / CALCULATE ( SUM ('Table'[Ordered Qty] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) )The first part, we use ALLSELECTED function to get a table which infused by outer slicer, but ignore the row-level content (such as each rows in table visual)
then we add a addtion column to this table, containing a rank index value based on the week of year, such as week 5, 4, 2 will get a rank by 1,2,3
we put the result table into a variable called "t"
Var t = ADDCOLUMNS ( ALLSELECTED( 'Table'), "WeekIndex", RANKX ( ALLSELECTED ( 'Table' ),[Week of Year],, DESC ) )Then we want to get the rank index value of now selected date (such as one row in table visual),
we use Max to get the current week value, then use it to find the index value in the table t
MAXX function is used to get the value from a variable table. (After filter the table t, it will ony return several rows contain same week number, they all have same index value)
Var i = MAXX ( FILTER ( t , 'Table' [Week of Year] = MAX ('Table' [Week of Year] ) ), [WeekIndex] )Now, we have the week index value of current week and a table contain the week index column. we can use the sum function to get value from a filtered table, just use the condition index in greater than current but lessthan than current index plus 12
CALCULATE ( SUM ('Table'[Confirmed Quantity] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) ) / CALCULATE ( SUM ('Table'[Ordered Qty] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) )Now the logic of this formula is clear, We think the problem may be in the variable i, could you please try to use the following formula?
Non-rolling 13 WK Confirmation Rate Version 2 = VAR t = ADDCOLUMNS ( ALLSELECTED ( 'Table' ), "WeekIndex", RANKX ( ALLSELECTED ( 'Table' ), [Week of Year],, DESC ) ) VAR i = RANKX ( ALLSELECTED ( 'Table' ), CALCULATE ( MAX ( [Week of Year] ) ),, DESC ) RETURN CALCULATE ( SUM ('Table'[Confirmed Quantity] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) ) / CALCULATE ( SUM ('Table'[Ordered Qty] ), FILTER ( t, [WeekIndex] <= i + 12 && [WeekIndex] >= i ) )Also do not forget to format this measure as a percentage value.
BTW, pbix as attached.Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.