Forum Discussion
Rohan110
Jun 21, 2023Copper Contributor
Pivot Table group positive and negative data
As you can see in the below image i have created two separate Pivot tables to group the positive and negative values separately. 1. Is there a way to group positive and negative value as sub groups ...
- Jun 28, 2023
Attached an example with a single [Amount] column with Positive & Negative values:
Edit the query in the attachment and follow the steps in APPLIED STEPS (all done with the UI). Once you've separated your [Income] & [Expense] (the added Custom steps) and removed [Amount] that's no longer necessary, right-click on column [Category] and in the drop-down menu select Unpivot Other Columns
IMPORTANT:
- For [Expense] you'll see I used function Number.Abs to convert to negative [Amount]s to positive. If you want your Expense to show negative in your PivotTable then remove Number.Abs (you will have to adjust the Graph DAX measure)
- When you add Custom Columns [Income] & [Expense] Power Query doesn't auto. Type the columns. Taking ex. [Income] when you create it, it displays exactly as below in PQ formula bar:
You must edit the formula and add, before ): , type number then Validate:
You must do the same for the [Expense] column
Reason is: default data Type in Power Query is Type any. Column(s) of Type any loaded to the Excel Data Model will be assigned the Type Text (no Sum, Avg... possible)
Lorenzo
Jun 22, 2023Silver Contributor
When you find a minute, When Array table is updated/ sorted, the adjacent column cells aren't aligned/linked is pending your feedback...
Re. your Pivot Table question the following is doable (there's a blank row between Categories for clarity but it can be removed) but not with a classic Pivot Table only, this is a single Pivot though:
You tagged your thread with Excel, Excel on Mac, Excel on mobile, Power BI. The above is acheivable with Excel >= 2013 on Windows and Power BI but not on Excel on Mac. Interested?
Rohan110
Jun 28, 2023Copper Contributor
Hi Lz.,
I use Microsoft office 365, with the latest excel version. Please provide your suggestion.
I use Microsoft office 365, with the latest excel version. Please provide your suggestion.
- LorenzoJun 28, 2023Silver Contributor
Hi Rohan110
Sample attached:
#1 Table1 is loaded to Power Query to Unpivot [Expense] & [Income] (kept the default "Attribute" column name - easy to change)
#2 Unpivoted table loaded to the Excel Data Model (Windows only)
#3 A couple of DAX measures (don't ask too much I have very basic knowledge)
- Rohan110Jun 28, 2023Copper ContributorHi L z.
Thanks for your quick response. Could you please let me know how you carried out unpivoting step which resulted in categorizing the data as rows and columns.
Also, my raw data has a single column of income and expenses, income in positive values and expense as negative values. Does this mean i need to split them into separate column, positive and negative and then carryout your method? Appreciate your support on this.