while I was setting up my visual page on PowerBI, I came across a weird issue to address with. I was trying to calculate an average of some values which came togheter with their dates (date) in tableA.
More precisely, tableA has a date field and a numeric feature (feature) and there might be more values for the same date. In addition, the data field points to another data field in a common calendar table (calendarTable). I would like to calculate an average of 'feature' (let's say, the daily average).
To achieve this, I've tried to calculate a new measure as stated here:
Average = CALCULATE(
AVERAGE('tableA'[feature]),
USERELATIONSHIP('tableA'[date], 'calendarTable'[date]),
GROUPBY(date, 'calendarTable'[date])
)
What I got is a 'cumulative' average instead of a daily average. In other terms, for each date the set of values to be averaged increases, including the previous values.
I've also tried to perform the calculation in SQL with success (in DAX there is no need to refer to tableB as I used a calculated column):
SELECT
CAST(a.Date AS Date) AS Dates,
AVG(DATEDIFF(MINUTE, b.Date, a.Date)) AS AVG_DURATION
FROM
tableB AS b
INNER JOIN
tableA AS a
ON
a.ID = b.ID
GROUP BY
CAST(a.Date AS Date)
ORDER BY
Dates ASC;
Does anyone have an idea on how to get in DAX the same result as in SQL? I've already tried to apply some filters on dates but with no luck.
Thanks.