Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
We have a single table of students with test scores. Columns include createdon (the date the test is taken), testscore, and contactid. We want to create a visual that displays the average first test score and the average most recent test score by all students, so that we can show improvements in test scores by students that take our course. Here's a few conditions.
Here's some example data to help.
testid | contactid | createdon | testscore |
1 | A | January 2, 2021 | 60 |
2 | B | January 2, 2021 | 87 |
3 | C | January 2, 2021 | 70 |
4 | A | February 1, 2021 | 68 |
5 | A | February 3, 2021 | 96 |
6 | B | February 5, 2021 | 80 |
7 | B | February 15, 2021 | 99 |
So, if the date slicer for the page has start date of January 1, 2021 and an end date of February 14, 2021, we only want the following values to be in the calculation we run....
testid | contactid | createdon | testscore |
1 | A | January 2, 2021 | 60 |
2 | B | January 2, 2021 | 87 |
5 | A | February 3, 2021 | 96 |
6 | B | February 5, 2021 | 80 |
....where we get the average of the earliest pairs of scores ((60+87)/2 = 73.5) and we get the average of the latest test scores ((96+80)/2 = 88) to be our sought after values.
Any hints or ideas on how I can get from here to there? We're trying to do this with DirectQuery, but if we need to use Import, we can make the switch. Thanks so much in advance!
Solved! Go to Solution.
@blueandgold Hmm. Well, since there is a date slicer involved probably better be a measure. Maybe something like the following:
Measure Min Date Average =
VAR __Contacts =
SELECTCOLUMNS(
FILTER(SUMMARIZE('Table',[contactid],"__Count",COUNTROWS('Table')),[__Count] > 1),
"__contactid",[contactid]
)
VAR __Table =
ADDCOLUMNS(
ADDCOLUMNS(
SELECTCOLUMNS(
FILTER('Table',[contactid] IN __Contacts),
"__contactid",[contactid],
),
"__Date" = MINX(FILTER('Table','Table'[contactid]=[__contactid]),[createdon])
),
"__Score",MINX(FILTER('Table','Table'[contactid] = [__contactid] && [createdon] = [__Date]
)
RETURN
AVERAGEX(__Table,[__Score])
Measure Max Date Average =
VAR __Contacts =
SELECTCOLUMNS(
FILTER(SUMMARIZE('Table',[contactid],"__Count",COUNTROWS('Table')),[__Count] > 1),
"__contactid",[contactid]
)
VAR __Table =
ADDCOLUMNS(
ADDCOLUMNS(
SELECTCOLUMNS(
FILTER('Table',[contactid] IN __Contacts),
"__contactid",[contactid],
),
"__Date" = MAXX(FILTER('Table','Table'[contactid]=[__contactid]),[createdon])
),
"__Score",MAXX(FILTER('Table','Table'[contactid] = [__contactid] && [createdon] = [__Date]
)
RETURN
AVERAGEX(__Table,[__Score])
@blueandgold Hmm. Well, since there is a date slicer involved probably better be a measure. Maybe something like the following:
Measure Min Date Average =
VAR __Contacts =
SELECTCOLUMNS(
FILTER(SUMMARIZE('Table',[contactid],"__Count",COUNTROWS('Table')),[__Count] > 1),
"__contactid",[contactid]
)
VAR __Table =
ADDCOLUMNS(
ADDCOLUMNS(
SELECTCOLUMNS(
FILTER('Table',[contactid] IN __Contacts),
"__contactid",[contactid],
),
"__Date" = MINX(FILTER('Table','Table'[contactid]=[__contactid]),[createdon])
),
"__Score",MINX(FILTER('Table','Table'[contactid] = [__contactid] && [createdon] = [__Date]
)
RETURN
AVERAGEX(__Table,[__Score])
Measure Max Date Average =
VAR __Contacts =
SELECTCOLUMNS(
FILTER(SUMMARIZE('Table',[contactid],"__Count",COUNTROWS('Table')),[__Count] > 1),
"__contactid",[contactid]
)
VAR __Table =
ADDCOLUMNS(
ADDCOLUMNS(
SELECTCOLUMNS(
FILTER('Table',[contactid] IN __Contacts),
"__contactid",[contactid],
),
"__Date" = MAXX(FILTER('Table','Table'[contactid]=[__contactid]),[createdon])
),
"__Score",MAXX(FILTER('Table','Table'[contactid] = [__contactid] && [createdon] = [__Date]
)
RETURN
AVERAGEX(__Table,[__Score])
@Greg_Deckler thank you so much for the detailed solution! When implementing this, I'm getting the following error for the Measure Max Date Average:
Argument '4' in SELECTCOLUMNS function is required.
Any idea what I might be missing?
@blueandgold Likely missing an ending ) somewhere. Perhaps try running the code through daxformatter.com to find the issue.
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
7 | |
5 | |
4 | |
3 |
User | Count |
---|---|
12 | |
11 | |
10 | |
9 | |
8 |