Forum Discussion
Complex Compound growth formula - dynamic
Hi all,
I am looking to build a measure in PowerBI that allows me to calculate a new column called baseline in the table1 as per formulas below:
The challenge is tha CM= Current Month is dynamic depending on the month we are. As of today CM=February and CM+1= March; however in a month time CM=March and CM+1=April.
The first formula needs to be applied till Jun-22 and after that second formula should be applied.
Below a sample of the table I am working with.
I should be able to aggregate the result and any level as per columns in the table (Channel, Client or Product)
Any help is well appreciated!
Thanks
Diana
Table1:
| Month Key | Month | DaysofMonth | Relative Month | Channel | Client ID | Product | Avg Daily Usage | Avg Daily Usage Growth MoM % |
| 391 | Jan-22 | 31 | CM-1 | Direct | 1006751 | ABC | 37 | 34% |
| 391 | Jan-22 | 31 | CM-1 | Direct | 1006751 | XYZ | 49 | -4% |
| 391 | Jan-22 | 31 | CM-1 | Direct | 1006751 | HJK | 1 | 0% |
| 391 | Jan-22 | 31 | CM-1 | Direct | 1006909 | ABC | 1,517 | 5% |
| 391 | Jan-22 | 31 | CM-1 | Direct | 1006909 | XYZ | 453 | 5% |
| 391 | Jan-22 | 31 | CM-1 | Direct | 1006909 | HJK | 274 | 18% |
| 391 | Jan-22 | 31 | CM-1 | Tele Sales | 937586 | ABC | 37,048 | 9% |
| 391 | Jan-22 | 31 | CM-1 | Tele Sales | 937586 | XYZ | 25,723 | 6% |
| 391 | Jan-22 | 31 | CM-1 | Tele Sales | 937586 | HJK | 5,121 | 1% |
| 392 | Feb-22 | 28 | CM | Direct | 1006751 | ABC | ||
| 392 | Feb-22 | 28 | CM | Direct | 1006751 | XYZ | ||
| 392 | Feb-22 | 28 | CM | Direct | 1006751 | HJK | ||
| 392 | Feb-22 | 28 | CM | Direct | 1006909 | ABC | ||
| 392 | Feb-22 | 28 | CM | Direct | 1006909 | XYZ | ||
| 392 | Feb-22 | 28 | CM | Direct | 1006909 | HJK | ||
| 392 | Feb-22 | 28 | CM | Tele Sales | 937586 | ABC | ||
| 392 | Feb-22 | 28 | CM | Tele Sales | 937586 | XYZ | ||
| 392 | Feb-22 | 28 | CM | Tele Sales | 937586 | HJK | ||
| 393 | Mar-22 | 31 | CM+1 | Direct | 1006751 | ABC | ||
| 393 | Mar-22 | 31 | CM+1 | Direct | 1006751 | XYZ | ||
| 393 | Mar-22 | 31 | CM+1 | Direct | 1006751 | HJK | ||
| 393 | Mar-22 | 31 | CM+1 | Direct | 1006909 | ABC | ||
| 393 | Mar-22 | 31 | CM+1 | Direct | 1006909 | XYZ | ||
| 393 | Mar-22 | 31 | CM+1 | Direct | 1006909 | HJK | ||
| 393 | Mar-22 | 31 | CM+1 | Tele Sales | 937586 | ABC | ||
| 393 | Mar-22 | 31 | CM+1 | Tele Sales | 937586 | XYZ | ||
| 393 | Mar-22 | 31 | CM+1 | Tele Sales | 937586 | HJK | ||
| 394 | Apr-22 | 30 | CM+2 | Direct | 1006751 | ABC | ||
| 394 | Apr-22 | 30 | CM+2 | Direct | 1006751 | XYZ | ||
| 394 | Apr-22 | 30 | CM+2 | Direct | 1006751 | HJK | ||
| 394 | Apr-22 | 30 | CM+2 | Direct | 1006909 | ABC | ||
| 394 | Apr-22 | 30 | CM+2 | Direct | 1006909 | XYZ | ||
| 394 | Apr-22 | 30 | CM+2 | Direct | 1006909 | HJK | ||
| 394 | Apr-22 | 30 | CM+2 | Tele Sales | 937586 | ABC | ||
| 394 | Apr-22 | 30 | CM+2 | Tele Sales | 937586 | XYZ | ||
| 394 | Apr-22 | 30 | CM+2 | Tele Sales | 937586 | HJK | ||
| 395 | May-22 | 31 | CM+3 | Direct | 1006751 | ABC | ||
| 395 | May-22 | 31 | CM+3 | Direct | 1006751 | XYZ | ||
| 395 | May-22 | 31 | CM+3 | Direct | 1006751 | HJK | ||
| 395 | May-22 | 31 | CM+3 | Direct | 1006909 | ABC | ||
| 395 | May-22 | 31 | CM+3 | Direct | 1006909 | XYZ | ||
| 395 | May-22 | 31 | CM+3 | Direct | 1006909 | HJK | ||
| 395 | May-22 | 31 | CM+3 | Tele Sales | 937586 | ABC | ||
| 395 | May-22 | 31 | CM+3 | Tele Sales | 937586 | XYZ | ||
| 395 | May-22 | 31 | CM+3 | Tele Sales | 937586 | HJK | ||
| 396 | Jun-22 | 30 | CM+4 | Direct | 1006751 | ABC | ||
| 396 | Jun-22 | 30 | CM+4 | Direct | 1006751 | XYZ | ||
| 396 | Jun-22 | 30 | CM+4 | Direct | 1006751 | HJK | ||
| 396 | Jun-22 | 30 | CM+4 | Direct | 1006909 | ABC | ||
| 396 | Jun-22 | 30 | CM+4 | Direct | 1006909 | XYZ | ||
| 396 | Jun-22 | 30 | CM+4 | Direct | 1006909 | HJK | ||
| 396 | Jun-22 | 30 | CM+4 | Tele Sales | 937586 | ABC | ||
| 396 | Jun-22 | 30 | CM+4 | Tele Sales | 937586 | XYZ | ||
| 396 | Jun-22 | 30 | CM+4 | Tele Sales | 937586 | HJK | ||
| 397 | Jul-22 | 31 | CM+5 | Direct | 1006751 | ABC | ||
| 397 | Jul-22 | 31 | CM+5 | Direct | 1006751 | XYZ | ||
| 397 | Jul-22 | 31 | CM+5 | Direct | 1006751 | HJK | ||
| 397 | Jul-22 | 31 | CM+5 | Direct | 1006909 | ABC | ||
| 397 | Jul-22 | 31 | CM+5 | Direct | 1006909 | XYZ | ||
| 397 | Jul-22 | 31 | CM+5 | Direct | 1006909 | HJK | ||
| 397 | Jul-22 | 31 | CM+5 | Tele Sales | 937586 | ABC | ||
| 397 | Jul-22 | 31 | CM+5 | Tele Sales | 937586 | XYZ | ||
| 397 | Jul-22 | 31 | CM+5 | Tele Sales | 937586 | HJK |
1 Reply
- lbendlinSuper User
As long as this data source is accessed in import mode and refreshed at least once a month (ideally at the beginning of the month) you can easily create that column in Power Query.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZRNS8NAFEX/Sgi4m8J8ZDLJsioiEVe6UEsXqWQhhCJVF/5782ILlmEm91pIScKcx3lz32SzKV1rSlV2/X5l7XTj5On67TC8fk43Rus6eHm1vrya/ovMzwXBq4tyq+CqT88vC1Wrdlqw4qredncLVYtC1mmwaqvbpR0wyhvp31Mll9qvvKNrLjVvQyXrm3TRx2Eciod+HD6mh9YF39T59l1QumpkMVs0swHWq2Cl/Zotmt0Br4wV1JyqSrGbYfdb1TbZ6Z8vAju2x2LHBnDsbEBZjJY8m7Mslp2kf5CIanYm/pAyWvf9AfrqsVjsCWG0ZCp3CKMlU7nHGJo7SiKqaO7y9Vu/n0iN5g5hsSeE0ZKp3CGMlkzlHmNo7iiJqKK5+3livtnzDmGxJ4TRkqncIYyWTOUeY2juKImoornL2+5rz553CIs9IYyWTOUOYbRkKvcYQ3NHSUQVzT3M5MiedwiLPSGMlkzlDmG0ZCr3GENzR0lEFch9+wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month Key" = _t, Month = _t, DaysofMonth = _t, Channel = _t, #"Client ID" = _t, Product = _t, #" Avg Daily Usage " = _t, #"Avg Daily Usage Growth MoM %" = _t]), #"Replaced Value" = Table.ReplaceValue(Source,"-"," 1 20",Replacer.ReplaceText,{"Month"}), #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Month", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Relative Month", each let rm = Date.Year([Month])*12+Date.Month([Month])-Date.Year( DateTime.LocalNow())*12-Date.Month(DateTime.LocalNow()) in if rm = 0 then "CM" else if rm < 0 then "CM" & Text.From(rm) else "CM+" & Text.From(rm)) in #"Added Custom"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".