Forum Discussion
Need help to resolve Excel Formula using Let,Take,index,Sort,Unique,HSTACK,MMULT,TOROW,MONTH.
- Sep 07, 2023
Thank you. Do I understand correctly that csv62719 is you source file. If to avoid Power Query we copy/paste data from it into the sheet in main file, here by formula create massaged range and based on it and month/year/monthid parameters create aggregated result. Workflow is correct?
Okay, thank you for the confirmation
The formula is working excellent with one exception the VISA section of my download is giving me an error message #CALC when I execute the formula against the download. I can see when I evaluate the formula the LAMBDA statement is showing an error #VALUE in the amount field. I guess the #CALC is related to this as an empty array. if it is a problem with the download I can always go back to the RBC bank and ask them to fix the problem.
Output
Input Data
Name Manager
Thanks for having a look at this for me.
- Norman_McIlwaineNov 27, 2023Brass Contributor
I have a small problem with not having the capabilities to refresh the data on a IPAD, it is imposable to change the month and get accurate results in the Excel output. I have tried to work around this and still run into the same problem, I have also requested this as an enhancement to Excel. However, it is not high on their priority list, and I can't get enough votes to get the fix to move it up on the list.
Is there any other way to get the results without having to do a refresh every time.?
- Norman_McIlwaineOct 08, 2023Brass ContributorThank you for the quick and excellent response.
- SergeiBaklanOct 08, 2023MVP
With Power Query it's better to calculate it separately (Opening Balance query in attached file), result will be like
and Closing Balance is calculated as
=SUBTOTAL(109,[Amount]) + Opening_Balance[Opening Balance]
- Norman_McIlwaineOct 07, 2023Brass Contributor
I am trying to set current month's ending balance to be next month's opening balance. I have tried various different date functions (i.e.PreviousMonth) but cannot get this to work. Is this possible in PQ?
(previous months balance)
Opening Balance 2,349.73 (Current month)
Balance 3,594.20
- SergeiBaklanSep 27, 2023MVP
Norman_McIlwaine , okay, thank you for the feedback.
- Norman_McIlwaineSep 27, 2023Brass ContributorThanks problem solved.
- SergeiBaklanSep 27, 2023MVP
Replacement table is in the first sheet of the file, in grid.
Modify it here and Refresh All. Power Query only reads that table.
- Norman_McIlwaineSep 27, 2023Brass Contributor
- Norman_McIlwaineSep 27, 2023Brass ContributorI have been away for a while and I am just getting back into PQ again. I was trying to add a new entry in the table replacements and I find that I can not do this using PQ editor. I believe this is because when I open the table it is in preview mode. All that I can do is to view the data in the table. How can I edit the table to insert a new row ?
- Norman_McIlwaineSep 12, 2023Brass ContributorThanks for helping me out on this one. I was entering excel functions instead of M code functions. I must get a book on M code.
Thanks again. - SergeiBaklanSep 12, 2023MVP
I added
fnPayment = (str as text) => Text.Trim( Text.Combine( List.Skip( Splitter.SplitTextByCharacterTransition({"0".."9"}, {" "} )(str), (q) => Text.StartsWith(q, "PAYMENT -") and Text.Length(q) = 14 ) ) ),
into the body of query and replace texts with help of it.
- Norman_McIlwaineSep 12, 2023Brass Contributor
Thank you very much for the enhancements it looks fabulous. I have one problem which I have been working on all day.
Its how do I do a removal on a transaction without the use of the * or ? in a find and replace situation.
In Excel I could do a find and replace with find PAYMENT???????? replace with XXXXXXXXXXXXX.
Unfortunately without the use of * or ? in PQ it is difficult and I have tried some work arounds but all failed with errors.
I would like to change the transaction PAYMENT - XXXX with nothing leaving the remainder of the text in the field where this text appears in the transaction field.
Example
If transaction = PAYMENT - 1155 NEO FINANCIAL replace with NEO FINANCIAL.
The numeric value changes on every occurrence therefor, I tried to remove the first 15 characters PQ and got into a lot of errors. What would be your work around this statement?
If you could help me out I would appreciate it very much.
- SergeiBaklanSep 11, 2023MVP
I added the table in first sheet for the replacements
In second sheet is the list of accounts with added empty record
it is used for drop-down list in the reporting. Didn't transfer 4.51e+15 into long number and keep it as it is. Since in csv files it could be shown as 4.51e+15, 4.5140e+15, whatever. It looks like you open csv in Excel and save it on closing, thus account is saved as Excel transforms it.
Not critical, but to be safe better not to open csv in Excel such way. Better to allow legal connector in options
With that in new Excel file you may insert csv as Data->Get data->Legacy Wizard->From text and on third step set data type as Text for Account column
Above is assuming if 45000... was not converted on 4e+15 before.
Finally in Reports sheet added one returned by Power Query
you only need to refresh it if parameters were changed.
- Norman_McIlwaineSep 09, 2023Brass ContributorSorry Sergei, Of course the report is after you pass the transaction from PQ to excel run it through the Excel formula. I was not thinking as I am in the middle of moving houses as well as this project.
- Norman_McIlwaineSep 09, 2023Brass Contributor
It is looking very good and I am able to follow the M source for Transaction changes on the csv file. However i cannot see how the report is structured in the source code. If for instance, rather than type in and remember a16 digit account numbers I could have a pick box attached to the id field of the four account numbers. similar to the pick box I added to the Excel output.
The Total Income and Total expenses (which was a great after thought thank you) was a nice surprise in the report.
PETRO CANADA AND Esso are Gasoline and should be summed together if possible?
The Source in PQ is showing Petro Canada as 29.47 and the report shows 49.05 with only one Petro Canada entry in the Transaction field for the month = 8 could I be missing something in the source file for the month = 8.
If I could see the source for the report I perhaps could help.
Thanking you for any assistance.
- Norman_McIlwaineSep 09, 2023Brass ContributorThanks for the quick response, I will give a try.
- SergeiBaklanSep 09, 2023MVP
Tried to correct, please check in attached if I understood the logic correctly.
Query is within the file. On ribbon Data->Queries and Connections. Double click on right pane on query name to open it in Power Query Editor. Within it you may use Home->Advanced Editor to play with generated M-code.
- Norman_McIlwaineSep 09, 2023Brass Contributor
Thank you for looking at this for me, It does look good however I have noticed a few of the items that I require are not in the output and should have been moved from columns 5 to 6.
PENSON,
OLD AGE SECURITY
CPP,
PROV/LOCAL GOV PYMT,
ESSO CIRCLE K
OD INTERESTWhat I tries to do in Power Query was to remove all the entries that contain "IDP" in both columns by using the find and replace function. But I could never use a wild card like *IDP* to remove all the entries. Then I can move the above entries to the corresponding columns without any fear of losing important data. Then I can remove the columns that I do not require.
How to do this in Power Query I do not know. could you send me the Power Query inputs to achieve this output for my perusal then I might understand how power query works. I will send you the latest download to use. - SergeiBaklanSep 08, 2023MVP
Preliminary I added formula into Report sheet.
- SergeiBaklanSep 08, 2023MVP
Okay, thank you. Let agree first how you'd like to massage the source data. I'll add the formula after that. Draft done by Power Query is attached.
In first sheet is filePath for your csv file
You need to change it on your actual one and click Refresh All. Result is in second sheet.
If you prefer to keep your file on OneDrive or SharePoint query shall be adjusted a bit. Just inform is that the case.
Another point, perhaps you have the set of csv files. If so not necessary to copy/paste information from each of them. You may create folder (again, on local drive or OneDrive, that's important to know), put each new csv into that folder and Power Query could automatically combine and transform them. If that's and option it's important to know are transactions in such files overlapping or not.
But let eat elephant by a bit. First please check attached and clarify with possible options regarding the data source.
- Norman_McIlwaineSep 08, 2023Brass Contributor
Thank you so much for your support and help. I have made the necessary updates to the formula to accept the new massaged download. it took a while and I now have what is an acceptable output to assist me in performing my own finances. I am including the file for your perusal if you think I could make any other changes please let me know. In the meantime, I am going to try Power Query to assist me in massaging the download prior to using it with your formula.
Once again thank you for your help, you surly are the best on this subject.
- SergeiBaklanSep 07, 2023MVP
Thank you. Do I understand correctly that csv62719 is you source file. If to avoid Power Query we copy/paste data from it into the sheet in main file, here by formula create massaged range and based on it and month/year/monthid parameters create aggregated result. Workflow is correct?
- Norman_McIlwaineSep 07, 2023Brass Contributor
Sorry for the delay I was trying to get the documents to uploaded to you. I really do not like Power Query as it appears to have a lot of limitations that Excel has got. Can we stick with the excel formula?
- SergeiBaklanSep 07, 2023MVP
Okay, I see. Could you please share what is the name of table returned by Power Query
If to stay on any cell within the table you may see it here
I'll try to adjust formula when.
- Norman_McIlwaineSep 06, 2023Brass Contributor
I have learned so much from you and your formula that I wish to keep it as I am not that comfortable using power query. I have never used it before and just picked it up through a couple of videos that I watched over the past few days. I am not that sure with the formulas contained it the power Query, but will have to pick it up at a fast pace. Beside that most of the cleanup of the download was done manually with a little help from power query.
In the meantime how do you make reference to the data in the formula to delete the last column which contains a lot of #CALC errors in every row. I have tried to make the appropriate changes and moved things around a bit but that's about all my knowledge of Excel. What I have learned is from you and I am very grateful for the experience thank you again.