Forum Discussion
Adding Custom Column To Obtain Prior Month Balance
- 3 years ago
JRParker my bad. I wanted to sort by date upon grouping but then changed my mind... Before I give up and commit a suicide, lets replace function f with the following
f = (tbl as table) as table => [sorted = Table.Sort(tbl, "Date"), // Sort the table by the "Date" column prior_month = {0} & List.RemoveLastN(sorted[Balance], 1), // Create a list of prior month balances by removing the last balance value and appending a 0 at the beginning out = Table.FromColumns(Table.ToColumns(sorted) & {prior_month}, Table.ColumnNames(sorted) & {"Prior Month"}) // Add the prior month balances as a new column named "Prior Month" ] [out]
JRParker See if this helps, this video covers all of the common time intelligence scenarios.
The PBIX is available here: MicrosoftHatesGregsQuickMeasures/PBIX at main · gdeckler/MicrosoftHatesGregsQuickMeasures (github.com)
Otherwise, Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
Thanks Greg... replied to my original post, but will reply directly to your post.
....the intent is create the custom column in Power Query; not Data View. Here is sample data; all but the last column is sample data from the table, with the last column the custom column with the expected results:
| Entity | Account Number | Date | Balance | Prior Month |
| FVE | 4000 | 3/31/2022 | ($2,330.08) | $0.00 |
| FVE | 4000 | 4/30/2022 | ($4,890.36) | ($2,330.08) |
| FVE | 4000 | 5/31/2022 | ($5,972.62) | ($4,890.36) |
| FVE | 4000 | 6/30/2022 | ($13,285.10) | ($5,972.62) |
| FVE | 4000 | 7/31/2022 | ($14,388.49) | ($13,285.10) |
| FVE | 4000 | 8/31/2022 | ($20,713.00) | ($14,388.49) |
| FVE | 4000 | 9/30/2022 | ($32,338.88) | ($20,713.00) |
| FVE | 4000 | 10/31/2022 | ($31,558.75) | ($32,338.88) |
| FVE | 4000 | 11/30/2022 | ($47,740.27) | ($31,558.75) |
| FVE | 4000 | 12/31/2022 | ($49,812.30) | ($47,740.27) |
| FVE | 4000 | 1/31/2023 | ($2,910.00) | ($49,812.30) |
| FVE | 4000 | 2/28/2023 | ($15,823.60) | ($2,910.00) |
| FVE | 4000 | 3/31/2023 | ($25,206.91) | ($15,823.60) |
| FVE | 4000 | 4/30/2023 | ($35,934.17) | ($25,206.91) |
| FVE | 4000 | 5/31/2023 | ($57,606.09) | ($35,934.17) |