SSRS REPORT using hour ,day and month selection , I have hourly data

Rahul Patil 0 Reputation points
2023-03-26T18:37:47.6333333+00:00

I have SQL table having hourly data for some Temperature & pressure , wanted to show same data by hourly , daily & monthly selection from SSRS REPORT

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,800 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,812 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sedat SALMAN 13,170 Reputation points
    2023-03-26T19:54:13.2566667+00:00

    you need to create a parameterized SQL query for the dataset and design the report layout

    I will give you an example query just create yours like this one

    
    DECLARE @TimeAggregation NVARCHAR(10) = @AggregationParameter;
    
    WITH CTE AS (
        SELECT
            DATEADD(HOUR, DATEDIFF(HOUR, 0, [DateTime]), 0) AS Hour,
            DATEADD(DAY, DATEDIFF(DAY, 0, [DateTime]), 0) AS Day,
            DATEADD(MONTH, DATEDIFF(MONTH, 0, [DateTime]), 0) AS Month,
            [Temperature],
            [Pressure]
        FROM
            YourTableName
    )
    SELECT
        CASE
            WHEN @TimeAggregation = 'Hourly' THEN Hour
            WHEN @TimeAggregation = 'Daily' THEN Day
            ELSE Month
        END AS DateTime,
        AVG([Temperature]) AS AvgTemperature,
        AVG([Pressure]) AS AvgPressure
    FROM
        CTE
    GROUP BY
        CASE
            WHEN @TimeAggregation = 'Hourly' THEN Hour
            WHEN @TimeAggregation = 'Daily' THEN Day
            ELSE Month
        END
    ORDER BY
        DateTime;
    
    
    1. Open SQL Server Data Tools (SSDT) and create a new report project.
    2. Add a new report to the project.
    3. Set up the data source to connect to your SQL Server.
    4. Create a new dataset for the report
    5. Create a report parameter named AggregationParameter with three available values: "Hourly", "Daily", and "Monthly". Set the default value as per your requirement
    6. Bind the AggregationParameter to the dataset parameter @AggregationParameter.
    7. Design the report layout
    0 comments No comments

  2. AniyaTang-MSFT 12,321 Reputation points Microsoft Vendor
    2023-03-27T02:26:20.5033333+00:00

    Hi @Rahul Patil

    What you mean by showing the same data by hourly, daily and monthly options, I don't particularly understand. Do you want to set the parameters in SSRS? You can refer to this link: https://learn.microsoft.com/en-us/sql/reporting-services/report-design/report-parameters-report-builder-and-report-designer?view=sql-server-ver16.

    You can provide more detailed instructions and information so that I can test it for you.

    Best regards,

    Aniya

    0 comments No comments