Forum Discussion
queenbean84
Jul 12, 2023Copper Contributor
Income Statement by month using pivot table
I am trying to create an income statement by month for the attached file. It will not allow me to group by month. I also want to have a grand total for PROFIT OR (LOSS). Any help here would be app...
flexyourdata
Jul 12, 2023Iron Contributor
Hi queenbean84
You can't group the date field because you have a calculated item on the Group field.
I downloaded a copy of your file, deleted the PROFIT+LOSS item from the Group field, and afterwards I was able to group the date field.
Unfortunately, it seems you can't have a calculated item and a grouped field in the same report:
Another way to handle this is to pre-calculate the profit-and-loss rows using Power Query, then build your pivot table from the query result.
Here's the M-code for the query:
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Renamed Columns" = Table.RenameColumns(Source,{{"Amount", "AmountOrig"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Amount", each if [Group]="Expense" then [AmountOrig]*-1 else [AmountOrig]),
#"Replaced Value" = Table.ReplaceValue(#"Added Custom","Income","Profit+Loss",Replacer.ReplaceText,{"Group"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","Expense","Profit+Loss",Replacer.ReplaceText,{"Group"}),
#"Reordered Columns" = Table.ReorderColumns(#"Replaced Value1",{"Date", "Description", "AmountOrig", "Amount", "Category", "Property", "Unit", "Group"}),
ProfitAndLoss = Table.RemoveColumns(#"Reordered Columns",{"AmountOrig"}),
Result = Table.Combine({Source,ProfitAndLoss})
in
Result
Updated file attached.