简体   繁体   中英

Why can't I change format for numeric field in MS Access report?

I have performance data (95%, 100%, 120%, etc.) that needs formatted as a percent so I can sort and conditionally format. Upon opening the properties window of my MS Access report, it will let me change the format (General Number, Currency, Percent, etc.) for values extracted directly from a table, such as employee_id or shift . But others, such as [6 wks ago] , [5 wks ago] , and on down do not allow me to do this. Is this because the field is the result of an IIF() statement? The following query is my original query:

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;

So I thought OK, it doesn't want to format the result of such a conditional statement. So I put the series of IIF()s in the FROM statement and selected those values directly, as shown below:

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;

It doesn't allow me to format the [n wks ago] columns from this query either. My original performance tables have 4 columns: employee_id , week_ending_dt , goal_hrs , and hrs_worked . This data goes for the past 6 weeks, so I created crosstab queries to give a different column for each week (we're using this to see how performance is trending week over week). Loader performance is stored separately from others' performance, so that's why I need the IIF() in the query. Is there some way to get this information that keeps the end performance values as numeric values whose format can be changed?

This here was my original question, but my lack of specificity means this answer is not feasible. Thank you!

It turns out that the query that feeds the crosstab had the following performance expression:

IIf([d2s_performance_tbl].[hrs_worked]=0,"", Round(([d2s_performance_tbl].[goal_hrs]/[d2s_performance_tbl].[hrs_worked]),2)) .

Removing the IIF() to leave just

Round(([d2s_performance_tbl].[goal_hrs]/[d2s_performance_tbl].[hrs_worked]),2)

leaves the values as numbers, which does follow through to the report, allowing me to change to percent and sort and all the other fun things that come with numeric values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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