Skip to content

racmac57/Power_BI_Data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here you go. Three drop-in files for C:\Dev\PowerBI_Date\.

CHANGELOG.md

# PowerBI_Date – Changelog

## 2025-11-02
- Added batch export of DAX measures from DAX Studio.
- Created merged catalog:
  - 2025_11_AllMeasures_withTable.csv
  - 2025_11_AllMeasures.dax
- Measure count: 365.
- Blank expressions: 6 placeholders skipped in .dax.
- Added repeatable merge script pattern for CSV/TSV with auto delimiter detect.
- Standardized monthly file naming: YYYY_MM_*.

## 2025-10-31 to 2025-11-01
- Set up DAX Studio export workflow.
- Validated export formats in Excel and PowerShell.
- Defined table map DMV for TableID to TableName join.
- Agreed storage paths under C:\Dev\PowerBI_Date\DAX and ...\PowerBI_Date\DAX\Studio.

## 2025-10
- Organized Power BI visuals and queries by topic.
- Started monthly “13-month rolling� reporting pack.
- Began documentation for exports, QA, and backups.

SUMMARY.md

# Project Summary

Purpose
- Keep a clean, versioned backup of Power BI measures and metadata.
- Support monthly reporting and quick recovery.
- Allow search, diff, and review of every measure.

What exists now
- 365 measures exported.
- 6 placeholders without expressions. Tracked in CSV. Omitted from .dax.
- Files:
  - C:\Dev\PowerBI_Date\DAX\2025_11_AllMeasures_withTable.csv
  - C:\Dev\PowerBI_Date\DAX\2025_11_AllMeasures.dax

Core workflow
1) Export measures and table map from DAX Studio.
2) Merge to a single CSV with TableName.
3) Build a .dax catalog for quick diff and re-use.
4) Track blanks and fix them in the model.

Status to fix
- Fill or delete these placeholders:
  - ATS_Court_Data: Measure
  - ATS_Court_Data: Measure 3
  - ATS_Court_Data: Report Month End := EOMONTH( TODAY(), -1 )
  - ATS_Court_Data: Measure 4
  - SSOCC_Data: Service Category Month Over Month
  - Table: Measure 2

Naming
- Use YYYY_MM prefix on every monthly export.
- Keep CSV and DAX pairs in C:\Dev\PowerBI_Date\DAX.
- Keep raw DAX Studio exports in C:\Dev\PowerBI_Date\DAX\Studio.

Quick QA
```powershell
# count measures
Import-Csv 'C:\Dev\PowerBI_Date\DAX\2025_11_AllMeasures_withTable.csv' | Measure-Object

# list blanks
Import-Csv 'C:\Dev\PowerBI_Date\DAX\2025_11_AllMeasures_withTable.csv' |
  ? { -not $_.DaxExpression } |
  Select TableName, MeasureName, DisplayFolder | ft -Auto

# README.md

PowerBI_Date

CI

Overview

  • Stores monthly exports for Power BI models.
  • Focus on measures, table map, and quick QA.
  • Lives at C:\Dev\PowerBI_Date and C:\Dev\PowerBI_Date\DAX.

Folder layout

  • C:\Dev\PowerBI_Date\DAX\Studio … raw exports from DAX Studio
  • C:\Dev\PowerBI_Date\DAX … merged CSV and .dax catalogs
  • C:\Dev\PowerBI_Date\mCode … Power Query M code exports organized by month and category

Monthly workflow

  1. Export from DAX Studio

    • Open PBIX in Power BI Desktop.
    • Connect with DAX Studio.
    • Results menu. File. CSV.
    • Save to C:\Dev\PowerBI_Date\DAX\Studio.

    Queries:

    • Measures

      SELECT
        [TableID],
        [Name]       AS MeasureName,
        [Expression] AS DaxExpression,
        [Description],
        [DisplayFolder],
        [FormatString]
      FROM $SYSTEM.TMSCHEMA_MEASURES;
      
    • Table map

      SELECT [ID] AS TableID, [Name] AS TableName
      FROM $SYSTEM.TMSCHEMA_TABLES;
      

    Export settings

    • Encoding: UTF-8.
    • Include headers: on.
    • Quote text: on.
    • Delimiter: comma or tab. Match the file name (.csv or .tsv).
  2. Merge and build .dax

    • Copy the latest two files to C:\Dev\PowerBI_Date\DAX with YYYY_MM names.

    • Run the merge script (example below). It auto detects comma or tab.

    • Outputs:

      • YYYY_MM_AllMeasures_withTable.csv
      • YYYY_MM_AllMeasures.dax
  3. QA

    • Check counts and blanks.
    • Fix blanks in the model when time allows.
    • Re-export if you change measures.

One-shot PowerShell

$dest = 'C:\Dev\PowerBI_Date\DAX'
$src  = 'C:\Dev\PowerBI_Date\DAX\Studio'
$stamp = (Get-Date -Format 'yyyy_MM')

# pick newest
$measSrc = Get-ChildItem $src -Filter '*AllMeasures.*' | Sort LastWriteTime -Desc | Select -First 1
$mapSrc  = Get-ChildItem $src -Filter '*TableMap.*'   | Sort LastWriteTime -Desc | Select -First 1

Copy-Item $measSrc.FullName "$dest\$stamp`_AllMeasures$($measSrc.Extension)" -Force
Copy-Item $mapSrc.FullName  "$dest\$stamp`_TableMap$($mapSrc.Extension)"   -Force

