Forum Discussion
Same calculations on multiple columns
I am new to Power BI desktop and I am trying to conceptually understand the best way to tackle this problem. So I have a table that looks like this:
| Index | FIFO2_1 | FIFO2_2 | FIFO2_3 | FIFO2_4 | FIFO2_5 | FIFO2_6 | FIFO2_7 |
| 0 | 0.097 | 0.096 | 0.101 | 0.096 | 0.191 | 0.187 | 0.098 |
| 1 | 0.096 | 0.094 | 0.099 | 0.094 | 0.188 | 0.184 | 0.096 |
| 2 | 0.094 | 0.093 | 0.098 | 0.093 | 0.185 | 0.182 | 0.095 |
| 3 | 0.093 | 0.092 | 0.097 | 0.092 | 0.184 | 0.180 | 0.094 |
| 4 | 0.093 | 0.091 | 0.096 | 0.091 | 0.182 | 0.179 | 0.094 |
| 5 | 0.092 | 0.090 | 0.095 | 0.091 | 0.181 | 0.178 | 0.093 |
| 6 | 0.091 | 0.090 | 0.095 | 0.090 | 0.179 | 0.177 | 0.092 |
| 7 | 0.091 | 0.089 | 0.094 | 0.090 | 0.178 | 0.176 | 0.092 |
| 8 | 0.090 | 0.088 | 0.094 | 0.089 | 0.177 | 0.175 | 0.091 |
| 9 | 0.089 | 0.088 | 0.093 | 0.089 | 0.176 | 0.174 | 0.091 |
| 10 | 0.089 | 0.087 | 0.092 | 0.088 | 0.175 | 0.173 | 0.091 |
| 11 | 0.088 | 0.087 | 0.092 | 0.088 | 0.174 | 0.173 | 0.090 |
| 12 | 0.088 | 0.086 | 0.091 | 0.087 | 0.173 | 0.172 | 0.090 |
| 13 | 0.088 | 0.086 | 0.091 | 0.087 | 0.172 | 0.171 | 0.089 |
| 14 | 0.087 | 0.086 | 0.091 | 0.086 | 0.171 | 0.171 | 0.089 |
| 15 | 0.087 | 0.085 | 0.090 | 0.086 | 0.170 | 0.170 | 0.089 |
| 16 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 17 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.127 | 0.064 |
| 18 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 19 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 20 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.127 | 0.064 |
| 21 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 22 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 23 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 24 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 25 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 26 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 27 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 28 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 29 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
| 30 | 0.063 | 0.063 | 0.066 | 0.063 | 0.125 | 0.126 | 0.064 |
I want to perform operations that will done on each one of the seven columns. For example, one of the steps I want to perform is taking the average for rows 15-20 for every columns, so it will AVG1, AVG2,....AVG7. Then I will subtract from the average every value in the corresponding column. So for FIFO2_1, if average is AVG1 then the formula will be AVG - Xi (where i ranges from 0-30).
Next, I will search for the index of the highest value for every column, so it will be MAX1, MAX2,..., MAX7. Then I will take the index and get the average of the last 10 points, this again for every column. So you can see it's a sequential process and I am not sure what will be the best way to preform it. It's the same process for every column.
What I did until now is create a measure for every column and then divide the
AverageBetween400and440 =
CALCULATE(
AVERAGE('Table'[FIFO_1_1]),
'Table'[Index] >= 15 && 'Table'[Index] <= 20
)
transformed_FIFI2_1 = VAR X= [AverageBetween400and440] RETURN CALCULATE(X- SUM(Table[FIFO_1_1]))
My plan is to replicate this for every columns but honestly this is not efficient a all and I don't even know how to perform the next steps. Is there a way to automate the process for all the columns?
- Anonymous2 years ago
Ashish_MathurThanks Ashish, I was actually able to solve the problem by pivoting the table in the following way. And then working with rows instead of columns.
Index FIFO2 Value
0 FIFO2_1 0.097 0 FIFO2_2 0.096 0 FIFO2_3 0.101 0 FIFO2_4 0.096 ... ... ... 30 FIFO2_6 0.126 30 FIFO2_7 0.064
Changing the DAX to:AverageBetween400and440 = CALCULATE( AVERAGE('Table'[Value]), 'Table'[Index] >= 15 && 'Table'[Index] <= 20 ) transformed_FIFI2 = [AverageBetween400and440] - SUM('Table'[Value]) Avg Last 10 Max = var maxV = MAX('Table'[Value]) var maxI = CALCULATE(MAX('Table'[Index]), 'Table'[Value] = maxV) RETURN CALCULATE( AVERAGE('Table'[Value]), 'Table'[Index] > maxI - 10 && 'Table'[Index] <= maxI )
2 Replies
- Ashish_MathurSuper User
Hi,
Based on the table that you have shared, show the expected result very clearly. Still better in the secondn tab of an Excel workbook, show your desired result using formulas/pivot tables. Share the download link of the Excel file.
- AnonymousNot applicable
Ashish_MathurThanks Ashish, I was actually able to solve the problem by pivoting the table in the following way. And then working with rows instead of columns.
Index FIFO2 Value
0 FIFO2_1 0.097 0 FIFO2_2 0.096 0 FIFO2_3 0.101 0 FIFO2_4 0.096 ... ... ... 30 FIFO2_6 0.126 30 FIFO2_7 0.064
Changing the DAX to:AverageBetween400and440 = CALCULATE( AVERAGE('Table'[Value]), 'Table'[Index] >= 15 && 'Table'[Index] <= 20 ) transformed_FIFI2 = [AverageBetween400and440] - SUM('Table'[Value]) Avg Last 10 Max = var maxV = MAX('Table'[Value]) var maxI = CALCULATE(MAX('Table'[Index]), 'Table'[Value] = maxV) RETURN CALCULATE( AVERAGE('Table'[Value]), 'Table'[Index] > maxI - 10 && 'Table'[Index] <= maxI )