Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I have a Tableau expression that I would like to convert into DAX.
PREVIOUS_VALUE(0)+
MIN(
WINDOW_AVG(SUM([values]),-365-[Days Average],-365+[Days Average]),
WINDOW_AVG(SUM([values]),-730-[Days Average],-730+[Days Average])
)
Hi, @MAwwad ,
1) In the first part of the query I get the following error message:
"The first argument of EARLIER/EARLIEST is not a valid column reference in the earlier row context.", - related to this row, MAX('Table'[Date]) = EARLIER(MAX('Table'[Date])) .
2) Also, I am not sure whwther WINDOWAVG function is avaialble, unless it is possible to combine WINDOW and AVERAGE somehow?
Hello!
Regarding your first question, the error message suggests that the column reference 'Table'[Date] is not valid in the context of the EARLIER function. This can happen if the EARLIER function is being used in a calculated column, and the column reference is not part of the column being calculated.
To resolve this issue, you can try using a measure instead of a calculated column, which allows you to refer to columns outside of the current row context. You can define a measure using the CALCULATE function, and then use the MAXX function to calculate the maximum date within the current filter context. Here's an example:
This measure calculates the maximum date for each category in the 'Table' table, by filtering the table to only include rows with the same category as the current row context.
Regarding your second question, the WINDOWAVG function is not a built-in function in DAX. However, you can use the AVERAGEX function along with a FILTER function to calculate a moving average over a specified window of rows. Here's an example:
This measure calculates a 7-day moving average for the 'Value' column in the 'Table' table, by filtering the table to include only rows with a date within the last 7 days, relative to the current row context.
I hope this helps! Let me know if you have any further questions.
Cumulative Rolling Average =
VAR PrevValue =
CALCULATE(
SUM([values]),
FILTER(
ALLSELECTED(),
MAX('Table'[Date]) = EARLIER(MAX('Table'[Date]))
)
)
RETURN
PrevValue +
MINX(
{
CALCULATE(
WINDOWAVG(SUM([values]), -365 - [Days Average], -365 + [Days Average])
),
CALCULATE(
WINDOWAVG(SUM([values]), -730 - [Days Average], -730 + [Days Average])
)
},
[Cumulative Rolling Average]
)
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
7 | |
7 | |
6 | |
6 |
User | Count |
---|---|
27 | |
12 | |
10 | |
9 | |
6 |