This isn’t exactly the same as this thread, but linking as a related topic: Use data or table functions inside a document