function Import-SmartCsv($p){ $line = Get-Content $p -TotalCount 1; $d = ($line -like '*`t*') ? "`t" : ','; Import-Csv $p -Delimiter $d }

$meas = Import-SmartCsv "$dest\$stamp`_AllMeasures$($measSrc.Extension)"
$map  = Import-SmartCsv "$dest\$stamp`_TableMap$($mapSrc.Extension)"

# normalize
$meas = $meas | Select `
  @{n='TableID';e={ $_.TableID -as [string]}},
  @{n='MeasureName';e={ $_.MeasureName ? $_.MeasureName : $_.Name }},
  @{n='DaxExpression';e={ $_.DaxExpression ? $_.DaxExpression : $_.Expression }},
  Description, DisplayFolder, FormatString
$map = $map | Select `
  @{n='TableID';e={ $_.TableID ? $_.TableID : $_.ID }},
  @{n='TableName';e={ $_.TableName ? $_.TableName : $_.Name }} |
  ? { $_.TableID -and $_.TableName }

# join
$lk=@{}; $map | % { if(-not $lk.ContainsKey($_.TableID)){ $lk[$_.TableID]=$_.TableName } }
$meas | % { $_ | Add-Member TableName ($lk[$_.TableID]) -Force }

# save merged
$merged = "$dest\$stamp`_AllMeasures_withTable.csv"
$meas | Export-Csv $merged -NoTypeInformation -Encoding UTF8

# build .dax
$sb = New-Object Text.StringBuilder
$meas | ? { $_.DaxExpression } | % {
  $t = $_.TableName ? $_.TableName : "_TableId_$($_.TableID)"
  $null = $sb.AppendLine("// $t\$($_.MeasureName)")
  $null = $sb.AppendLine("[$($_.MeasureName)] = $($_.DaxExpression)")
  $null = $sb.AppendLine()
}
$outDax = "$dest\$stamp`_AllMeasures.dax"
[IO.File]::WriteAllText($outDax, $sb.ToString(), [Text.Encoding]::UTF8)

# summary
"Rows: $($meas.Count)"
"Expr blanks: $(( $meas | ? { -not $_.DaxExpression }).Count)"
"Saved: $merged"
"Saved: $outDax"

Troubleshooting

  • DMV query fails in DAX Studio

    • Make sure the tab is in DMV mode. Open DMV pane. Double click the DMV. You should see SELECT * FROM $SYSTEM....
  • Excel shows a single column on import

    • Pick the right delimiter. Comma for .csv. Tab for .tsv.
  • Line breaks inside DAX

    • Keep UTF-8 and quoted text on export.

Checklist each month

  • Export measures and table map.
  • Run the merge script.
  • Confirm counts.
  • Review blanks. Fix if needed.
  • Commit the two outputs to version control.

If you want, I can add a tiny `Run-Exports.cmd` that calls the PowerShell block with one double-click.
::contentReference[oaicite:0]{index=0}

Monthly DAX export workflow

  1. Run DMV queries in DAX Studio.
  2. Export to TSV with headers and quotes.
  3. Run the merge script to create Joined CSV and DAX.
  4. Run tools\organize_dax_studio.ps1 to file by month.
  5. Review INDEX.md and SUMMARY.md.
  6. Commit and push.

M Code (Power Query) export workflow

Current Status: Automated extraction tools have limitations with newer .pbix format. Manual export is recommended.

Recommended Method: Manual Export from Power Query Editor

  1. Open Power BI Desktop with your .pbix file.
  2. Open Power Query Editor (Home → Transform Data).
  3. For each query:
    • Click the query
    • View → Advanced Editor (or Home → Advanced Editor)
    • Copy the M code
    • Save as QueryName.m in mCode\YYYY_MM\
  4. Organize files with tools\organize_mcode_from_helper.ps1

Folder structure: mCode\YYYY_MM\ organized by category (arrest, nibrs, detectives, etc.)

Alternative methods explored:

  • pbi-tools v1.2.0 - Does not support direct .pbix extraction
  • Tabular Editor 2.x - M code not exposed via TOM API when connected to Power BI Desktop
  • Direct .pbix ZIP extraction - M code stored in binary format in newer TMDL-based .pbix files

