Do you really can diff Power BI files?
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 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:
1
2
3
4
5
6
7
8
|
InputObject SideIndicator
----------- -------------
"name": "cf391530-7ccc-48d2-a86b-f14e16122e89", =>
"name": "Adventure Works Sales", =>
"expression": "CALCULATE(sum(Sales[ReturnAmount]), 'Product'[BrandName] = \"Adventure Works\")", =>
"name": "b9f7b199-f8a7-4ca4-83a4-35b5f6724554", <=
"name": "Teste", <=
"expression": "sum(Sales[ReturnAmount])", <=
|
Or if you use a tool like kdiff3, uncommenting line 19 of the script:
Have fun!!
Share!