Forum Discussion
DAX Measure for Ranking the valid rows and calculating the average rating
- 4 months ago
Hi SRHR
Can you try these
Rank Valid Measure =
VAR LearningDate = SELECTEDVALUE(Attendance[Learning Date])
VAR Email = SELECTEDVALUE(Attendance[Email])
VAR FormKey = SELECTEDVALUE(Attendance[Form Key])
RETURN
IF(SELECTEDVALUE(Attendance[Status]) = "Completed" &&CALCULATE(
COUNTROWS(Survey),
FILTER(
Survey,
Survey[Email] = Email &&
Survey[Form Key] = FormKey &&
Survey[Survey Date] >= LearningDate &&
Survey[Survey Date] <= LearningDate + 2
) ) > 0,1,0)
Avg Rating Measure =
AVERAGEX(FILTER(
Survey,
VAR MatchLearningDate =
CALCULATE(MAX(Attendance[Learning Date]),
FILTER(
Attendance,
Attendance[Email] = Survey[Email] &&
Attendance[Form Key] = Survey[Form Key] && Attendance[Status] = "Completed"))
RETURN
NOT ISBLANK(MatchLearningDate) && Survey[Survey Date] >= MatchLearningDate &&
Survey[Survey Date] <= MatchLearningDate + 2),
Survey[Rating])
- 4 months ago
I understand the challenge of linking survey responses without a clear identifier.
Valid Survey Rank = CALCULATE ( COUNTROWS ( Survey ), FILTER ( Survey, Survey[Email] = EARLIER ( Attendance[Email] ) && Survey[Form Key] = EARLIER ( Attendance[Form Key] ) && Survey[Survey Date] > Attendance[Learning Date] ) )This formula counts survey responses where the date is after the learning date for the same email and form.
Hola
the best approach is to do this in Power Query rather than DAX, create a custom column in Attendance that looks up matching survey rows by Email + Form Key within the date window. But if you want to keep it in DAX, here's an average rating measure:
daxAvg Valid Rating =
VAR LearningDate = MAX(Attendance[Learning Date])
VAR FormKey = MAX(Attendance[Form Key])
VAR ValidSurveys =
FILTER(
Survey,
Survey[Form Key] = FormKey
&& Survey[Survey Date] >= LearningDate
&& Survey[Survey Date] <= LearningDate + 2
&& Survey[Email] IN
CALCULATETABLE(
VALUES(Attendance[Email]),
Attendance[Status] = "Completed",
Attendance[Learning Date] = LearningDate,
Attendance[Form Key] = FormKey
)
)
RETURN
AVERAGEX(ValidSurveys, Survey[Rating])