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, in your source data such Id is transforming into number. When we wrap group by SUBSTITUTE it returns back as text. However, Id in filter is still the number. Since number <> text, formula finds nothing and returns an error.
The workaround could be to transform Id into the text the same way, i.e. use
Id, SUBSTITUTE(CHOOSECOLS(monthRange, 1),"",""),
When it shall return correct result. Entire formula will be
=LET(
date, CHOOSECOLS(range, 2),
rangeId, CHOOSECOLS(range, 1),
monthRange, FILTER(range,
(EOMONTH(date,0) = EOMONTH( DATE(year,monthNumber,1), 0 ))*
IF( monthID = "", 1, ( rangeId = monthID ) )
),
Id, SUBSTITUTE(CHOOSECOLS(monthRange, 1),"",""),
transaction, CHOOSECOLS(monthRange, 4),
type, CHOOSECOLS(monthRange, 5),
amount, CHOOSECOLS(monthRange, 6),
groupIndexes, {1,4,5},
group, SUBSTITUTE( UNIQUE( CHOOSECOLS(monthRange, groupIndexes ) ),"",""),
result,VSTACK({"Id","Transaction","Type","Amount"},
HSTACK(
group,
BYROW( group,
LAMBDA(v, SUM(
FILTER(amount,
(Id = INDEX(v,1,1) )*
(transaction = INDEX(v,1,2) )*
(type = INDEX(v,1,3) )
)
) )
)
) ), result
)
which is in With ID sheet attached.
Changed the source Id to text and full Id text. It all looks good now.
Thanks for the help
- 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.