Forum Discussion
Unpivot removes rows with no/null values - how to keep them?
- 9 years ago
Select Monday to Friday in Query Editor, Go to Transform Tab, Replace Values ---> Replace "null" with "0".
You would see the expected results.
Select Monday to Friday in Query Editor, Go to Transform Tab, Replace Values ---> Replace "null" with "0".
You would see the expected results.
How can I account for new columns of data being added when using the replace “Null” with 0? I’ve found that replace values does not pick up new columns when added to the table, thus, the unpivot removes the new column's rows with null values. Is there a way to make the replace values dynamic as new columns are added or to keep nulls through the unpivot process and then replace them when the values are in a single column?
I've only been able address this issue by manually adding the column name in the advanced editor's replace values code line.
Thanks,
Dane
- AJaso9 years agoNew Member
I figured out a way to account for new columns. It's not the prettiest solution but it works.
Create a blank query
1) Create a list: ={0..9999} (The 9999 represents the max number of rows of data you think you might have)
2) Convert the list to table
3) Define the list as a parameter
In your original query that you want to unpivot
4) Add an index column (before unpivoting)
5) Duplicate the query twice
In the first duplicate query
6) Demote the headers
7) Transpose the table
8) Select the first column and delete other columns. You now have a header column.
9) Add a custom column invoking the parameter
In the second duplicate query
10) Select all of the columns that you are not going to unpivot including the index column, remove other columns
11) Merge this query with the first duplicate. Select index column from this query and number column from first duplicate and merge with a left outer join.
Back in the original query
13) Unpivot your data like you normally would
12) Merge this query with the second duplicate query. Select both the index and header columns in each query and then merge with an all outer join.
Now you should have a solution that contains null values and does not need to be modified each time you add a column. I hope someone can come up with a better method but, for now, this is all I've got.
- nickvanmaele9 years ago
Advocate II
Thank you for your time and suggestion.
- BradleyA9 years agoRegular Visitor
Nick,
You probably thought of this already:
1) replace Null with 0 or "No Value"
2) unpivot
3) replace the 0 or "No Value" with Null