While working with some customers a few times this question came up: “How
can I diff my current file with a older one? I really want to compare
my files, to know what changed from one to another."
Many many people working with Power BI end up with a directory full
of files looking like: “myPowerBIFileV1.pbix”,
“myPowerbifilev2.pbix”… “myPowerbifilevN.pbix”. The scenario wull
get worse if we have two or more people working in the same file, and
until recently my answer was always the same: “You can’t”.
Once again PowerShell to the rescue
Using a
library
that’s open sourced by DevScope we can
diff the files by using the function to migrate a Power BI file to an
Analysis Services tabular model for each of the files and in the end
compare them with any text comparing software.
A full example
You can install the library by running in a elevated PowerShell console the following command:
1
Install-Module PowerBIPS.Tools
If you have already installed to make sure you have the latest version run:
1
Update-Module PowerBIPS.Tools
And then you run this script replacing with your own files:
# Load the Module
Import-Module PowerBIPS.Tools
# Get script current path
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
# Extract the model to the folder SSAS. Make sure you have your Power BI file open
Convert-PowerBIDesktopToASTabular -pbiDesktopWindowName "DemoFile -*" -outputPath "$currentPath\SSAS\" -removeInternalPBITables -Verbose
################################################################################# Diffing# Extract the altered model to the folder SSASV2. Make sure you have your Power BI file open
Convert-PowerBIDesktopToASTabular -pbiDesktopWindowName "DemoFile2 -*" -outputPath "$currentPath\SSASV2\" -removeInternalPBITables -Verbose
# Call the diff viewer
$fileV1 = "$currentPath\SSAS\model.bim"
$fileV2 = "$currentPath\SSASV2\model.bim"#Invoke-Command -ScriptBlock {& 'C:\Program Files (x86)\KDiff3\kdiff3.exe' $fileV1 $fileV2} #Kdiff3
Compare-Object (Get-Content $fileV1) (Get-Content $fileV2) -SyncWindow 10 # Powershell Way
You should get this kind of output showing the differences between the two files: