Forum Discussion
Average per month group by
- 3 years ago
Hi, reporter9
Hi,
Thank you for your quick response, I check your dax and find that the reason that causes this issue is that “format” funmction.
Because the “format” function return the “Text” type data , we can not compare the “Text” type data to the “Date” type data. And the other error is that “ _date < _quarter_end”. We can not use the _date as the condition, we need use the ‘Table’[month_date] because we are filtering the ‘Table’.
So in the end , you can try to user this dax:
Average2 = var _phase = SELECTEDVALUE('Table'[Phase]) var _date =VALUES('Table'[Month_Date]) var _quarter_end = DATE( YEAR( TODAY() ), QUARTER( TODAY() ) * 3 + 1, 1 ) - 1 var _duration =SUMX(FILTER( ALLSELECTED('Table'), 'Table'[month_date] in _date && 'Table'[Phase]=_phase) , [Duration]) var _count =COUNTROWS(DISTINCT(SELECTCOLUMNS( FILTER(ALLSELECTED('Table'), 'Table'[month_date] in _date && 'Table'[Month_Date]< _quarter_end ) ,"ID",[ID],"Month_date",[Month_Date]))) return DIVIDE(_duration,_count)Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi , reporter9
Thank you for your quick feedback. Based on the screenshot you provided , i can understand that the issue happens when you try to dill to the quater and show the "sum" not the "average" . The root cause is in my "distinctcount" is wrong .
You can just also update the dax to this:
Average = var _phase = SELECTEDVALUE('Table'[Phase])
var _date =VALUES('Table'[Month_Date])
var _duration =SUMX(FILTER( ALLSELECTED('Table'), 'Table'[month_date] in _date && 'Table'[Phase]=_phase) , [Duration])
var _count =COUNTROWS(DISTINCT(SELECTCOLUMNS( FILTER(ALLSELECTED('Table'),'Table'[month_date] in _date) ,"ID",[ID],"Month_date",[Month_Date])))
return
DIVIDE(_duration,_count)
Then we can meet your need in the end:
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi v-yueyunzh-msft ,
loooks good. Additionally always the current quarter (var _quarter_end) should not be visable. I have 'update' your proposal and I have the issue that with this the visual is blank. Where is my fault?
Thank you.