Ticket T1279762
Visible to All Users

How to format duration as HH:MM instead of minutes in XRCrossTab

created 3 days ago (modified 2 days ago)

[DevExpress Support Team: CLONED FROM T1279152: XtraReport - Display overview of all found nested groups AFTER displaying the details for these nested groups]

Just note: I create the report definitions by C# code on my own but in case of troubles I can export it to WYSIWYG editor, find the solution and then to project found solution to my code.

My current result is this summary table:
Clipboard-File-1.png

Issue 3) The values in NORM and WORKED columns are numbers and have meaning "number of minutes". I want them to be formatted like 39:20 (hours and minutes - but it is a duration, not 24h time). How to set format for these columns? Or should I use some custom function?

The desired result is something like this:
Clipboard-File-2.png

Thank you very much. I know I have a lot of questions. :-)
M.

Answers approved by DevExpress Support

created 2 days ago

Hello Miroslav,

There is no built-in expression function to format an integer value as a time span. I confirm that you need to write a custom function for this purpose.

For instance, the following function works correctly on my side:

C#
[VSDesignerCustomFunction] public class MinutesToDuration : ReportCustomFunctionOperatorBase { public override string FunctionCategory => "Date & Time"; public override int MinOperandCount => 1; public override int MaxOperandCount => 1; public override object Evaluate(params object[] operands) { var totalMinutes = double.Parse(operands[0].ToString()); var hours = (int)(totalMinutes / 60); var minutes = (int)Math.Abs(totalMinutes % 60); return $"{hours:N0}:{minutes:D2}"; } public override bool IsValidOperandType(int operandIndex, int operandCount, Type type) { if (operandIndex >= operandCount) return false; return type == typeof(double) || type == typeof(double) || type == typeof(int); } public override string Name => "MinutesToDuration"; }

To register it in your Blazor application, call the CustomFunctions.Register method at application startup before var app = builder.Build();.

Once you create and register this custom function, use it similarly to how I demonstrated in the videos I attached to your other tickets.

Please try this solution and let me know if it helps.

Regards,
Aleksandr

    Comments (1)

      Thank you.
      I've written a similar custom function already but (for me) the missing piece of information was that I can reference the cross-tab summary values in expression bindings for individual cells, as we mentioned in Users marked an answer(s) in this ticket as helpful How to calculate a difference between two columns in XRCrossTab .

      This ticket can be closed.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.