Documentation:

  • tools/export_mcode_manual_guide.md - Detailed manual export guide
  • tools/export_mcode_with_tabular_editor.md - Tabular Editor method (limited functionality)
  • docs/MCODE_EXPORT_GUIDE.md - Complete M code export guide with all methods

Backfill Visual Export Pipeline

Status: Fully implemented and verified (2025-11-03)

Automates renaming and organization of exported Power BI visual CSV files to support the 13-month rolling window data backfill workflow.

Quick Start:

# Dry run
pwsh -File C:\Dev\Power_BI_Data\Rename_Exports.ps1 -ReportEndMonth "2025-09-01" -DryRun

# Execute
pwsh -File C:\Dev\Power_BI_Data\Rename_Exports.ps1 -ReportEndMonth "2025-09-01"

Features:

  • Automatic slug-based matching (lowercase, underscore-separated)
  • Idempotent file moves with SHA256 hash comparison
  • Map validation with comprehensive linting
  • Centralized logging in Logs\Exports\YYYY_MM\
  • Exit code precedence: 0 (success), 1 (unmapped), 2 (validation failure)
  • Culture-safe date formatting (InvariantCulture)

Workflow:

  1. Export visual CSVs to Exports\Inbox
  2. Run dry run to preview moves and identify unmapped files
  3. Update Backfill\visual_map.csv with missing mappings
  4. Execute live run to organize files
  5. Verify files in Backfill\YYYY_MM_range_*\<subject>\

Output Structure:

  • Organized files: Backfill\YYYY_MM_range_StartLabel_EndLabel\<subject>\YYYY_MM_<slug>.csv
  • Logs: Logs\Exports\YYYY_MM\planned_moves.csv, moved_files.csv, unmapped_titles.txt, map_lint.csv

Documentation:

  • docs/BACKFILL_ROLL-OUT_CHECKLIST.md - Complete roll-out guide with examples
  • docs/BACKFILL_SPEC_QA_REVIEW.md - QA specification and corrections
  • docs/13_MONTH_ROLLING_WORKFLOW.md - 13-month rolling window workflow details
  • Rename_Exports.ps1 - Main script with inline documentation

Single-directory convention

All scripts and exports now use C:\Dev\PowerBI_Date as the root directory. DAX exports are organized under:

  • DAX\Studio\YYYY_MM\ - Raw DAX Studio exports (TSV/CSV)
  • DAX\ - Processed exports (AllMeasures_withTable.csv, AllMeasures.dax)

Git Repository Management

Repository: https://github.com/racmac57/Power_BI_Data

Quick Push

# Use the idempotent script
powershell -ExecutionPolicy Bypass -File C:\Dev\PowerBI_Date\tools\git_push_direct.ps1

# Or manually
cd C:\Dev\PowerBI_Date
git add -A
git commit -m "Your message"
git push

Monthly Tags

After completing monthly exports, create a version tag:

git tag -a v2025_12 -m "December 2025 DAX exports"
git push origin v2025_12

CI/CD Pipeline

Automated workflow with linting, validation, and releases:

# Create monthly tag (triggers workflow)
powershell -ExecutionPolicy Bypass -File tools\tag_month.ps1

What happens:

  • Lints PowerShell scripts with PSScriptAnalyzer
  • Validates DAX export structure
  • Generates measures diff report
  • Creates GitHub Release with artifacts

View: https://github.com/racmac57/Power_BI_Data/actions

Documentation

File Handling

  • .gitattributes ensures CSV/TSV/DAX files have readable diffs
  • .gitignore excludes logs and ad-hoc dumps, keeps organized monthly folders

Latest export: 2025_11 (359 measures, 0 blanks)

ETL Output Standardization

Status: Partially integrated (2025-11-03) - 3 of 6 ETLs complete

Standardized Python ETL outputs for the 13-month rolling window workflow.

Integration Status:

  • Arrests - Complete (MonthKey normalized)
  • Summons - Complete (MonthKey normalized)
  • Policy_Training - Complete (MonthKey added, Excel preserved)
  • Response_Times - Next target (high priority)
  • Community_Engagement - Pending
  • Overtime_TimeOff - Pending

Quick Start:

from tools.etl_output_writer import write_current_month
import pandas as pd

# After ETL processing
write_current_month(
    df=my_dataframe,
    subject='Arrests',
    report_end_month=pd.Timestamp('2025-10-01')
)

Output Location: ETL\current_month\{Subject}_Current_YYYY-MM-DD.csv

Documentation:

  • docs/README_ETL_OUTPUTS.md - Complete ETL output contract and integration guide
  • docs/ETL_INTEGRATION_SNIPPETS.md - Per-subject integration snippets
  • tools/etl_output_writer.py - Python utility module
  • tools/validate_current_month.py - Validation script
  • tools/example_etl_integration.py - Example integration code

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors