我有需要格式化为百分比的性能数据(95%,100%,120%等),因此我可以排序和有条件地格式化。打开MS Access报告的属性窗口后,它将允许我更改直接从表格中提取的值的格式(常规数字,货币,百分比等),例如employee_id
或shift
。但其他人,例如[6 wks ago]
,[5 wks ago]
和其他人,不允许我这样做。这是因为该字段是IIF()
语句的结果吗?以下查询是我的原始查询:
SELECT
D2s_roster_tbl.employee_id AS ID,
D2s_roster_tbl.employee_name AS Name,
D2s_roster_tbl.position_desc AS [Position],
D2s_roster_tbl.adj_hire_dt AS [Hire DT],
D2s_roster_tbl.shift_nbr AS Shift,
D2s_roster_tbl.supervisor,
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/09],[trndPerformanceQry_crosstab].[11/09]) AS [6 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/16],[trndPerformanceQry_crosstab].[11/16]) AS [5 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/23],[trndPerformanceQry_crosstab].[11/23]) AS [4 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/30],[trndPerformanceQry_crosstab].[11/30]) AS [3 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[12/07],[trndPerformanceQry_crosstab].[12/07]) AS [2 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[12/14],[trndPerformanceQry_crosstab].[12/14]) AS [Last wk],
FROM
((D2s_roster_tbl
LEFT JOIN trndLoaderPerformanceTbl_Crosstab ON D2s_roster_tbl.employee_id = trndLoaderPerformanceTbl_Crosstab.employee_id)
LEFT JOIN trndPerformanceQry_Crosstab ON D2s_roster_tbl.employee_id = trndPerformanceQry_Crosstab.employee_id)
LEFT JOIN trndPerfFormatPercent_Crosstab ON D2s_roster_tbl.employee_id = trndPerfFormatPercent_Crosstab.employee_id;
所以我认为好的,它不想格式化这种条件语句的结果。所以我将一系列IIF()s
放在FROM语句中并直接选择这些值,如下所示:
SELECT
D2s_roster_tbl.employee_id AS ID,
D2s_roster_tbl.employee_name AS Name,
D2s_roster_tbl.position_desc AS [Position],
D2s_roster_tbl.adj_hire_dt AS [Hire DT],
D2s_roster_tbl.shift_nbr AS Shift,
D2s_roster_tbl.supervisor,
j.[6 wks ago],
j.[5 wks ago],
j.[4 wks ago],
j.[3 wks ago],
j.[2 wks ago],
j.[Last wk]
FROM
((D2s_roster_tbl
LEFT JOIN trndLoaderPerformanceTbl_Crosstab ON D2s_roster_tbl.employee_id = trndLoaderPerformanceTbl_Crosstab.employee_id)
LEFT JOIN trndPerformanceQry_Crosstab ON D2s_roster_tbl.employee_id = trndPerformanceQry_Crosstab.employee_id)
LEFT JOIN (SELECT
d2s_roster_tbl.employee_id,
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/09],[trndPerformanceQry_crosstab].[11/09]) AS [6 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/16],[trndPerformanceQry_crosstab].[11/16]) AS [5 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/23],[trndPerformanceQry_crosstab].[11/23]) AS [4 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[11/30],[trndPerformanceQry_crosstab].[11/30]) AS [3 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[12/07],[trndPerformanceQry_crosstab].[12/07]) AS [2 wks ago],
IIf([D2s_roster_tbl].[Position_desc] Like "*loader*",[trndLoaderPerformanceTbl_Crosstab].[12/14],[trndPerformanceQry_crosstab].[12/14]) AS [Last wk]
FROM
((D2s_roster_tbl
LEFT JOIN trndLoaderPerformanceTbl_Crosstab ON D2s_roster_tbl.employee_id = trndLoaderPerformanceTbl_Crosstab.employee_id)
LEFT JOIN trndPerformanceQry_Crosstab ON D2s_roster_tbl.employee_id = trndPerformanceQry_Crosstab.employee_id)) AS J ON d2s_roster_tbl.employee_id = j.employee_id;
它也不允许我格式化此查询中的[n wks ago]
列。我的原始效果表有4列:employee_id
,week_ending_dt
,goal_hrs
和hrs_worked
。这个数据是过去6周的,因此我创建了交叉表查询,以便为每周提供不同的列(我们使用它来查看性能是如何每周一周的趋势)。加载程序性能与其他程序的性能分开存储,因此这就是我在查询中需要IIF()
的原因。是否有某种方法可以获取此信息,将最终性能值保持为可以更改格式的数值?
This here是我原来的问题,但我缺乏特异性意味着这个答案是不可行的。谢谢!
答案 0 :(得分:1)
事实证明,提供交叉表的查询具有以下性能表达式:
IIf([d2s_performance_tbl].[hrs_worked]=0,"", Round(([d2s_performance_tbl].[goal_hrs]/[d2s_performance_tbl].[hrs_worked]),2))
。
删除IIF()
只留下
Round(([d2s_performance_tbl].[goal_hrs]/[d2s_performance_tbl].[hrs_worked]),2)
将值保留为数字,这些数字会一直显示在报告中,允许我更改为百分比和排序以及所有其他有趣的数字值。