简体   繁体   English

Power BI - 如何显示计数的平均值

[英]Power BI - How do I show an average of a count

I have a table showing attendance of students for a town.我有一张表,显示一个城镇的学生出勤率。 There's a row for every student for every day they attended, so if student #1 attended 175 days over the course of the year there are 175 lines for that student, each with the unique date.每个学生在他们参加的每一天都有一行,所以如果学生 #1 在一年中参加了 175 天,那么该学生有 175 行,每行都有唯一的日期。 Each row also contains their name, ID, the date, and what school they were at.每一行还包含他们的姓名、ID、日期和他们就读的学校。 (Elementary, Middle, High School) (小学、初中、高中)

I need a table that shows average count of students in attendance, by Day of week and school - so:我需要一个表格,按星期几和学校显示出勤学生的平均人数 - 所以:

Columns = Day of Week (Monday-Friday)列 = 星期几(星期一至星期五)

Rows = School (Elementary, Middle, High School) So I need a matrix to show that the average attendance for the elementary school on Monday is 110, on Tuesday it's 114, etc. etc. Please help - Rows = School (Elementary, Middle, High School) 所以我需要一个矩阵来显示周一小学的平均出勤率为 110,周二为 114,等等。请帮助 -

My formula is close - but not correct: Ave of Count of ID = AVERAGEX( KEEPFILTERS(VALUES('Attendance'[Date].[Day])), CALCULATE(COUNTA('Attendance'[ID] )))我的公式很接近 - 但不正确: Ave of Count of ID = AVERAGEX( KEEPFILTERS(VALUES('Attendance'[Date].[Day])), CALCULATE(COUNTA('Attendance'[ID] )))

Change VALUES ( Attendance[Date].[Day] ) to VALUES ( Attendance[Date] ) .VALUES ( Attendance[Date].[Day] )更改为VALUES ( Attendance[Date] ) This should be enough to turn your code work.这应该足以让您的代码工作。

Optionally, please consider following for simplicity and better performance.或者,为了简单和更好的性能,请考虑以下。

  • Remove KEEPFILTERS .删除KEEPFILTERS
  • Use COUNTROWS instead of COUNTA .使用COUNTROWS而不是COUNTA
  • Use a calendar table instead of the date column in Attendance table.使用日历表而不是出勤表中的日期列。
Average Attendees Per Day = 
AVERAGEX (
    VALUES ( 'Calendar'[Date] ),
    CALCULATE ( COUNTROWS ( 'Attendance' ) )
)

Given you've mentioned 'Attendance'[Date].[Day] I assume you've got a single table with ID, School, Date (and a hierarchy on Date with the day name?) rather than a dimension/fact table setup.鉴于您已经提到了“出勤”[日期].[天] 我假设您有一个带有 ID、学校、日期的表(以及带有日期名称的日期层次结构?)而不是维度/事实表设置.

In that case you should be able to use the following:在这种情况下,您应该能够使用以下内容:

Avg Days=AVERAGEX(SUMMARIZE(Attendance,Attendance[ID]),CALCULATE(COUNTROWS(Attendance)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM