Forum Discussion
Power Bi forecast line chart
Hi there,
I am looking for power consumption per period chart but with filter on
values from Tool column (Tools names are never the same).
Power consumption for periods 5,6,7 should be a prediction based on the previous values.
Period 5 should be avg of values for period 4,3,2 in this case "(21 + 5 + 60) / 3"
Period 6 = avg for 4 last periods; Period 7 = avg for 5 previous periods if exists
Can power bi do anything like that?
| date | Period | Tool | power consumption per period |
| 12-Jun | 1 | A | 20 |
| 15-Jun | 1 | B | 20 |
| 05-Jul | 2 | C | 60 |
| 31-Jul | 3 | D | 5 |
| 03-Aug | 4 | E | 21 |
| 04-Aug | 4 | F | 21 |
| 5 | |||
| 6 | |||
| 7 |
Hi,
The Dax I created was for a measure. If you want to use it in a calculated column it needs to be a bit different. Actually in this case I recommend using a calculated table:Period Value =var selection = 5var vartable = SUMMARIZE(FILTER(all('Table (2)'),'Table (2)'[Period]>=2 && 'Table (2)'[Period]<5),'Table (2)'[Period],'Table (2)'[power consumption per period],'Table (2)'[Tool]) //Here I take the previous periods values into a variable tablevar averagevar = AVERAGEX(vartable,'Table (2)'[power consumption per period]) //Calculate average for the previous periods (28.67)var vartable2 = Union(vartable,{("5",averagevar,"")}) //create another var table with the previous valuevar averagevar2 = AVERAGEX(vartable2,'Table (2)'[power consumption per period]) //again calculate average it is the same since we have one more row and the perious value are otherwise the samevar vartable3 = union(vartable2,{("6",averagevar2,"")})var averagevar3 = AVERAGEX(vartable3,'Table (2)'[power consumption per period]) //same as previous stepvar vartable4 =union(vartable3,{("7",averagevar3,"")})returnvartable4 //select value depending on the row valueHowever, If there isn't any specific reason to use a calculated column you can just use the measure version.
6 Replies
- ValtteriN
Community Champion
Hi,
Here is one way to do this:Period Value =var selection = SELECTEDVALUE('Table (2)'[Period])var vartable = SUMMARIZE(FILTER(all('Table (2)'),'Table (2)'[Period]>=2 && 'Table (2)'[Period]<5),'Table (2)'[Period],'Table (2)'[power consumption per period]) //Here I take the previous periods values into a variable tablevar averagevar = AVERAGEX(vartable,'Table (2)'[power consumption per period]) //Calculate average for the previous periods (28.67)var vartable2 = Union(vartable,{("5",averagevar)}) //create another var table with the previous valuevar averagevar2 = AVERAGEX(vartable2,'Table (2)'[power consumption per period]) //again calculate average it is the same since we have one more row and the perious value are otherwise the samevar vartable3 = union(vartable2,{("6",averagevar2)})var averagevar3 = AVERAGEX(vartable3,'Table (2)'[power consumption per period]) //same as previous stepreturnSWITCH(TRUE(),selection=5,averagevar,selection=6,averagevar2,selection=7,averagevar3) //select value depending on the row value
I hope this helps and if it does consider accepting this post as a solution!- AnonymousNot applicable
Hi ValtteriN,
thanks for your time. Does not work for me?
any idea why it does not show values ?
- ValtteriN
Community Champion
Hi,
The Dax I created was for a measure. If you want to use it in a calculated column it needs to be a bit different. Actually in this case I recommend using a calculated table:Period Value =var selection = 5var vartable = SUMMARIZE(FILTER(all('Table (2)'),'Table (2)'[Period]>=2 && 'Table (2)'[Period]<5),'Table (2)'[Period],'Table (2)'[power consumption per period],'Table (2)'[Tool]) //Here I take the previous periods values into a variable tablevar averagevar = AVERAGEX(vartable,'Table (2)'[power consumption per period]) //Calculate average for the previous periods (28.67)var vartable2 = Union(vartable,{("5",averagevar,"")}) //create another var table with the previous valuevar averagevar2 = AVERAGEX(vartable2,'Table (2)'[power consumption per period]) //again calculate average it is the same since we have one more row and the perious value are otherwise the samevar vartable3 = union(vartable2,{("6",averagevar2,"")})var averagevar3 = AVERAGEX(vartable3,'Table (2)'[power consumption per period]) //same as previous stepvar vartable4 =union(vartable3,{("7",averagevar3,"")})returnvartable4 //select value depending on the row valueHowever, If there isn't any specific reason to use a calculated column you can just use the measure version.