Skip to content

hy5guy/Power_BI_Data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 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.

Backfill (Monthly CSV Reports) Workflow

Automated Processing: Export CSV files from Power BI monthly reports directly to _DropExports\ folder, then run the automation script.

Quick Start:

  1. Export all CSV files from Power BI monthly reports
  2. Save them to C:\Dev\PowerBI_Date\_DropExports\
  3. Run: .\tools\organize_backfill_exports.ps1
  4. Files are automatically categorized, moved, renamed, and manifest updated

What the script does:

  • Auto-detects current month (or specify with -Month)
  • Categorizes files by filename keywords (arrest, traffic, detectives, etc.)
  • Moves files to correct category folders in Backfill\YYYY_MM\
  • Adds YYYY_MM_ prefix to all filenames
  • Updates manifest.json automatically

Manual Workflow (Alternative):

  1. Export CSV files and place in appropriate Backfill\YYYY_MM\[category]\ folders
  2. Run .\tools\rename_backfill_files.ps1 -Month "YYYY_MM" -Folder "Backfill\YYYY_MM"
  3. Run .\tools\update_backfill_manifest.ps1 -Folder "Backfill\YYYY_MM"

Documentation:

  • Backfill/QUICK_START.md - Quick reference guide
  • Backfill/BACKFILL_WORKFLOW.md - Complete workflow documentation

Status:

  • October 2025: 34 files processed and organized
  • November 2025: Folder structure ready, awaiting exports

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

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

Master ETL Automation

Centralized Automation Hub: For Python ETL scripts that process data for Power BI.

A master automation system is available at:

  • C:\Users\carucci_r\OneDrive - City of Hackensack\Master_Automation\

Features:

  • Run all Python ETL scripts from one location
  • Sequential execution in configured order
  • Automatic Power BI integration (copies outputs to _DropExports\)
  • Comprehensive logging and error handling
  • Configurable via config\scripts.json

Usage:

cd "C:\Users\carucci_r\OneDrive - City of Hackensack\Master_Automation"
.\scripts\run_all_etl.ps1

Pre-configured Scripts: Arrests, Community Engagement, Overtime TimeOff, Policy Training, Response Times, Summons, NIBRS, and more.

Documentation:

  • docs/MASTER_AUTOMATION_GUIDE.md - Complete guide
  • Master_Automation/README.md - Full documentation
  • Master_Automation/QUICK_START.md - Quick reference

Documentation

File Handling

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

Latest DAX export: 2025_11 (359 measures, 0 blanks) Latest Backfill: October 2025 (34 CSV files organized)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors