Excel PowerQuery: null values in a number column - excel

I am using a PowerQuery query to import data from CSV files. Some cells in the CSV files are empty. When imported into PowerQuery, these cells get an error "Cannot convert the value null to type Number." The field gets (correctly) identified as type=number. However, I'd really just like these error values to just be blank entries, like they were in the original file. "Replace Errors" only allows me to change these error values into numbers (it won't let assign a blank or any non-numeric value). Any ideas on how to get these values to just be blank (or Null)?

The column has been typed as a whole number Int64 in the "Changed Type" step. Change the type of the column to Decimal number. You should no longer see Errors and your blanks will appear as "null" and will function as nulls.

Related

Power Query incorporate null into equation

I have 2 columns within power query, one as a helper column that contains numbers in each cell and acts kind of as a back up hwne the next column is empty. The other column contains values and the mentioned empty cells. I wish to perform calculations using these columns and so have formatted these to be as Decimal Number. This causes the empty cells to be returned as null which is fine although I can't get power query to recognise these when creating a custom column. I wish to create an if statement that if the second column is null then the value from the helper column is returned instead.
Testing this in another column using = if [Custom.3] = "null" just returns all values as False so clearly null can't be recognised.
Similarly I am unable to replace error to "" because it has to be a numerical value.
How can I get power query to recognise when a value is not present?
= if [Custom.3] = "null" just tests for a text word of length 4 letters, null
To test for an actual null, use = if [Custom.3] = null
See sample code I provided to your other question at convert null to blanks
Note: if it is not a null (are you sure?) then try a line feed #(lf)

INDEX MATCH on structured references / #value error

The use of INDEX / MATCH on 2 defined tables and a structured reference on their columns causes a #value error, although the function has been entered as an array-function.
Given:
**Table1:**
Key1|SourceVal
1|A
2|AA
**Table2:**
Key2|ValDisp
1|_{=INDEX(Table1;MATCH(Table2[#[Key2]];Table1[Key1];0);Table1[SourceVal])}_
The formula entered in column "ValDisp" effects in a #value error.
The formula analyzer shows, that the correct value is found, but is turned into #value during the last step.
INDEX can be invoked in two ways. In the way you are using it, first parameter is a range, and second and third parameters are numbers.
You are using =INDEX(Table1;MATCH(Table2[#[Key2]];Table1[Key1];0);Table1[SourceVal])
Last parameter Table1[SourceVal] does not return a number, so try to replace it with column number:
=INDEX(Table1;MATCH(Table2[#[Key2]];Table1[Key1];0);2)
Another option would be using a second MATCH that searchs for the name of the column and returns its position inside headers area of Table1. Something like this:
I got Excel 2007 so my structured references are different. Not # like in Excel 2010 and higher
You could replace the 2 by MATCH(Table1[[#HEADERS];[Sourceval]];Table1[#HEADERS];0)

Excel - Ignore blanks in descending sort

In the attached file, when I sort on column C on descending order, it puts blanks on top. (it shouldn't happen)
Column D is just "Copy as values" of column C and sort works fine in column D
So I guess there is some issue with my formula in column C
File Link: https://drive.google.com/open?id=1TRDympt3-CFn6916aLGxd3du5SL_FaxM
Formula I am using: =IF(A3="","",IF(ISERROR(MATCH(TRIM(S!$A3),$G$4:$G$8,0)),$B3,""))
If you need to be able to sort in either ascending or descending order, then I can't think of a simple solution just through formulas.
The next simplest solution may be just applying an autofilter to exclude blanks (which actually does get rid of nullstrings).
If you're automating this through VBA, I think it would be simplest to first sort ascending, apply a filter to remove nullstrings, then sort descending.
You could also potentially incorporate the top 10 filter.
This is caused by the difference between a null-string and an empty cell.
The result of your formula is the null-string "", which is not the same as the "nothing" in an empty cell.
Truly empty cells are ignored by Excel when sorting, whereas the null-string is actually a string containing just the null-string character and is included in sorting.
I suspect the reason column D sorted correctly for you is because you only copied the cells with normal values from column C. If you copy the entire column (including what look like blank cells), then the issue persists because then you've also copied the null-string characters.
In a column of values, as in column D, you can remove null-strings using the Text-to-Columns tool with the delimiter option and deselecting all delimiters. (Same as how you can convert numbers stored as text to actual numbers.)
However with formulas, as in column C, there is no way of telling Excel to return truly "Nothing".
As a workaround, if you only ever have positive values, you can change your formula to return the value 0 instead of the null-string "". As a result, the 0 values will be put at the bottom when sorting descending.
You can then also hide the 0 values by changing the number formatting of the column:
Select the entire column in the data table
Format Cells...
On the Number tab, select "Custom" in the Category
Manually change the Type value from "0.00" to "0.00;-0.00;"
This format says to display:
Positive numbers with 2 decimal places
Negative numbers with 2 decimal places and negative sign at the front
Zeroes as blank

Using IF, INDEX and MATCH to retrive the value out of the two column that is not blank

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.

Worksheet functions returning 0 when the actual value is ""

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.

Resources