| name | Power BI Modeling |
| description | Create and manage Power BI semantic model structure using pbi-cli -- tables, columns, measures, relationships, hierarchies, calculation groups, and date/calendar tables. Invoke this skill whenever the user says "create table", "add measure", "add column", "create relationship", "date table", "calendar table", "star schema", "mark as date table", "add hierarchy", "calculation group", or any model-building task. Also invoke when creating multiple measures at once -- the skill contains critical guidance on multi-line DAX expression handling. |
| tools | pbi-cli |
Power BI Modeling Skill
Use pbi-cli to manage semantic model structure. Requires pipx install pbi-cli-tool, pbi-cli skills install, and pbi connect.
Prerequisites
pipx install pbi-cli-tool
pbi-cli skills install
pbi connect
Tables
pbi table list
pbi table get Sales
pbi table create Sales --mode Import
pbi table delete OldTable
pbi table rename OldName NewName
pbi table refresh Sales --type Full
pbi table schema Sales
pbi table mark-date Calendar --date-column Date
Columns
pbi column list --table Sales
pbi column get Amount --table Sales
pbi column create Revenue --table Sales --data-type double --source-column Revenue
pbi column create Profit --table Sales --expression "[Revenue]-[Cost]"
pbi column delete OldCol --table Sales
pbi column rename OldName NewName --table Sales
Measures
pbi measure list
pbi measure list --table Sales
pbi measure get "Total Revenue" --table Sales
pbi measure create "Total Revenue" -e "SUM(Sales[Revenue])" -t Sales
pbi measure create "Revenue $" -e "SUM(Sales[Revenue])" -t Sales --format-string "\$#,##0"
pbi measure create "KPI" -e "..." -t Sales --folder "Key Measures" --description "Main KPI"
pbi measure update "Total Revenue" -t Sales -e "SUMX(Sales, Sales[Qty]*Sales[Price])"
pbi measure delete "Old Measure" -t Sales
pbi measure rename "Old" "New" -t Sales
pbi measure move "Revenue" -t Sales --to-table Finance
Multi-line DAX in measure expressions: The -e flag passes DAX as a shell argument, which collapses newlines. For simple expressions like SUM(Sales[Amount]) or DIVIDE([A] - [B], [B]) this works fine. For complex expressions using VAR/RETURN, pipe from stdin instead:
echo 'VAR TotalSales = SUM(Sales[Amount])
VAR TotalCost = SUM(Sales[Cost])
RETURN TotalSales - TotalCost' | pbi measure create "Profit" -e - -t Sales
See the power-bi-dax skill for the full explanation and more workarounds.
Relationships
pbi relationship list
pbi relationship get RelName
pbi relationship create \
--from-table Sales --from-column ProductKey \
--to-table Products --to-column ProductKey
pbi relationship delete RelName
pbi relationship find --table Sales
pbi relationship activate RelName
pbi relationship deactivate RelName
Hierarchies
pbi hierarchy list --table Date
pbi hierarchy get "Calendar" --table Date
pbi hierarchy create "Calendar" --table Date
pbi hierarchy delete "Calendar" --table Date
Calculation Groups
pbi calc-group list
pbi calc-group create "Time Intelligence" --description "Time calcs"
pbi calc-group items "Time Intelligence"
pbi calc-group create-item "YTD" \
--group "Time Intelligence" \
--expression "CALCULATE(SELECTEDMEASURE(), DATESYTD(Calendar[Date]))"
pbi calc-group delete "Time Intelligence"
Creating a Date/Calendar Table
Date tables are essential for time intelligence functions (TOTALYTD, SAMEPERIODLASTYEAR, DATEADD, etc.).
pbi table create Calendar \
--dax-expression "ADDCOLUMNS(CALENDAR(DATE(2023,1,1), DATE(2024,12,31)), \"Year\", YEAR([Date]), \"MonthNumber\", MONTH([Date]), \"MonthName\", FORMAT([Date], \"MMMM\"), \"Quarter\", \"Q\" & FORMAT([Date], \"Q\"))"
pbi table mark-date Calendar --date-column Date
pbi calendar list
Workflow: Create a Star Schema
pbi table create Sales --mode Import
pbi table create Products --mode Import
pbi table create Calendar --mode Import
pbi relationship create --from-table Sales --from-column ProductKey --to-table Products --to-column ProductKey
pbi relationship create --from-table Sales --from-column DateKey --to-table Calendar --to-column DateKey
pbi table mark-date Calendar --date-column Date
pbi measure create "Total Revenue" -e "SUM(Sales[Revenue])" -t Sales --format-string "\$#,##0"
pbi measure create "Total Qty" -e "SUM(Sales[Quantity])" -t Sales --format-string "#,##0"
pbi measure create "Avg Price" -e "AVERAGE(Sales[UnitPrice])" -t Sales --format-string "\$#,##0.00"
pbi table list
pbi measure list
pbi relationship list
Best Practices
- Use format strings for currency (
$#,##0), percentage (0.0%), and integer (#,##0) measures
- Organize measures into display folders by business domain
- Always mark calendar tables with
mark-date for time intelligence
- Use
--json flag when scripting: pbi --json measure list
- Export TMDL for version control:
pbi database export-tmdl ./model/