Forum Discussion
Line Chart Legend Rolling Average
- Anonymous1 year ago
Hi vjr37 ,
If you want to add [Name] in Legend and display two lines based on Name, I suggest you to update code as below.
RollingMean6Months = VAR CurrentDate = MAX ( 'Charge'[Date] ) VAR SixMonthsAgo = EDATE ( CurrentDate, -6 ) RETURN AVERAGEX ( FILTER ( ALL( 'Charge'), Charge[Name] = MAX(Charge[Name]) && 'Charge'[Date] <= CurrentDate && 'Charge'[Date] > SixMonthsAgo ), 'Charge'[Value] )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- 1 year ago
Hi,
One of ways is to have dimension tables for date and company, and create one to many relationship to the fact table, that looks something like below.
Please check the below picture and the attached pbix file.
WINDOW function (DAX) - DAX | Microsoft Learn
sales 6 months rolling avg: = VAR _t = WINDOW ( -5, REL, 0, REL, ALL ( calendar_dim[Year-Month], calendar_dim[Year-Month sort] ), ORDERBY ( calendar_dim[Year-Month sort], ASC ) ) RETURN IF ( SUM ( sales_fact[value] ), AVERAGEX ( _t, CALCULATE ( SUM ( sales_fact[value] ) ) ) )
Hi,
One of ways is to have dimension tables for date and company, and create one to many relationship to the fact table, that looks something like below.
Please check the below picture and the attached pbix file.
WINDOW function (DAX) - DAX | Microsoft Learn
sales 6 months rolling avg: =
VAR _t =
WINDOW (
-5,
REL,
0,
REL,
ALL ( calendar_dim[Year-Month], calendar_dim[Year-Month sort] ),
ORDERBY ( calendar_dim[Year-Month sort], ASC )
)
RETURN
IF (
SUM ( sales_fact[value] ),
AVERAGEX ( _t, CALCULATE ( SUM ( sales_fact[value] ) ) )
)
- vjr371 year agoRegular Visitor
This also worked as well. I'd say this method follows appropriate standard practice too. Thanks for the help