We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Format date field and prefilter data

Hello,

I have a Pivot table as below:

I have 2 questions:

  1. Is it possible to use a single date field to display the year, month, and day in separate columns?
  2. Would it be possible to prefilter the data 12 months back from today's date?


Please provide some sample.


  <SfPivotView TValue="StockStatus" ShowFieldList=true ShowGroupingBar="true">

        <PivotViewDataSourceSettings DataSource="@datasource">

            <PivotViewColumns>

                <PivotViewColumn Name="ReportDate"></PivotViewColumn>

            </PivotViewColumns>

            <PivotViewValues>

                <PivotViewValue Name="Qty" Type=SummaryTypes.PercentageOfColumnTotal Caption="Qty"></PivotViewValue>

            </PivotViewValues>

            <PivotViewRows>

                <PivotViewRow Name="StockStatus"></PivotViewRow>

            </PivotViewRows>

            <PivotViewFormatSettings>

                <PivotViewFormatSetting Name="ReportDate" Type="FormatType.DateTime" Format="MMM-yy"></PivotViewFormatSetting>

            </PivotViewFormatSettings>

            <PivotViewFilterSettings>

                <PivotViewFilterSetting Name="Year" Type=Syncfusion.Blazor.PivotView.FilterType.Date Items="@(new string[] { "> 2022-01-01" })">

                </PivotViewFilterSetting>

            </PivotViewFilterSettings>

            <PivotViewDisplayOption View=View.Table></PivotViewDisplayOption>

        </PivotViewDataSourceSettings>

    </SfPivotView>





1 Reply 1 reply marked as answer

AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team October 10, 2022 01:59 PM UTC

Hi Sao,


Please find the response below:


Query

Comments

Is it possible to use a single date field to display the year, month, and day in separate columns?

 

 

Yes, You can group the date field into years, months and days in code-behind by using "PivotViewGroupSettings". Please refer the below code examples.

 

Code example:

<SfPivotView AllowGrouping="true">

    <PivotViewDataSourceSettings DataSource="@Data">

        <PivotViewColumns>

            <PivotViewColumn Name="TimeLine" Caption="Date"></PivotViewColumn>

        </PivotViewColumns>

        <PivotViewGroupSettings>

            <PivotViewGroupSetting Name="TimeLine" Type=GroupType.Date GroupInterval="new List<DateGroup> { DateGroup.Years, DateGroup.Months, DateGroup.Days }" StartingAt="1/1/2015" EndingAt="1/1/2016"></PivotViewGroupSetting>

        </PivotViewGroupSettings>

    </PivotViewDataSourceSettings>

</SfPivotView>

 

You can also group the date field into years, months and days using Grouping UI. Please refer the below code example and screenshot.

Code example:

<SfPivotView AllowGrouping="true">

</SfPivotView>

 

Screenshot:

Output screenshot:

Would it be possible to prefilter the data 12 months back from today's date?

 

You can set the range for the date field in code-behind by using "PivotViewGroupSettings". Also you can set the range in Grouping UI too. Please refer the below code examples.

 

Code example:

<SfPivotView AllowGrouping="true">

    <PivotViewDataSourceSettings DataSource="@Data">

        <PivotViewGroupSettings>

            <PivotViewGroupSetting Name="TimeLine" Type=GroupType.Date GroupInterval="new List<DateGroup> { DateGroup.Years, DateGroup.Months, DateGroup.Days }" StartingAt="1/1/2015" EndingAt="1/1/2016"></PivotViewGroupSetting>

        </PivotViewGroupSettings>

    </PivotViewDataSourceSettings>

</SfPivotView>


Meanwhile we have prepared a sample for your reference.

Sample :  https://www.syncfusion.com/downloads/support/directtrac/general/ze/PivotTable-607751418


Please refer the following document link to know more about Grouping feature.

Document : https://blazor.syncfusion.com/documentation/pivot-table/grouping#group-interval


Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.


Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon