Can anyone help create a stored procedure for dynamic correlation matrices?

I’ve been trying to build a stored procedure in either BigQuery or Snowflake that dynamically creates a correlation table.

I know you can manually create a correlation matrix as seen here, but there’s gotta be a way to do it dynamically, right?

I’ve been trying to use the logic in Felipe Hoffa’s dynamic pivot stored procedure to get the logic right but haven’t cracked it yet.

Documentation

Any thoughts much appreciated!