Forum Discussion
Average YoY changes by Year Selection
To calculate the average year-over-year (YoY) changes based on the year selection in Power BI and display it as a single DAX formula, you can use the following approach. You'll need to create a measure that calculates the YoY change for each year, and then another measure to calculate the average of these YoY changes. Here's how you can do it:
Step 1: Create a Measure for YoY Changes
First, create a measure that calculates the YoY change for each year. You can use the following DAX formula for this measure:
```DAX
YoY Change =
VAR SelectedYear = MAX('All '[Start Date].[Year])
VAR PreviousYear = SelectedYear - 1
RETURN
CALCULATE(
SUM('Scores by Questions'[Scores Changes YoY]),
'All '[Start Date].[Year] = SelectedYear
) - CALCULATE(
SUM('Scores by Questions'[Scores Changes YoY]),
'All '[Start Date].[Year] = PreviousYear
)
```
This measure calculates the difference between the sum of "Scores Changes YoY" for the selected year and the previous year.
Step 2: Create a Measure for Average YoY Changes
Now, create a measure to calculate the average YoY change based on the year selection. You can use the following DAX formula for this measure:
```DAX
Average YoY Change =
VAR SelectedYear = MAX('All '[Start Date].[Year])
VAR TotalYears = COUNTROWS(ALL('All '[Start Date].[Year]))
RETURN
DIVIDE(
SUMX(
VALUES('All '[Start Date].[Year]),
[YoY Change]
),
TotalYears
)
```
This measure calculates the sum of YoY changes for all years and then divides it by the total number of years.
Step 3: Display the Average YoY Change
Now, you can use the "Average YoY Change" measure in your visualization to display the average YoY change based on the selected year. When you select a specific year in your slicer or filter, this measure will dynamically calculate and display the correct average YoY change.
By following these steps, you can compute the average YoY changes as a single DAX formula and display it based on the year selection in your Power BI report.