0bb5ea697e61dd5e31fb0096ab5be982678ee8f2
15-dot-3-Advanced-Expressions.md
| ... | ... | @@ -5,9 +5,7 @@ |
| 5 | 5 | We can use arithmetic to get a percentage of one value compared to an aggregate value. |
| 6 | 6 | |
| 7 | 7 | **The following expression determines the percentage of an order’s cost paid for shipping:** |
| 8 | -``` |
|
| 9 | -([Orders].[Freight])/(([Order Details].[UnitPrice]) * ([Order Details].[Quantity])+([Orders].[Freight])) |
|
| 10 | -``` |
|
| 8 | +``([Orders].[Freight])/(([Order Details].[UnitPrice]) * ([Order Details].[Quantity])+([Orders].[Freight]))`` |
|
| 11 | 9 | |
| 12 | 10 |  |
| 13 | 11 | |
| ... | ... | @@ -21,11 +19,9 @@ However, this is where we encounter a limitation on expressions. The above expr |
| 21 | 19 | |
| 22 | 20 | If we break the total equation into steps, the problem becomes clearer: |
| 23 | 21 | |
| 24 | -1): Calculate UnitPrice*Quantity for each ProductID within an OrderID. |
|
| 25 | - |
|
| 26 | -2): Sum these calculated values into a hypothetical TotalUnitPrice for the OrderID. |
|
| 27 | - |
|
| 28 | -3): Add Freight to TotalUnitPrice and divide Freight by this value to get a percentage freight cost of total order cost. |
|
| 22 | +1. Calculate UnitPrice*Quantity for each ProductID within an OrderID. |
|
| 23 | +2. Sum these calculated values into a hypothetical TotalUnitPrice for the OrderID. |
|
| 24 | +3. Add Freight to TotalUnitPrice and divide Freight by this value to get a percentage freight cost of total order cost. |
|
| 29 | 25 | |
| 30 | 26 | Since expressions cannot create fields, but only display calculations based on fields, expressions cannot execute step 2. Steps 1 and 2 should be calculated in a view, which would create a computed column that can be used in an expression for step 3. |
| 31 | 27 |