Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tableau api Tableau-计算日期小于其他数据源的值的平均值_Tableau Api - Fatal编程技术网

Tableau api Tableau-计算日期小于其他数据源的值的平均值

Tableau api Tableau-计算日期小于其他数据源的值的平均值,tableau-api,Tableau Api,我试图计算Tableau中一列的平均值,但问题是我试图使用来自另一个数据源的单个日期值(基于过滤器)仅计算考试日期为的平均值。我无法下载您的文件以使用您的数据进行测试,但尝试颠倒取平均值的顺序 平均值(IF DATE(ATTR([examing DATE]))我可以通过使用自定义SQL将表连接在一起并根据我的条件计算平均值来解决这个问题,以获得我想要的列结果 如果能在Tableau中直接使用这种功能,那就太好了,但不管怎样,都能完成任务 编辑: 选择 [学年] ,[学科] --获取学生人数 ,计

我试图计算Tableau中一列的平均值,但问题是我试图使用来自另一个数据源的单个日期值(基于过滤器)仅计算考试日期为的平均值。我无法下载您的文件以使用您的数据进行测试,但尝试颠倒取平均值的顺序


平均值(IF DATE(ATTR([examing DATE]))我可以通过使用自定义SQL将表连接在一起并根据我的条件计算平均值来解决这个问题,以获得我想要的列结果

如果能在Tableau中直接使用这种功能,那就太好了,但不管怎样,都能完成任务

编辑:

选择
[学年]
,[学科]
--获取学生人数
,计数([Id])为[学生(N)]
--获取原始分数的平均值
,将(平均分数(RawScore)作为十进制(10,2))转换为[学校平均值]
--根据“调整分数”列获取失败次数
,将([AdjustedScore]<70然后1结束)计算为[School Failures]
--这是用作包含分数的截止点的列
,[Average_Update]。[Update]
来自[dbo]。[平均值][平均值]
完全外部联接[dbo].[Average\u Update][Average\u Update]在([Average\u Update].[Id]=[Average].UpdateDateId)上
--连接数据以实现精确计算的关键
完全外接(
选择不同的S.[Id]、S.[LastName]、S.[FirstName]、S.[ExamDate]、S.[RawScoreStandard]、S.[RawScorePercent]、S.[AdjustedScore]、S.[Subject]、P.[Id]作为周期Id
来自[StudentScore]S
完全外接
(
--只有第一次尝试
选择不同的[NBOMEId],S2.[Subject],MIN([ExamDate])作为ExamDate
来自[StudentScore]S2
分组依据[NBOMEId],S2。[受试者]
)B
关于S.[NBOMEId]=B.[NBOMEId]和S.[Subject]=B.[Subject]和S.[ExamDate]=B.[ExamDate]
--根据另一个表中包含开始和结束日期的时段列表,将“考试时段”分组。
完全外连接[ExamPeriod]P

关于S.[ExamDate]=P.PeriodStart和S.[ExamDate]谢谢。我尝试了不同的变体,但最终发现了一个常见错误:“avg(聚合函数)的参数已经是一个聚合,无法进一步聚合。”使用以下公式:avg(如果日期(ATTR([Exam DATE])测试分数)][Updated]),然后ATTR([Raw Score])(完)谢谢。我在上面的SQL代码示例中添加了我们喜欢的方式chrish:p
IF DATE(ATTR([Exam Date])) <= DATE(ATTR([Averages (Tableau Test Scores)].[Updated])) THEN AVG([Raw Score]) END

IF DATEDIFF('day', DATE(ATTR([Exam Date])), DATE(ATTR([Averages (Tableau Test Scores)].[Updated]))) > 1 THEN AVG([Raw Score]) END
SELECT AVG([Raw Score]) WHERE ExamDate <= (Filtered Exam Date)
SELECT 
[AcademicYear]
,[Discipline]
--Get the number of student takers
,COUNT([Id]) AS [Students (N)]
--Get the average of the Raw Score
,CAST(AVG(RawScore) AS DECIMAL(10,2)) AS [School Mean]
--Get the number of failures based on an "adjusted score" column
,COUNT([AdjustedScore] < 70 THEN 1 END) AS [School Failures]
--This is the column used as the cutoff point for including scores
,[Average_Update].[Updated]
FROM [dbo].[Average] [Average]

FULL OUTER JOIN [dbo].[Average_Update] [Average_Update] ON ([Average_Update].[Id] = [Average].UpdateDateId)

--The meat of joining data for accurate calculations
FULL OUTER JOIN (
SELECT DISTINCT S.[Id], S.[LastName], S.[FirstName], S.[ExamDate], S.[RawScoreStandard], S.[RawScorePercent], S.[AdjustedScore], S.[Subject], P.[Id] AS PeriodId
FROM [StudentScore] S
FULL OUTER JOIN
(
--Get only the 1st attempt
SELECT DISTINCT [NBOMEId], S2.[Subject], MIN([ExamDate]) AS ExamDate
FROM [StudentScore] S2
GROUP BY [NBOMEId],S2.[Subject]
) B
ON S.[NBOMEId] = B.[NBOMEId] AND S.[Subject] = B.[Subject] AND S.[ExamDate] = B.[ExamDate]
--Group in "Exam Periods" based on the list of periods w/ start & end dates in another table.
FULL OUTER JOIN [ExamPeriod] P 
ON  S.[ExamDate] = P.PeriodStart AND S.[ExamDate] <= P.PeriodEnd
WHERE S.[Subject] = B.[Subject]
GROUP BY P.[Id], S.[Subject], S.[ExamDate], S.[RawScoreStandard], S.[RawScorePercent], S.[AdjustedScore], S.[NBOMEId], S.[NBOMELastName], S.[NBOMEFirstName], S.[SecondYrTake]) [StudentScore]  
ON 
([StudentScore].PeriodId = [Average_Update].ExamPeriodId 
AND [StudentScore].Subject = [Average].Subject 
AND [StudentScore].[ExamDate] <= [Average_Update].[Updated])
--End meat


--Joins to pull in relevant data for normalized tables
FULL OUTER JOIN [dbo].[Student] [Student] ON ([StudentScore].[NBOMEId] = [Student].[NBOMEId])
INNER JOIN [dbo].[ExamPeriod] [ExamPeriod] ON ([Average_Update].ExamPeriodId = [ExamPeriod].[Id])
INNER JOIN [dbo].[AcademicYear] [AcademicYear] ON ([ExamPeriod].[AcademicYearId] = [AcademicYear].[Id])

--This will pull only the latest update entry for every academic year.
WHERE [Updated] IN (
SELECT DISTINCT MAX([Updated]) AS MaxDate
FROM [Average_Update]
GROUP BY[ExamPeriodId])

GROUP BY [AcademicYear].[AcademicYearText], [Average].[Subject], [Average_Update].[Updated], 
ORDER BY [AcademicYear].[AcademicYearText], [Average_Update].[Updated], [Average].[Subject]