KnightFhawker
New Member
- Joined
- Dec 7, 2016
- Messages
- 17
- Office Version
- 365
- 2016
- Platform
- Windows
- Mobile
- Web
Hello,
It has been a very long time since I have posted on here, so I apologize in advance if I am rusty on any preferred protocol and information/data to include on a post.
I need to be able to able to obtain the average daily balance of each case, for each quarter. Since I have not found a simple function in Power Query to accomplish this directly, I am structuring the data to create a listing of the balance for each day. I will then take the average for each quarter as needed.
Through my research online, I have been able to accomplish this daily balance (running total) for one individual case using a Power Query function, but since I have many different cases (each with a different case number as the column header), I have been unable to find the right coding to repeat this function for each of the cases.
Two main hurdles are that not only will the headers (case numbers) be changing each time the data is pulled, but the number of cases (columns) will also be changing. With these two hurdles in mind, I need to be able to repeat the function, to have each run of the function add the resulting column to the same table, and have the function repeat based upon the dynamically varying number of columns that will have differing column header names. To begin working toward resolving this issue, I have built a query that can be used as a reference list for all of the column names (case numbers) in List format (Query name: MasterCaseList).
I hope that this information, along with some screenshots and sample code that I have listed below, will provide a clear understanding of what I need to accomplish and where I am currently stuck at in the process. Any assistance would be greatly appreciated. Please let me know if you have any questions, and if there is any additional information that I can provide to make things more clear.
Code for Power Query Function: fxRunningTotal
Code for Query: CalendarCaseAverages
The above screenshots and code show the successful run of the function, which essentially provides a running total list to capture the total balance, for a single case, for each date. However, the full table has many columns listing the activity for each case, by date, throughout the full period of time pulled from the source system.
The additional complexity to this is that there will always be a dynamic header that will be the actual case numbers ("A12345", "B45678", etc., instead of "Case1", "Case2", and "Case3", which I used to keep this example generic). Also, the number of columns will change each quarter when the complete data is pulled for the full period of time, up to the most recent quarter (See screenshot below).
I am trying to code the "CalendarCaseAverages" Query to repeat the function above for each dynamically named column, and for each of the dynamically changing number of cases that will be included each subsequent quarter.
I imagine that a List.Generate or List.Accumulate might be helpful functions to use, but either way I am unsure how to even reference the Source and incorporate the function to allow for more than one column of data since both sets of code are based upon "List" functions.
I am using Power Query, because this data will eventually need to dynamically populate tables into an Excel workbook for each individual month.
Again, I hope all of this information makes sense, and that I have provided what would be needed to understand where I stand at the moment, but please do not hesitate to ask any questions or inquire about any additional information that you believe would be helpful.
Any suggestion would be greatly appreciated. Thank you in advance for your time and assistance.
It has been a very long time since I have posted on here, so I apologize in advance if I am rusty on any preferred protocol and information/data to include on a post.
I need to be able to able to obtain the average daily balance of each case, for each quarter. Since I have not found a simple function in Power Query to accomplish this directly, I am structuring the data to create a listing of the balance for each day. I will then take the average for each quarter as needed.
Through my research online, I have been able to accomplish this daily balance (running total) for one individual case using a Power Query function, but since I have many different cases (each with a different case number as the column header), I have been unable to find the right coding to repeat this function for each of the cases.
Two main hurdles are that not only will the headers (case numbers) be changing each time the data is pulled, but the number of cases (columns) will also be changing. With these two hurdles in mind, I need to be able to repeat the function, to have each run of the function add the resulting column to the same table, and have the function repeat based upon the dynamically varying number of columns that will have differing column header names. To begin working toward resolving this issue, I have built a query that can be used as a reference list for all of the column names (case numbers) in List format (Query name: MasterCaseList).
I hope that this information, along with some screenshots and sample code that I have listed below, will provide a clear understanding of what I need to accomplish and where I am currently stuck at in the process. Any assistance would be greatly appreciated. Please let me know if you have any questions, and if there is any additional information that I can provide to make things more clear.
Code for Power Query Function: fxRunningTotal
Power Query:
(values as list) as list =>
let
RT = List.Generate
(
() => [RT = values{0}, counter = 0],
each [counter] < List.Count(values),
each [RT = [RT] + values{[counter] + 1}, counter = [counter] + 1],
each [RT]
)
in
RT
Code for Query: CalendarCaseAverages
Power Query:
let
Source = CalendarCaseActivity[Case1],
BufferedValues = List.Buffer(Source),
RT = Table.FromList(fxRunningTotal(BufferedValues), Splitter.SplitByNothing(), {"RT"}),
Columns = List.Combine({Table.ToColumns(RT)}),
#"Converted To Table" = Table.FromColumns(Columns, List.Combine({Table.ColumnNames(CalendarCaseActivity)}))
in
#"Converted To Table"
The above screenshots and code show the successful run of the function, which essentially provides a running total list to capture the total balance, for a single case, for each date. However, the full table has many columns listing the activity for each case, by date, throughout the full period of time pulled from the source system.
The additional complexity to this is that there will always be a dynamic header that will be the actual case numbers ("A12345", "B45678", etc., instead of "Case1", "Case2", and "Case3", which I used to keep this example generic). Also, the number of columns will change each quarter when the complete data is pulled for the full period of time, up to the most recent quarter (See screenshot below).
I am trying to code the "CalendarCaseAverages" Query to repeat the function above for each dynamically named column, and for each of the dynamically changing number of cases that will be included each subsequent quarter.
I imagine that a List.Generate or List.Accumulate might be helpful functions to use, but either way I am unsure how to even reference the Source and incorporate the function to allow for more than one column of data since both sets of code are based upon "List" functions.
I am using Power Query, because this data will eventually need to dynamically populate tables into an Excel workbook for each individual month.
Again, I hope all of this information makes sense, and that I have provided what would be needed to understand where I stand at the moment, but please do not hesitate to ask any questions or inquire about any additional information that you believe would be helpful.
Any suggestion would be greatly appreciated. Thank you in advance for your time and assistance.