I am trying to create a custom column in power query that counts null values from column 7 - column 41. The function I have used is List.NonNullCount(List.Range(Record.FieldValues(),7,41))). There are many many rows of data so I would like it to calculate each row within the custom column.
For some reason even though each column between 7-41 has null values across the row the output is 2. I would expect the output to be 0. Futhermore I am getting an output of 35 when all columns from 7-41 have a value not equal to null across the row. I would expect 34 in this case. I did replace all blank values with null using the transform function in power query.
I'm not sure if my function List.NonNullCount(List.Range(Record.FieldValues(),7,41))) is correct or if there is a better way to do it. any help appreciated!!!!
In my version, you need to have an argument for Record.FieldValues. What you write: Record.FieldValues() would produce an error.
Also, the third argument of List.Range is the number of columns to return; it is not the number of the last column.
And the first column is column 0, not column 1
So something like:
List.NonNullCount(List.Range(Record.FieldValues(_),6,35))
should return the nonNull count for columns 7-41
Using PowerPivot functionality to create measures.
There are two types of values in a column: integers and NULL (string).
Trying to figure out how to create a DAX formula to calculate an average for the column that would take only cells that contain integers.
It feels that the next basic formula would work:
=CALCULATE (
AVERAGE ( tData[columnA]),
FILTER ( tData, [columnA] <> "NULL" )
)
but it throws an error: The function AVERAGE takes an argument that evaluates to numbers or dates and cannot work with values of type String.
I'm wondering if there is a way to avoid this error without removing/cleaning NULLs values beforehand?
Power BI tables cannot contain mixed types of values in a single column. If there is numbers and texts in a column, the column type is text. Numeric values included in the column is not actually numbers, they are just texts composed of numeric characters.
So, in order to make it work, you need to explicitly convert numeric strings to real numbers.
= CALCULATE(
AVERAGEX( tData[columnA], VALUE(tData[columnA]) ),
tData[columnA] <> "NULL"
)
However, I suggest not to have text and numeric values in one column. Use Power Query to either remove rows with "NULL", or convert them to BLANK.
Best way here would if you replace your NULL (string) values with the database null (nothing) value. This way your rows stay null but your calculation still works.
Go to Edit Queries > Transform > Repalce Values and replace your string NULL to a database null. Your table will look like this then:
Now the avarage calcualtion is simple:
Database null values get ignored from every calculations. This is way it works.
I'm trying to create an excel register that counts the number of times someone has registered, and returns the date of the last time they turned up but am having trouble with this last step:
See this simplified setup:
To do this, I assume I need to find the index value of the column in which the name last appears, and the use it to return the date in the first row, the tricky part trying to get that index value.
I've tried to use lookup formulas and am pretty sure that an array formula is how this can be accomplished but am unsure how I can use them in this specific case.
Assuming you have Excel 2010 or later:
=INDEX($1:$1,AGGREGATE(14,6,COLUMN(A$2:D$8)/(A$2:D$8=O2),1))
Copy down as required.
The explanation is as follows:
The portion:
(A$2:D$8=O2)
simply returns an array of Boolean TRUE/FALSE values as to whether each of the cells within that range is equal to the entry in O2 or not, i.e. using your example:
{TRUE,FALSE,TRUE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,TRUE,FALSE,FALSE;FALSE,FALSE,FALSE,TRUE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE}
The part:
COLUMN(A$2:D$8)
returns the column number for each column within the specified range, i.e.:
{1,2,3,4}
By reciprocating this array with that containing our conditional Boolean TRUE/FALSE returns, we produce an array whose only numerical entries correspond to columns in which our search string (i.e. "James") is located, since:
COLUMN(A$2:D$8)/(A$2:D$8=O2)
which is:
{1,2,3,4}/{TRUE,FALSE,TRUE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,TRUE,FALSE,FALSE;FALSE,FALSE,FALSE,TRUE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE}
becomes:
{1,#DIV/0!,3,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,2,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,4;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!}
by virtue of the fact that, when subjected to a suitable mathematical operation (of which division is one), Boolean TRUE/FALSE values are coerced into their numerical equivalents (TRUE=1, FALSE=0), meaning that, effectively, for any numerical value x:
x/TRUE ⇒ x/1 = x
and:
x/FALSE ⇒ x/0 = #DIV/0!
By setting AGGREGATE's first parameter to 14 (equivalent to the function LARGE) and its second to 6 (instructing it to ignore any errors in the array passed), we can extract the largest column index which meets our criterion, such that:
AGGREGATE(14,6,COLUMN(A$2:D$8)/(A$2:D$8=O2),1)
which is here:
AGGREGATE(14,6,{1,#DIV/0!,3,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,2,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,4;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!},1)
returns 4.
All that is left is to pass this value to INDEX, such that:
INDEX($1:$1,AGGREGATE(14,6,COLUMN(A$2:D$8)/(A$2:D$8=O2),1))
which is:
INDEX($1:$1,4)
returns:
13/11/2015
as required.
Regards
I want to use IF, INDEX and MATCH function together to get the output from the another sheet that has two columns (one of them in always blank and so need value from a column which in not blank).
The formula I'm using looks like :
=IF(ISBLANK('DATA 1'!B:B);
INDEX('DATA 1'!B:B;MATCH(OUTPUT!B14;'DATA 1'!A:A;0));
INDEX('DATA 1'!C:C;MATCH(OUTPUT!B14;'DATA 1'!A:A;0)) )
This formula is returning values from one column only and when the corresponding column is blank it shows #N/A .
I want it to show the value from whichever column (out of the two on another sheet) that is not blank.
You should be using:
=IF(ISBLANK(INDEX('DATA 1'!C:C,MATCH(OUTPUT!B27,'DATA 1'!A:A,0))),INDEX('DATA 1'!B:B,MATCH(OUTPUT!B27,'DATA 1'!A:A,0)),INDEX('DATA 1'!C:C,MATCH(OUTPUT!B27,'DATA 1'!A:A,0)))
though you need to be aware that ISBLANK will return FALSE when passed a null string (""), so if any of your entries in 'DATA 1'!B:B or 'DATA 1'!C:C contain such an entry (perhaps as a result of formulas in those cells), then the above will not give correct results.
As such, more rigorous is:
=IF(INDEX('DATA 1'!C:C,MATCH(OUTPUT!B27,'DATA 1'!A:A,0))="",INDEX('DATA 1'!B:B,MATCH(OUTPUT!B27,'DATA 1'!A:A,0)),INDEX('DATA 1'!C:C,MATCH(OUTPUT!B27,'DATA 1'!A:A,0)))
Assuming the returns are text, not numeric, you could also use the shorter:
=LOOKUP(REPT("z",255),INDEX('DATA 1'!B:C,MATCH(OUTPUT!B27,'DATA 1'!A:A,0),N(IF(1,{1,2}))))
though its brevity is arguably offset by its complexity and, again, this will fail if null strings are present in those ranges.
For some time I've been aware that excel make a last minute decision to return 0 in lookup functions when the actual target value is "empty". I know that the actual function returns the correct value because I got into the habit of using If(lookupfunction="","",lookupfunction), which is a pain but works.
I have a table with a vlookup in a calculated column which looks up another table based on a third table with a parallel structure (using tablename[#[name]] style referencing). Some of the entries in the source table are blank and the lookup was returning blank (to my surprise and delight). I then deleted one of the non-blank entries in the source table and the vlookup returned 0 instead of "", just for the one I deleted. If I delete another entry, it also reverts to zero instead of "". I checked all of the formatting and it is all set to general so the zeros are not being hidden.
I guess that is by way of a bug report, but my question is: is there a neat way to pass "" through worksheet functions without them being converted to 0 all the time
Unfortunately Excel formulas cannot return an Empty cell - empty gets coerced to zero. A cell containing ' or "" or space is not an empty cell but contains a zero-length string: functions like Lookups will happily return a zero-length string - it looks like an empty cell but is not.