You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerBI技术问询:如何统计不同课程中的学生人数(去重场景)

Hey there! Let's work through this Power BI problem together—you need to count unique students, right? The key here is making sure someone like Ahmad (who’s taking two courses) only gets counted once, even though they show up twice in your table.

First, let’s map out your example data to make sure we’re on the same page: your table probably looks something like this:

NameCourseAttendance
AhmadMathPresent
AhmadEnglishPresent
SarahMathPresent
JohnSciencePresent

And you want the total unique student count to be 3, not 4. Here are the easiest ways to pull this off in Power BI:

1. Quick Total Unique Student Count (DAX Measure)

If all you need is a single number showing how many unique students you have, create a new Measure with this DAX code:

Unique Student Count = DISTINCTCOUNT('YourTable'[name])

Drop this into a Card visual, and it’ll instantly show 3 for your data—DISTINCTCOUNT automatically ignores duplicate names, so Ahmad only gets counted once.

2. Per-Course Counts + Deduplicated Total

If you want to see how many students are in each course, but also have a total that doesn’t double-count students in multiple courses, use this more flexible measure:

Unique Students per Course = 
VAR CurrentCourse = SELECTEDVALUE('YourTable'[course])
RETURN
IF(
    ISFILTERED('YourTable'[course]),
    COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('YourTable', 'YourTable'[course] = CurrentCourse), "StudentName", [name]))),
    DISTINCTCOUNT('YourTable'[name])
)

Here’s what this does:

  • When you look at a specific course (like Math), it counts the unique students in that course (Ahmad + Sarah = 2)
  • When you view the overall total (no course filter), it shows the deduplicated count of 3 students
3. Bonus: Flag First Enrollment (Calculated Column)

If you want to manually filter out duplicate student entries later, add a Calculated Column:

Is First Enrollment = 
VAR StudentName = [name]
VAR FirstCourse = MINX(FILTER('YourTable', [name] = StudentName), [course])
RETURN
IF([course] = FirstCourse, TRUE(), FALSE())

This marks the first course each student took as TRUE—you can then filter your visuals to only include these rows if you want to avoid duplicates in tables or charts.

Pro Tips:

  • Double-check your name column for typos (like "Ahmad" vs "ahmad")—small inconsistencies will make DISTINCTCOUNT treat them as different students.
  • If you only want to count students who attended, add a filter to your measure or visual for attendance = "Present" (adjust the value to match your data’s attendance label).

内容的提问来源于stack exchange,提问作者hanan alharbi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 17:59:05