Lookup value based on last matching criteria in Google Sheets - arrays

Below is an example of a table I have. I am trying to find the previous bank total amount and then adding the current transaction amount.
I am able to find the previous total amount using =INDIRECT(ADDRESS(ROW()-1,COLUMN())) and then able to add it using SUM() method.
But the problem is I have multiple banks account and in some case, the previous row bank is different from the current row bank.
How can I find the previous total amount depending on the current row bank name?
I have also shared an Expected Result Column if someone doesn't understand what I am trying to do.
Any help would be appreciated.

try:
=ARRAYFORMULA(IF(D2:D="",,MMULT((D2:D=TRANSPOSE(D2:D))*(ROW(D2:D)>=
TRANSPOSE(ROW(D2:D)))*(TRANSPOSE(C2:C)), ROW(D2:D)^0)))

Related

Google Data Studio : how to obtain a SUM related to a COUNT_DISTINCT?

I have a dataset including 3 columns :
ID transac (The unique ID of the transaction - Dimension)
Source (The source of the transaction - Dimension)
Amount € (The amount of the transaction - Stat)
screenshot of my dataset
To Count the number of transactions (for one or more sources), i use COUNT_DISTINCT function
I want to make the sum of the transactions amounts (for one or more sources). But i don't want to additionate the amounts of the transactions with the same ID !
Is there a way to do this calcul with a DataStudio function ?
Thanks for your answers. :-)
EDIT : I saw that we could do this type of calculation via SQL here and I would like to do this in DataStudio (so that I don't have to pre-calculate the amounts per source.)
IMO, your dataset contains wrong data. Each value should be relative only to that line, but this is not the case: if the total is =20, each line should describe the participation of that line to the total. With 4 sources, each line should be =5 or something else that sums 20.
To solve it in DataStudio, you need something like CALCULATE function in PowerBI, but currently DataStudio doesn't support this feature.
But there are some options to consider to repair your data:
If you're sure there are always 4 sources, just create a new calculated field with the expression Amount/4 and SUM it. It is not an elegant solution, but it works.
If your data source is Google Sheets, you can easily repair the data using formulas, like in this example:
Link to spreadsheet
For this spreadsheet, I used this formula in adjusted_amount column: =C2/COUNTIF(A:A,A2). With this column in DataStudio, just use the usual SUM aggregation function to summarize it correctly.

Can you create dynamic formulas in Google Sheets?

So I'm just starting out creating a portfolio tracker within Google Sheets. I'm using the Google Finance methods to get the stocks name and all the relevant data that I need. The only issue is that I can't figure out how to populate the specific data I need without having to manually type out the same formula's for each stock I want data for.
For example... Each row in the first column would contain the ticker symbol for that specific stock. If I bought a new stock, I would just type in the ticker symbol in cell A1 and this would populate the necessary fields such as price and so on. If I bought another stock I would essentially do the same thing but now in A2.
I know that you can get the price of a stock by doing
=GOOGLEFINANCE(A1, "price")
but is there any way to make it dynamic? something like:
=GOOGLEFINANCE(A(Row(ref)), "price")?
Any suggestions would be helpful. Maybe there's even an addon that makes this process simpler, but I'm not sure.
try:
=ARRAYFORMULA(IFERROR(GOOGLEFINANCE(A1:A10, "price")))
You just have to write the function for A1:
=GOOGLEFINANCE(A1, "price")
And then drag the little square on the cell down. It will automatically pick up the correspondant number of the row in the A column.
You can set-up your sheet to have like 100 rows used, and when you add the ticker it will automatically calculate it.
If you don't want th #N/A to show you can do it like:
=IFERROR(GOOGLEFINANCE(A1, "price"))

Index Match multiple criteria and multiple rows google sheets

I am trying to match date and time, and metric category with multiple rows in a data sheet. Currently, I record metrics every day in a similar function with a set of rows showing metric data based on intervals of time. These rows are broken up by date.
I would like to be able to add to a dashboard the current metrics without someone needing to dig through the tables I am recording in. This would require the metric to stay up there until the next interval changed.
I will use =SPLIT(NOW) for the date and time but for now I would like to at least get this to work with static interval and date. I tried using Index Match using AND(), & etc and I cannot get it to work. I also tried to use an array but it errors every time.
Google Sheets Index Match Multi Criteria
If the time intervals for each day will be exactly the same and the data structure will never change with 3 identical lines per day (as per your screenshot) than I think you are overcomplicating things a little:
B2:
=index($A$7:$E$15,MATCH($A$1,$A$7:$A$15,0)+1,MATCH(B$1,$A$7:$E$7,0))
B3:
=index($A$7:$E$15,MATCH($A$1,$A$7:$A$15,0)+2,MATCH(B$1,$A$7:$E$7,0))
B4:
=index($A$7:$E$15,MATCH($A$1,$A$7:$A$15,0)+2,MATCH(B$1,$A$7:$E$7,0))

Google Sheets Array/Filter for Newest Date/Unique ID

I have a sheet "RawCount" with Google Form results that will accumulate over time (people will make entries each week or as their raw number changes).
I need a way to compile the data to obtain the most recent entry for each individual who has entered data via the form:
This data will accumulate with new entries over the period of eight months from up to 100 or more different people.
I would like to sum the most recent entries for each individual onto another tab in the same Google Sheet that contains a scorecard.
Thanks for any help you can offer. I think I've sprained my brain on this.

Creating custom rollups with SSAS

I am currently working on a requirement as follows and would appreciate some help in figuring out a way to configure the aggregation of my measure:
I have a fact table that contains the following Item ID, DateID,StoreID, ReceivedComments. The way received comments work is that on a daily basis a new record is created that adds to the value of received comments (for example if Item 5 in Store 5 on 1 Jan had 23 Received Comments and it received 5 comments the following day, the row for Jan 2 would be Item 5, Store 5, Jan 2, 28)
We created a measure using MAX and it works fine whenever Item ID is used in the query. When we start moving to a higher level the max produces wrong results. Our requirement is to setup the measure to be as follows:
If the member selected is on the Item Level then MAX, if it's on any other level (Date or Store) then the measure should aggregate the Max of all Items under this date or store.
Due to the business rules and structure of the database Store and Item are different dimensions so I can not include them in 1 Hierarchy.
We have been playing around with Custom RollUps but so far haven't been able to get it to work.
Thanks
I would solve this by using a more traditional approach to your fact table. Instead of keeping a cumulative count in the ReceivedComments column, I would keep only the number of comments received THAT DAY.
That way, instead of using MAX, you can create your measure using SUM, and it will automatically rollup when you go to higher levels.
The only disadvantage I can see to this approach is that you will need to use a range of dates, instead of only the most recent date, to get a full total of all the comments for a given item/store/date. But that's a very small change to your MDX.
Someone suggested using ISLEAF to determine the level, Instead of using ISLeaf i went with AS CASE WHEN [Item].[ItemID].CURRENTMEMBER.LEVEL IS [Item].[ItemID].[(All)] so I don't have to account for other dimensions such as Date, Store, etc as I have several other dimensions that all behave the same way.
And then I went with this formula to determine the Sum of the Max of the items in a particular store like this:
SUM({[Item].[Item ID].children},[Measures].[ReceivedComments]), Now I expect some performance issues with this measure but we are currently running some tests to see if it's gonna be reliable to work with it on actual data.

Resources