Forum Discussion
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 CSV to an S3 Bucket. Ideally I want to do this programmatically so we can schedule it and forget about it. I'm able to export the data by using PowerShell, however, its not completely in the format I'd want. When I run the query the resulting CSV file contains [ ] around the column names. I've attempted to use SELECTCOLUMNS to rename the columns but this has the same result. Is there any way to achieve what I want in the DAX query?
Current DAX
EVALUATE
SUMMARIZECOLUMNS (
'XactlyTemplate'[Performance Month],
'XactlyTemplate'[Invoice Number1],
'XactlyTemplate'[Transaction Date],
'XactlyTemplate'[Customer Unique ID],
'XactlyTemplate'[Customer Name],
'XactlyTemplate'[Customer State],
'XactlyTemplate'[Customer Region],
'XactlyTemplate'[ContractID],
'XactlyTemplate'[Contract Start Date],
'XactlyTemplate'[Contract End Date],
'XactlyTemplate'[Order/Contract Term in Months],
'XactlyTemplate'[Order/Contract Term in Days],
'XactlyTemplate'[Usage Type],
'XactlyTemplate'[AcctAssignGroup],
'XactlyTemplate'[Revenue Type],
'XactlyTemplate'[Transaction Type Description],
'XactlyTemplate'[Stock_Material Code],
'XactlyTemplate'[Stock_Material Code Description],
'XactlyTemplate'[Product Name],
'XactlyTemplate'[Sub-Product],
'XactlyTemplate'[Recurring/Non-Recurring],
'XactlyTemplate'[Currency],
'XactlyTemplate'[Sales Org],
'XactlyTemplate'[Business Unit],
'XactlyTemplate'[Partner Account],
'XactlyTemplate'[Partner Name],
'XactlyTemplate'[Sales Team],
'XactlyTemplate'[Employee_ID_2],
'XactlyTemplate'[Employee_2_Split_Percentage],
'XactlyTemplate'[Employee_ID_3],
'XactlyTemplate'[Employee_3_Split_Percentage],
'XactlyTemplate'[Employee_ID_4],
'XactlyTemplate'[Employee_4_Split_Percentage],
'XactlyTemplate'[Employee_ID_5],
'XactlyTemplate'[Employee_5_Split_Percentage],
'XactlyTemplate'[Employee_ID_6],
'XactlyTemplate'[Employee_6_Split_Percentage],
'XactlyTemplate'[Employee_ID_7],
'XactlyTemplate'[Employee_7_Split_Percentage],
'XactlyTemplate'[Employee_ID_8],
'XactlyTemplate'[Employee_8_Split_Percentage],
'XactlyTemplate'[Employee_ID_9],
'XactlyTemplate'[Employee_9_Split_Percentage],
'XactlyTemplate'[Employee_ID_10],
'XactlyTemplate'[Employee_10_Split_Percentage],
'XactlyTemplate'[Employee_ID_1],
TREATAS ( { DATE ( 2020, 9, 1 ) }, 'XactlyTemplate'[Performance Month] ),
"No_of_Units", CALCULATE ( SUM ( 'XactlyTemplate'[# of Units] ) ),
"Total_Amt", CALCULATE ( SUM ( 'XactlyTemplate'[Total Amt] ) ),
"Employee_1_Split_Percentage", CALCULATE ( SUM ( 'XactlyTemplate'[Employee_1_Split_Percentage] ) )
)
EDIT: DAX to remove invalid SELECTCOLUMNS
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
12 Replies
- lbendlinSuper User
When I run such a query in DAX Studio I don't get any square brackets in the output format. How are you piping the results of the query into your output file?
- mark_carlisleAdvocate IV
Confirmed your test, the square brackets are not present in DAX Studio when running the same query. The full PowerShell script is below and is ran in PowerShell 7.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.AdomdClient") $PowerBIEndpoint = "REDACTED" $PowerBILogin = "" $PowerBIPassword = "" $Query = "EVALUATE SUMMARIZECOLUMNS ( 'XactlyTemplate'[Performance Month], 'XactlyTemplate'[Invoice Number1], 'XactlyTemplate'[Transaction Date], 'XactlyTemplate'[Customer Unique ID], 'XactlyTemplate'[Customer Name], 'XactlyTemplate'[Customer State], 'XactlyTemplate'[Customer Region], 'XactlyTemplate'[ContractID], 'XactlyTemplate'[Contract Start Date], 'XactlyTemplate'[Contract End Date], 'XactlyTemplate'[Order/Contract Term in Months], 'XactlyTemplate'[Order/Contract Term in Days], 'XactlyTemplate'[Usage Type], 'XactlyTemplate'[AcctAssignGroup], 'XactlyTemplate'[Revenue Type], 'XactlyTemplate'[Transaction Type Description], 'XactlyTemplate'[Stock_Material Code], 'XactlyTemplate'[Stock_Material Code Description], 'XactlyTemplate'[Product Name], 'XactlyTemplate'[Sub-Product], 'XactlyTemplate'[Recurring/Non-Recurring], 'XactlyTemplate'[Currency], 'XactlyTemplate'[Sales Org], 'XactlyTemplate'[Business Unit], 'XactlyTemplate'[Partner Account], 'XactlyTemplate'[Partner Name], 'XactlyTemplate'[Sales Team], 'XactlyTemplate'[Employee_ID_2], 'XactlyTemplate'[Employee_2_Split_Percentage], 'XactlyTemplate'[Employee_ID_3], 'XactlyTemplate'[Employee_3_Split_Percentage], 'XactlyTemplate'[Employee_ID_4], 'XactlyTemplate'[Employee_4_Split_Percentage], 'XactlyTemplate'[Employee_ID_5], 'XactlyTemplate'[Employee_5_Split_Percentage], 'XactlyTemplate'[Employee_ID_6], 'XactlyTemplate'[Employee_6_Split_Percentage], 'XactlyTemplate'[Employee_ID_7], 'XactlyTemplate'[Employee_7_Split_Percentage], 'XactlyTemplate'[Employee_ID_8], 'XactlyTemplate'[Employee_8_Split_Percentage], 'XactlyTemplate'[Employee_ID_9], 'XactlyTemplate'[Employee_9_Split_Percentage], 'XactlyTemplate'[Employee_ID_10], 'XactlyTemplate'[Employee_10_Split_Percentage], 'XactlyTemplate'[Employee_ID_1], TREATAS ( { DATE ( 2020, 9, 1 ) }, 'XactlyTemplate'[Performance Month] ), `"No_of_Units`", CALCULATE ( SUM ( 'XactlyTemplate'[# of Units] ) ), `"Total_Amt`", CALCULATE ( SUM ( 'XactlyTemplate'[Total Amt] ) ), `"Employee_1_Split_Percentage`", CALCULATE ( SUM ( 'XactlyTemplate'[Employee_1_Split_Percentage] ) ) )" $ExportPath = "REDACTED\Export.csv" $Connection = New-Object -TypeName System.Data.OleDb.OleDbConnection $Results = New-Object System.Data.DataTable $Connection.ConnectionString = "Provider=MSOLAP.8;Data Source="+ $PowerBIEndpoint +";UID="+ $PowerBILogin +";PWD="+ $PowerBIPassword $Connection.Open() $Adapter = New-Object -TypeName System.Data.OleDb.OleDbDataAdapter $Query ,$Connection $Adapter.Fill($Results) $Results | export-csv -Path $ExportPath -NoTypeInformation -Encoding UTF8noBOM $Connection.Dispose() $Connection.Close()SOURCE: https://sqlitybi.com/how-to-export-data-from-power-bi-using-xmla-endpoints/
- lbendlinSuper User
Hmm. The square brackets are kinda needed as they separate the column name from the table name. You cannot guarantee that the query only returns values from a single host table. What would you want to replace them with?
Also, what made you move from the ADOmd client to the OLEdb OLAP.8 client?