Skip to content

Instantly share code, notes, and snippets.

@bjulius
Last active April 16, 2025 01:47
Show Gist options
  • Save bjulius/bbe97b5a954fc15fd58dea76e066e5b4 to your computer and use it in GitHub Desktop.
Save bjulius/bbe97b5a954fc15fd58dea76e066e5b4 to your computer and use it in GitHub Desktop.
DAX Measure to Extract Data Model Info for Prompting AI
BIM Info =
VAR TableInfo =
ADDCOLUMNS (
INFO.VIEW.TABLES (),
"Component", "Tables"
)
VAR ColumnInfo =
ADDCOLUMNS (
INFO.VIEW.COLUMNS (),
"Component", "Columns"
)
VAR RelationshipInfo =
ADDCOLUMNS (
INFO.VIEW.RELATIONSHIPS (),
"Component", "Relationships"
)
VAR MeasureInfo =
ADDCOLUMNS (
INFO.VIEW.MEASURES (),
"Component", "Measures"
)
VAR Result =
TOCSV ( TableInfo )
& TOCSV ( ColumnInfo )
& TOCSV ( RelationshipInfo )
& TOCSV ( MeasureInfo )
RETURN
Result
// Authored by Brian Julius, Feb 2025
@bjulius
Copy link
Author

bjulius commented Feb 20, 2025

Nalaka Wanniarachchi just came up with a really nice optimization of my DAX measure.

If instead of implementing this through a DAX measure, if you do it via a DAX query, it saves you the step of dragging the measure into the empty table visual.

Here's the DAX Query code:

EVALUATE
VAR TableInfo =
ADDCOLUMNS (
INFO.VIEW.TABLES (),
"Component", "Tables"
)
VAR ColumnInfo =
ADDCOLUMNS (
INFO.VIEW.COLUMNS (),
"Component", "Columns"
)
VAR RelationshipInfo =
ADDCOLUMNS (
INFO.VIEW.RELATIONSHIPS (),
"Component", "Relationships"
)
VAR MeasureInfo =
ADDCOLUMNS (
INFO.VIEW.MEASURES (),
"Component", "Measures"
)
VAR Result =
TOCSV ( TableInfo )
& TOCSV ( ColumnInfo )
& TOCSV ( RelationshipInfo )
& TOCSV ( MeasureInfo )
RETURN
{
Result
}

Now just hit F5 to run the query, click on the output cell and then select

Because the query requires no modification across reports, you can just include this in your startup template so you'll automatically have it available in every report you create.

Nice work, Nalaka!
DAX Query Version of BIM File Measure

@bjulius
Copy link
Author

bjulius commented Feb 20, 2025

For more info about this technique, here's the link to my original LinkedIn post about it:

https://bit.ly/BIMInfoWithDAX

Extract BIM Info with a single DAX Measure

@EDNAHQ
Copy link

EDNAHQ commented Feb 24, 2025

Love this!

@maxanatsko
Copy link

There seems to be either limit to output size, or TOCSV (tried TOJSON as well) trips over some special characters - in large model I'm getting just few percent of Measures data, it is severely truncated.
Doesn't happen when I run INFO.VIEW.MEASURES directly.
@bjulius have you encountered this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment