Piwik API: sorting results by "nb_visits" is wrong - matomo

I configured 2 custom variables in Piwik. I'm using the API to obtain values ordered by "nb_visists".
The request that I used is this:
http://localhost/piwik/?module=API&method=CustomVariables.getCustomVariables&idSite=2&period=range&date=2015-01-19,2015-01-20&format=JSON&filter_sort_column=nb_visits&filter_sort_order=asc&expanded=1&token_auth=......&segment=customVariablePageName2==category;customVariablePageValue2=#/maincategory/
The problem is that the results are not sorted according to the value of "nb_visits" column.
When I use the parameter "filter_sort_column" the results are sorted in a different way, but the order is still wrong.

The sorting should work, however in your example you requested 2 days. So you will get 2 results, each having many rows.
Rows will be sorted in each result, but the 2 results will not be sorted.
It can be confusing if you have 1 row per day: in that case, it will seem like the sorting doesn't work, but remember the sorting is done per day.

Related

Dynamic Array with multiple CountIfs

Is there a way how to get multiple results out of COUNTIF(S)?
I have a "compliance checklist" table of resources, where each row represents one resource. Based on the periods in columns H-J I get ✕ if person is non-compliant and ✓ if everything is OK.
Current formula for compliance calculation:
=COUNTIFS(INDEX($H$8#,(ROW(H8)-ROW($H$7)),,1),"✕")
This current formula needs to be in each line separately and I would like to change it to dynamic array formula to have only 1 formula in first row. However I have tried, it seemed to me that it is not possible, I always get !SPILL or another type of error.
I don't think what you are trying is possible in a row-wise fashion through COUNTIFS(). Btw, "SPILL" error is because a formula wants to spill data but is not able to do so since those cells are allready filled with data.
Either way, you could try MMULT() instead:
Formula in G8:
=MMULT(--(H8#="✕"),{1;1;1})
If you want to, you can make the 2nd parameter dynamic too:
=MMULT(--(H8#="✕"),SEQUENCE(COLUMNS(H8#),,1,0))

How do I reverse an array in Google Sheets?

Suppose I have a long, unordered, and gradually growing column that I search the even numbers from.
=filter(A1:A,ISEVEN(A1:A)=TRUE)
Now I would like to reverse this result, so that the last even number in column A is listed first in the result. Many examples use helper columns or the row function, but that doesn't seem to be an option because you don't know how many even elements there are in this array before you begin. And even if I separately calculate that using rows I can't seem to figure it out. It seems like there should be a rather simple way to just "reverse" an array right?
use:
=INDEX(SORT(FILTER({A1:A, ROW(A1:A)}, ISEVEN(A1:A), A1:A<>""), 2, 0),, 1)
Try this:
=QUERY(FILTER({A:A,ROW(A:A)},ISNUMBER(A:A),ISEVEN(A:A)),"Select Col1 Order By Col2 Desc")

Tallying Unique Names per month using in cell formulas

I have a list of people and dates that they were contacted. From that list, I need to pull the number of contacts per month for unique individuals. Here's an example list:
I need a formula in D:D that returns a 1 for the first instance of a date for each unique individual. I really don't want to manually type all those 1's.
I'll update this with what I come up with - I usually like to show that I've made an attempt, but I'm really not familiar with arrays at all, and I'm sure I'm going to need one here.
I appreciate the assistance, thanks.
Using your provided sample data, in cell C2 and copy down, no array needed:
=IF(COUNTIFS(A$2:A2,A2,B$2:B2,">="&DATE(YEAR(B2),MONTH(B2),1),B$2:B2,"<"&EOMONTH(B2,0)+1)=1,1,"")
Alternate:
=IF(COUNTIFS(A$2:A2,A2,B$2:B2,">="&EOMONTH(B2,-1)+1,B$2:B2,"<"&EOMONTH(B2,0)+1)=1,1,"")

(Nested) IF statement to calculate MEAN in Excel

I have collected values for several test persons and for different tasks, and I want to calculate the AVERAGE and STDEV for each of the test persons for each task. This is what my table looks like:
I want to calculate the AVERAGE and STDEV for each person and each task, and I want to do this with one formula and (as it is possible) no "help columns" or by filtering manually. On a different sheet (called "analysis") I have another table to show me the summarized data. It looks like this:
In the highlighted cell, I want to add the summarized AVERAGE (and there's a similar table for STDEV). So far, I tried:
=AVERAGE(IF(analysis!B1=values!$A$2:$A$13,IF(analysis!A2=values!$B$2:$B$13,values!$C$2:$C$13)))
... and many other variants of this, like switching the positions and so on. I also tried COUNTIF in the IF loop (that's a solution I found for somehow similar problems, but then I didn't find a way to tell Excel to just calculate the values where the test person and task was actually correct.
I guess it's because the IF statement doesn't work with an array, but this is just a guess. I searched for similar questions in different portals, but the main problem was that I really need Excel to return the correct values in order to calculate the mean - just returning TRUE or FALSE won't work (or at least I don't know how). I would appreciate every advice or solution you have!
Excel does not have a function called "mean". It uses the "Average" function.
Also, your formulas are array formulas and need to be confirmed with Ctrl-Shift-Enter (see screenshot for result).
=AVERAGE(IF(Analysis!B$1=Values!$A$2:$A$13,IF(Analysis!$A2=Values!$B$2:$B$13,Values!$C$2:$C$13)))
The same approach will apply to a StDev function.
Your formula is fine except that you need to change MEAN to AVERAGE. Also if you want to be able to pull the formula down and across to select the four combinations of Task and Test Person, you need to fix the row and column with $ signs
=AVERAGE(IF(analysis!B$1=values!$A$2:$A$13,IF(analysis!$A2=values!$B$2:$B$13,values!$C$2:$C$13)))
Make sure that you enter it as an array formula using CtrlShiftEnter
You can then get the standard deviation in exactly the same way replacing AVERAGE by STDEV or STDEV.S (for sample SD, the usual one) or STDEV.P (for population SD).

speed up array formula

I have the following formula which I will explain below:
{=SUM(IF(($G$1:$L$1=$O$1)*($G$2:$L$2=$O$2)*($G$3:$L$3=$O$3)*($G$4:$L$4=$O$4)*($G$5:$L$5=$O$5)*($G$6:$L$6=$O$6)*($G$7:$L$7=$O$7);G21:L21))}
Here is what the worksheet looks like:
Under columns G - L we have a 'database' of all data. These columns will be added cumulatively each quarter (approx 30 columns a quarter). So after a few years we have ended up with a bunch of database columns (1000 + columns of raw data). For the sake of this demo, I have only included those 6 columns.
As you can see, each column contains specific parameters, between rows 1 - 7, which allows to identify specific CountryCode + Project Code + Category + Fiscal Year, + ... (etc.). This allows us to track down a unique specific project and retrieve its data.
What we have afterwards on the column O is a specific project we are trying to retrieve values for (you can see that the rows 1 - 7 are the same as under column G (we are trying to retrieve values for this particular project).
Here comes our formula. I have attached above. Here is what it looks like when I press F2. As you can see the IF statement is first simply checking whether the particular columns match the pre-defined criteria under column O and it sums all the columns that match all the criteria between rows 1-7.
Now here is the problem. We have a worksheet, which contains 20 projects (such as column O) and we are using this array formula there to retrieve values. The problem is that retrieving data using this way takes A LOT OF TIME. We have also adopted a principle via VBA that we iterate through all the cells, then we insert a formula, calculate array cell, and then we copy & Paste resulting value inside (so that we won't end up with full sheet of array formulas). However it still takes LONG to calculate (1 minute or so).
I was wondering, if there is a better solution how to retrieve the data in the already mentioned format (that means we have a specific criteria we are trying to find)? Maybe SUMIFS could be better? Or sumproduct? Or even compeltely different solution?
I am open to any proposal which would fasten the process.
i met similar problem about 2 weeks ago. At first i use a helper column/row. The helper column is to concatenate the 7 string in each column. then only use the IF function to check if the joined text match. Such as, assuming the helper row is row 8 per your sample, cell G8 formula would be
=CONCATENATE(G1,"|",G2,"|",G3,"|",G4,"|",G5,"|",G6,"|",G7)
and do the same for the rest including column O
=CONCATENATE(O1,"|",O2,"|",O3,"|",O4,"|",O5,"|",O6,"|",O7)
Then do a HLOOKUP
=HLOOKUP(O8,G8:L21,14,0)
In my case, the calculation time reduce from 10 min to a few seconds!
Alternatively I also found a way to do without helper column, using array again, but the idea is pretty much the same,
the formula in O21 as per your sample would be
=SUM(IF(CONCATENATE(G1:L1,G2:L2,G3:L3,G4:L4,G5:L5,G6:L6,G7:L7)=CONCATENATE(O1,O2,O3,O4,O5,O6,O7),G21:L21))
(i didn't add in the "|" delimiter for this formula, but it is better to do so)
But in the end I prefer the helper column method.
For your reference
HTH
To improve performance avoid reapeating same calculations multiple times.
This allows us to track down a unique specific project and retrieve its data.
If a combination of 7 values is unique, calculate the position of chosen project only once in helper cell (for example O15) with array formula (confirmed with Ctrl+Shift+Enter:
=MATCH(1;(G1:L1=O1)*(G2:L2=O2)*(G3:L3=O3)*(G4:L4=O4)*(G5:L5=O5)*(G6:L6=O6)*(G7:L7=O7);0)
Use the following formula in O21 and drag down:
=INDEX(G21:L21;1;$O$15)

Resources