Forum Discussion
mark_carlisle
5 years agoAdvocate IV
Removing square brackets from column headers DAX query
I'm attempting to streamline an extremely convoluted process developed by one of my colleagues that involves exporting data from a Power BI report, renaming various columns, then uploading the final ...
- 5 years ago
You're right. I see it too. How about this?
$Results | export-csv -Path $ExportPath -NoTypeInformation
(Get-Content -Path $ExportPath ) -replace '[\[\]]' | Set-Content -Path $ExportPath
lbendlin
5 years agoSuper User
You're right. I see it too. How about this?
$Results | export-csv -Path $ExportPath -NoTypeInformation
(Get-Content -Path $ExportPath ) -replace '[\[\]]' | Set-Content -Path $ExportPath
Anonymous
4 years agoNot applicable
Here's a cleaner way, directly modifying the column names in the dataset, only having to write the file once. The Split method treats the brackets as delimiters and selects the second element of the resulting array as the column name.
$Adapter.Fill($Results)
$Results.Columns.ColumnName |
ForEach-Object {
$Results.Columns[$_].ColumnName = $_.Split(@('[',']'))[1]
}
$Results | Export-CSV -Path $ExportPath -NoTypeInformation