Forum Discussion
Adding Measure extends X-Axis...
See below. This project is a distillation of a greater project, so please no out of the box solutions -- such as using visual calculations, visual level filters, or the Analytics features. The solution needs to be in the DAX code.
I have two simple tables as shown below. My 30DayAvg measure is calculating a static last 30 day average regardless of any filters selected. I was able to achieve that, although I had to use nested CALCULATE's. The problem now is, whenever I add it to the line chart, it extends the x-axis to include all dates. I want the horizontal line (purple) to appear only where there are Average Reading values (the variable blue line) -- i.e. only for the dates selected by the date slicer.
Can someone help me with the DAX to achieve this? Thanks!
DAX:
30DayAvg = CALCULATE(
CALCULATE(AVERAGE(Table1[Reading]), ALL(Dates), Table1[DateTime] >= MAX(Table1[DateTime]) - 30),
ALLSELECTED(Table1[DateTime]))
Report:
Data:
your data model is the wrong way round.
Dates should be the dimension table and "Table1" the facts table.
Then do what Ashish_Mathur suggested.
Why is the dark line supposed to be straight? It's an average over 30 days.
By the way, you can do that much simpler with Window functions.
30DayAvg = CALCULATE(AVERAGE(Table1[Reading]), WINDOW(-29,REL,0,rel,ALLSELECTED(Dates[Date])))PBI file attached.
11 Replies
- lbendlinSuper User
calculating a static last 30 day average regardless of any filters selected. I was able to achieve that, although I had to use nested CALCULATE's. The problem now is, whenever I add it to the line chart, it extends the x-axis to include all dates.You removed all filters on the date. But it sounds like you didn't want to do that?
- bvyHelper V
I had to do that to get the average to be correct. Do you see another way?
- lbendlinSuper User
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523
- v-echaithraCommunity Support
Hi bvy ,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.Regards,
Chaithra E. - v-echaithraCommunity Support
Hi bvy ,
May I ask if you have gotten this issue resolved?
If it is solved, please mark the helpful reply or share your solution and accept it as solution, it will be helpful for other members of the community who have similar problems as yours to solve it faster.
Regards,
Chaithra. - v-echaithraCommunity Support
Hi @bvy ,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.Regards,
Chaithra E.