为什么我的总数没有正确显示,我该如何解决?

时间:2019-06-26 18:41:00

标签: sql-server ms-access reporting-services

我正在使用来自SQL Server的数据在SSRS中重建访问报告。 在报告中,我有一个矩阵,值之一是SumOfPieces。 SumOfPieces在我的查询中为sum(t1.pieces) as SumOfPieces。 在表内部,仅通过使用[SumOfPieces]即可获得正确的行值,但是我的总计没有将任何东西加在一起。例如,这就是我得到的:

Product | Facility | Shift/Line | Pieces
BFS     | BRWP     | A 1        | 65,000
BFS     | MHWP     | A 2        | 70,000
BFS     | MHWP     | B 2        | 80,000
________________________________________
Total   |          |            | 70,000

由于某种原因,它给了我中间价值 总计的表达式就是=Sum(fields!SumOfPieces.Value) 我尝试了类似此表达式=Sum(avg(fields!SumPieces.Value,"Product1")

的其他变体

在Access中,这是通过嵌套4-5深的查询来完成的。 对于该字段,它看起来像

  • 带有t1.Pieces的原始查询t1
  • 对t1的下一个查询为t1.Pieces总计为t1.SumOfPieces
  • 下一个查询与其他人一起加入t1

“访问”报告仅使用该SumOfPieces作为行值,然后使用总和(SumOfPieces)。

我的数据集查询示例:

SELECT
   StaveHistorySummary.fk_Inspectors
  ,StaveHistorySummary.fk_InspectionSites
  ,StaveHistorySummary.fk_ProductionLines
  ,StaveHistorySummary.fk_ProductTypes
  ,StaveHistorySummary.DateMade
  ,StaveHistorySummary.[TimeStamp]
  ,StaveHistorySummary.StaveHistoryguid
  ,InspectionSites.SiteAbbr
  ,Inspectors.Name
  ,ProductTypes.Product
  ,ProductionLines.LineName
  ,CAST(sum(Millproduction.Pieces) as int) AS SumPieces
  ,CASE 
     WHEN SapEdgingInches IS NOT NULL THEN SapEdgingInches
     WHEN HeartEdgingInches IS NOT NULL THEN HeartEdgingInches
     WHEN BothEdgingInches IS NOT NULL THEN BothEdgingInches
     WHEN SawnIncorrInches IS NOT NULL THEN SawnIncorrInches
     WHEN EqualizedIncorrInches IS NOT NULL THEN EqualizedIncorrInches
     WHEN SawnOKInches IS NOT NULL THEN SawnOKInches
     END AS WIDTH
FROM
  StaveHistorySummary
  INNER JOIN ProductionLines
    ON StaveHistorySummary.fk_ProductionLines = ProductionLines.ProductionLines_NDX
  INNER JOIN InspectionSites
    ON StaveHistorySummary.fk_InspectionSites = InspectionSites.InspectionSites_NDX
  INNER JOIN ProductTypes
    ON StaveHistorySummary.fk_ProductTypes = ProductTypes.ProductTypes_NDX
  INNER JOIN Inspectors
    ON StaveHistorySummary.fk_Inspectors = Inspectors.Inspectors_NDX
  INNER JOIN MillProduction
    ON inspectionsites.inspectionsites_ndx = MillProduction.fk_inspectionsites
      AND productionlines.productionlines_ndx = MillProduction.fk_productionlines
      AND producttypes.producttypes_ndx = millproduction.fk_producttypes
WHERE (CAST(CAST(stavehistorysummary.DateMade as date) as datetime) BETWEEN '6/16/2019' AND '6/22/2019')
AND (CAST(CAST(MillProduction.DateMade as date) as datetime) BETWEEN '6/16/2019' AND '6/22/2019')
GROUP BY 
StaveHistorySummary.fk_Inspectors
  ,StaveHistorySummary.fk_InspectionSites
  ,StaveHistorySummary.fk_ProductionLines
  ,StaveHistorySummary.fk_ProductTypes
  ,StaveHistorySummary.DateMade
  ,StaveHistorySummary.[TimeStamp]
  ,StaveHistorySummary.StaveHistoryguid
  ,InspectionSites.SiteAbbr
  ,Inspectors.Name
  ,ProductTypes.Product
  ,ProductionLines.LineName
  ,CAST(sum(Millproduction.Pieces) as int) AS SumPieces
  ,CASE 
     WHEN SapEdgingInches IS NOT NULL THEN SapEdgingInches
     WHEN HeartEdgingInches IS NOT NULL THEN HeartEdgingInches
     WHEN BothEdgingInches IS NOT NULL THEN BothEdgingInches
     WHEN SawnIncorrInches IS NOT NULL THEN SawnIncorrInches
     WHEN EqualizedIncorrInches IS NOT NULL THEN EqualizedIncorrInches
     WHEN SawnOKInches IS NOT NULL THEN SawnOKInches
     END AS WIDTH

Image of Matrix

0 个答案:

没有答案