How to Sum time by values from expression or ReportItem in RDLC reports

B M-A 361 Reputation points
2022-10-29T10:02:19.33+00:00

Hello,

I want to sum time values o RDLC report, based on values from textbox generated by Expression and I get this error message :
The Value expression for the text box ‘Textbox24’ refers to the report item ‘Textbox23’. Report item expressions can only refer to other report items within the same grouping scope or a containing grouping scope. Letters in the names of report items must use the correct case.

             Time1      Time 2            TotalTime(Expression)// Textbox23  
             1:00           1:00                2:00  
             2:00           2:00                4:00  

Total Time 3:00 3:00 Error Textbox24

How to sum Total time?

Best regards,

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,678 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,288 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hui Liu-MSFT 40,271 Reputation points Microsoft Vendor
    2022-10-31T03:00:47.697+00:00

    Here is an example of summing datetime, you could refer to it.
    Xaml:

     <Window.DataContext>  
            <local:ViewModel/>  
        </Window.DataContext>  
        <Grid>  
            <DataGrid ItemsSource="{Binding TestData}" AutoGenerateColumns="False">  
                <DataGrid.Columns>  
                    <DataGridTextColumn Header="Time1" Binding="{Binding Time1,StringFormat='HH:mm'}"/>  
                    <DataGridTextColumn Header="Time2" Binding="{Binding Time2,StringFormat='HH:mm'}"/>  
                    <DataGridTextColumn Header="TotalTime" Binding="{Binding Time3,StringFormat='HH:mm'}"/>  
                </DataGrid.Columns>  
                  
            </DataGrid>  
        </Grid>  
    

    Codebehind:

    255443-sum-datetime.txt

    Update:

    <Window x:Class="BindDataFromRDLC.MainWindow"  
            ...  
             xmlns:rdlcreport="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"   
            mc:Ignorable="d"  
           >  
        <StackPanel>  
             
            <DataGrid ItemsSource="{Binding TestData}" AutoGenerateColumns="False">  
                <DataGrid.Columns>  
                    <DataGridTextColumn Header="Time1" Binding="{Binding Time1,StringFormat='HH:mm'}"/>  
                    <DataGridTextColumn Header="Time2" Binding="{Binding Time2,StringFormat='HH:mm'}"/>  
                    <DataGridTextColumn Header="TotalTime" Binding="{Binding Time3,StringFormat='HH:mm'}"/>  
                </DataGrid.Columns>  
            </DataGrid>  
            <WindowsFormsHost Name="windowsFormsHost1" Height="400" >  
                <rdlcreport:ReportViewer x:Name="_reportviewer" />  
            </WindowsFormsHost>  
        </StackPanel>  
    </Window>  
    

    The codebehind:

    257040-rdlc.txt

    The result:
    257059-image.png

    ----------------------------------------------------------------------------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Rajanikant Hawaldar 86 Reputation points
    2022-10-31T09:27:50.613+00:00
    =Sum(Fields!TotalTime.Value)