I cannot seem to preserve previously set formatting upon adding a new column in a Power Query.
- Source table has values as percent with two decimals
- I import into PQ and it applies what it thinks is proper formatting:
- I change the formatting to what I want:
- Pivot on the Date Column
- Load it back to the worksheet
- Note that the percent formatting is lost.
If I format this "results" table in Excel as percent with two decimals, and subsequently add "rows" (eg, a new entry in the Source with the same date but a different value) and Refresh, the formatting will be preserved.
But if the new entry requires a new column (eg a new date), the formatting of this new column, when loaded back to Excel, will be General
and not Percentage
.
The Properties for the Query are as below.
Is there a PQ solution for these issues (both the initial and "refresh" formatting)? Or must I resort to VBA with a Worksheet_change event?
Here is the M-Code
for the Query:
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Date", type date}, {"Value", Percentage.Type}}),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"Date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"Date", type text}}, "en-US")[Date]), "Date", "Value", List.Sum)
in
#"Pivoted Column"