Skip to content

Instantly share code, notes, and snippets.

@ExcelExciting
Last active August 10, 2023 21:05
Show Gist options
  • Save ExcelExciting/98398f37eec7d9f7b416993cfb221722 to your computer and use it in GitHub Desktop.
Save ExcelExciting/98398f37eec7d9f7b416993cfb221722 to your computer and use it in GitHub Desktop.
Lambda - 00003 - CBMCONVERTER
/*
--------------------- CBM CONVERTER ---------------------
*/
CBMCONVERTER =
/*Calculate Cubic Meters (CBM)
Calculate Cubic Meters (CBM). CBM Converter allow you to measure your cargo volume in CBM (m³).
CBM calcuation is widely use in shipping/logistics industry to calculate a cargo volume.
author,"Faraz Shaikh, Microsoft® MVP",
wesite,"www.ExcelExciting.com",
created,"20221129",
update1,"20230601",
update1_remarks,"update the code with number of packages",
*UOM = Unit of Measurement
lenght = select the lenght
width = select the width
height = select the width
[number_of_packages] = this optional argument which is by defalut 1 (one), incase if you 7 packages with the same dimensions then you need declare dimension once and declare number of packages.
[UOM_IN] = is optional argument which accepts the current UOM & convert into meters see the Example 01
if the UOM is not declared it will consider values as meter and do the calculations
EXAMPLE 01 >> when UOM is in centimeters
=CBMCONVERTER(95,70,65,,"cm")
RESULT>> 0.43225
EXAMPLE 02 >> when UOM is in milimeters
=CBMCONVERTER(950,700,650,,"mm")
RESULT>> 0.43225
EXAMPLE 03 >> when UOM is in inches
=CBMCONVERTER(37.4016,27.5591,25.5906,,"in")
RESULT>> 0.43225
EXAMPLE 04 >> When UOM is in meter
=CBMCONVERTER(0.95,0.7,0.65)
RESULT>> 0.43225
EXAMPLE 05 >> When we declare number of packages
=CBMCONVERTER(0.95,0.7,0.65,10)
RESULT>> 4.3225
*/
LAMBDA(lenght, width, height, [number_of_packages], [UOM_IN],
LET(
v_UOM_FROM, LOWER(IF(ISOMITTED(UOM_IN), "m", UOM_IN)),
v_number_of_packages,IF(ISOMITTED(number_of_packages),1,number_of_packages),
v_convert_lenght, CONVERT(lenght, v_UOM_FROM, "m"),
v_convert_width, CONVERT(width, v_UOM_FROM, "m"),
v_convert_height, CONVERT(height, v_UOM_FROM, "m"),
v_calculate_result, v_number_of_packages * (v_convert_lenght * v_convert_width * v_convert_height),
result, v_calculate_result,
result
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment