Forum Discussion
Calculating differences between multiple columns and then the median of these values
Hi
I have been asked to calculate the following three stage exercise:
- Calculate the differences between the weekly data in the table below
- Calculate the median of those weekly differences for a specific week
- Calculate the movement in the median of weekly differences compared to the previous week
The above is an ongoing exercise each week so I suspect use of variable will be necessary.
| Week 1 | Week 2 | Week 3 | Week 4 | Week 5 | Week 6 | Week 7 | |
| Worms | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| Overcooked | 11 | 23 | 45 | 67 | 43 | 54 | 56 |
| The Survivalists | 34 | 54 | 43 | 45 | 67 | 54 | 56 |
I appreciate I could just do the calculations in excel and upload the weekly differences but believe there will be a solution just in Power BI.
- NickTeam17
I suggest you unpivot this data, which is done in the Power Query Editor.
So to make it as dynamic as possible select all the columns that are NOT weeks, then select Unpivot Other Columns..
Then you will have two columns: Attribute and Value. Rename Attribute to Week Number and Value to whatever you want.
When you've got that under control, come back and see us if you need more help with calculating the average, difference and filtering by week, but this will be more straightforward once it's in columns.
https://radacad.com/pivot-and-unpivot-with-power-bi
2 Replies
- AllisonKennedyCommunity ChampionNickTeam17
I suggest you unpivot this data, which is done in the Power Query Editor.
So to make it as dynamic as possible select all the columns that are NOT weeks, then select Unpivot Other Columns..
Then you will have two columns: Attribute and Value. Rename Attribute to Week Number and Value to whatever you want.
When you've got that under control, come back and see us if you need more help with calculating the average, difference and filtering by week, but this will be more straightforward once it's in columns.
https://radacad.com/pivot-and-unpivot-with-power-bi - amitchandakSuper User
NickTeam17 , either transpose or unpivot
https://radacad.com/pivot-and-unpivot-with-power-bi
Transpose : https://yodalearning.com/tutorials/power-query-helps-transposing-data/Create a week table and join week in this table (use Rank logic blog to deal with weeks)
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