Skip to content

Instantly share code, notes, and snippets.

View ncalm's full-sized avatar
💭
hitting computer with hammer

Owen Price ncalm

💭
hitting computer with hammer
View GitHub Profile
@ncalm
ncalm / excel-lambda-DICECOEFF.txt
Created April 2, 2024 20:16
This Excel LAMBDA function calculates the Sørensen–Dice coefficient between two text strings
/*
GETBIGRAMS - Get the bigrams of a text string
Inputs: 1. str - a text string
Returns: A vertical array of the bigrams of the text string
Example:
=GETBIGRAMS("banana")
={"ba";"an";"na";"a"}
*/
@ncalm
ncalm / office-scripts-protection.ts
Last active March 22, 2024 13:32
This gist demonstrates how to set protection options in Office Scripts for Excel
function main(workbook: ExcelScript.Workbook) {
const activeSheet = workbook.getActiveWorksheet()
// Returns an object representing the worksheet's protection
const activeSheetProtection = activeSheet.getProtection()
// Protect the sheet according to preferred options (password as 2nd arg is optional)
// This line uses the ternary operator. The protect call is only used if the getProtected() call returns false
@ncalm
ncalm / create-format-chart.ts
Last active March 9, 2024 21:33
This Office Scripts function creates and formats a chart - for exploration and learning
/*
* Create and format a chart from some AdventureWorksDW2019 data
* The table has these columns: Year, Month, SalesAmount
* The worksheet must include a named cell called 'referenceLineValue'. This value is used to draw the line on the chart.
*/
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
@ncalm
ncalm / powerquery-TextSplit.m
Created February 7, 2024 01:09
This code demonstrates one way to parse a string of fields into multiple rows and columns
let
Source = "APS Deposit 04/01/2022 $5,174.27 APS ACH Deposit 04/04/2022 $65,186.66",
Split = Text.Split(Source, " "),
Typed = List.Transform(Split,
each try Number.From(_) otherwise
try Date.From(_, "en-gb") otherwise _ ),
Accumulate = List.Accumulate({0..List.Count(Typed)-1}, "",
(a, b) =>
let
c = Typed{b},
@ncalm
ncalm / excel-lambda-two_arg.txt
Last active January 15, 2024 18:38
Some simple functions for pairwise lifting of VBA UDFs
two_arg = LAMBDA(function,
LAMBDA(x, y,
function(x, y)
)
);
@ncalm
ncalm / excel-lambda-rgb2hex.txt
Last active February 7, 2024 15:31
Resources for retrieving, understanding and using the ColorIndex property in VBA
RGB2HEX = LAMBDA(rgb_array,
LET(
_rgb_array,TOROW(0+rgb_array),
IF(COUNT(_rgb_array)<>3,#VALUE!,
CONCAT("#",DEC2HEX(_rgb_array,2))
)
)
);
@ncalm
ncalm / excel-lambda-StandardErrorofMean.txt
Created January 4, 2024 15:24
This Excel LAMBDA function calculates the standard error of the mean
/*
Standard error of the mean
Usage:
For a measurement from a sample of 100:
Initialize:
MYSAMPLE_SEM = SEM(100);
Use:
@ncalm
ncalm / ChallengeURL.txt
Created December 31, 2023 14:33
Solution to Crispo Mwangi's question on Dec 31 23
https://www.linkedin.com/posts/crispo-mwangi-6ab49453_excel-exceltips-crispexcel-activity-7147058784119554048-Am6l?utm_source=share&utm_medium=member_desktop
@ncalm
ncalm / excel-lambda-UNPIVOTEVERYNROWS.txt
Created December 28, 2023 19:25
This Excel LAMBDA function allows pivoting of attribute/value stacks where some entities have missing attributes
PIVOTEVERYNROWS = LAMBDA(attribute, value, first_attribute,
LET(
unique_attributes, UNIQUE(attribute),
attribute_ids, SEQUENCE(ROWS(unique_attributes)),
col_id, XLOOKUP(attribute, unique_attributes, attribute_ids),
shift, --(attribute = first_attribute),
row_id, SCAN(, shift, SUM),
pivoted, PIVOTBY(row_id, HSTACK(col_id, attribute), value, SINGLE,0,0,,0),
DROP(pivoted, 1, 1)
)
@ncalm
ncalm / sql_server_change_table_description.sql
Last active December 19, 2023 17:47
This SQL Server procedure encapsulates the process of adding or changing the Description extended property on a table
DROP PROCEDURE IF EXISTS change_table_description;
GO
CREATE PROCEDURE change_table_description (
@table_schema nvarchar(128),
@table_name nvarchar(128),
@description nvarchar(255)
)
AS
BEGIN