[]
        
(Showing Draft Content)

LAMBDA

This function allows you to create and name custom reusable functions that can be called like any other function.

Syntax

LAMBDA([parameter1, parameter2, ...], calculation)

Arguments

This function has these arguments:

Argument

Description

parameter

[Optional] A value that you want to pass to the function, such as a cell reference, string or number. You can enter up to 253 parameters.

calculation

[Required] The formula you want to execute and return as the result of the function. It must be the last argument and it must return a result.

Remarks

  • If an incorrect number of parameters or more than 253 parameters are provided to a LAMBDA function, it returns a #VALUE! error.

  • If an incorrect number of arguments is passed to a LAMBDA function, it returns a #VALUE! error.

  • If you call a LAMBDA function from within itself and the call is circular, it returns a #NUM! error.

  • If you create a LAMBDA function in a cell without also calling it from within the cell, it returns a #CALC! error.

Note: If the lambda function is recursive, the maximum recursion depth is related to the browser.

Examples

The following code sample shows the basic usage of LAMBDA function.

// Create a workbook.
var workbook = new GrapeCity.Documents.Excel.Workbook();
var sheet = workbook.Worksheets[0];

// Set data.
sheet.Range["B3:C11"].Value = new object[,] {
    { "Date","Fahrenheit" },
    { new DateTime(2025,6,1),95},
    { new DateTime(2025,6,2),95},
    { new DateTime(2025,6,3),96.8},
    { new DateTime(2025,6,4),86},
    { new DateTime(2025,6,5),82.4},
    { new DateTime(2025,6,6),89.6},
    { new DateTime(2025,6,7),86},
    { new DateTime(2025,6,8),87.8} };

ITable table = sheet.Tables.Add(sheet.Range["B3:C11"], true);
ITable table1 = sheet.Tables.Add(sheet.Range["E3:E11"], true);
sheet.Range["B3:B11"].NumberFormat = "yyyy-mm-dd";

table.ConvertToRange();
table1.ConvertToRange();

// Define the LAMBDA name ToCelsius, implementing the formula for converting Fahrenheit to Celsius.
workbook.Names.Add("ToCelsius", "=LAMBDA(temp, (5/9) * (temp-32))");

// Insert the formula in the range E4:E11 to convert the Fahrenheit values in column C to Celsius.
sheet.Range["E4:E11"].Formula2 = "ToCelsius(C4)";

sheet.Range["E3"].Value = "=ToCelsius(C4:C11)";
sheet.Range["B:E"].AutoFit();

// Save the Excel file.
workbook.Save("LAMBDAToCelsius.xlsx");

image

Lambda Helper Functions

DsExcel.NET supports seven new LAMBDA helper functions. These functions help creating re-usable LAMBDA functions by having LAMBDA function as a parameter. They also serve as stand-alone functions themselves. For more information, refer:

  • BYROW

  • BYCOL

  • ISOMITTED

  • MAKEARRAY

  • MAP

  • REDUCE

  • SCAN