Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
pbrenneise
Contributor II
Contributor II

Function for Counting Number of Fields Per Row That Have String

Is there a way in Qlik to count the number of fields per row, which contain string? I have a large data set with a total of 9 columns that looks like this:

Col ACol BCol CCol DCol ECol FCol GCol HCol I
Entry 1YN YNMaineX12/21/2015
Entry 2 NYNYGeorgiaY 
Entry 3YYNNYAlabamaY12/22/2018
Entry 4     Vermont 12/25/2017

...

The data were receiving is only partially complete and we'd like to calculate how many rows are missing data. Specifically, I need to add a new column in the Load Script, which contains a total based on how many fields from Col B Through Col I are LEN() > 1 for that particular row. Is there an efficient way to do this? Thanks!

Labels (1)
  • LEN

1 Solution

Accepted Solutions
y_grynechko
Creator III
Creator III

Temp:
LOAD
"Col A",
if(isnull([Col A]), 1,0) as [Col A Nulls],
"Col B",
if(isnull([Col B]), 1,0) as [Col B Nulls],
"Col C",
if(isnull([Col C]), 1,0) as [Col C Nulls],
"Col D",
if(isnull([Col D]), 1,0) as [Col D Nulls],
"Col E",
if(isnull([Col E]), 1,0) as [Col E Nulls],
"Col F",
if(isnull([Col F]), 1,0) as [Col F Nulls],
"Col G",
if(isnull([Col G]), 1,0) as [Col G Nulls],
"Col H",
if(isnull([Col H]), 1,0) as [Col H Nulls],
"Col I",
if(isnull([Col I]), 1,0) as [Col I Nulls]
FROM [lib://Desktop/Book1.xlsx]
(ooxml, embedded labels, table is Sheet1);

Table:
LOAD
"Col A",
"Col B",
"Col C",
"Col D",
"Col E",
"Col F",
"Col G",
"Col H",
"Col I",
[Col A Nulls]+ [Col B Nulls] + [Col C Nulls] + [Col D Nulls] + [Col E Nulls] + [Col F Nulls] + [Col G Nulls] + [Col H Nulls] + [Col I Nulls] as [Count of Nulls]
Resident Temp;
Drop Table Temp;

View solution in original post

4 Replies
y_grynechko
Creator III
Creator III

Temp:
LOAD
"Col A",
if(isnull([Col A]), 1,0) as [Col A Nulls],
"Col B",
if(isnull([Col B]), 1,0) as [Col B Nulls],
"Col C",
if(isnull([Col C]), 1,0) as [Col C Nulls],
"Col D",
if(isnull([Col D]), 1,0) as [Col D Nulls],
"Col E",
if(isnull([Col E]), 1,0) as [Col E Nulls],
"Col F",
if(isnull([Col F]), 1,0) as [Col F Nulls],
"Col G",
if(isnull([Col G]), 1,0) as [Col G Nulls],
"Col H",
if(isnull([Col H]), 1,0) as [Col H Nulls],
"Col I",
if(isnull([Col I]), 1,0) as [Col I Nulls]
FROM [lib://Desktop/Book1.xlsx]
(ooxml, embedded labels, table is Sheet1);

Table:
LOAD
"Col A",
"Col B",
"Col C",
"Col D",
"Col E",
"Col F",
"Col G",
"Col H",
"Col I",
[Col A Nulls]+ [Col B Nulls] + [Col C Nulls] + [Col D Nulls] + [Col E Nulls] + [Col F Nulls] + [Col G Nulls] + [Col H Nulls] + [Col I Nulls] as [Count of Nulls]
Resident Temp;
Drop Table Temp;

pbrenneise
Contributor II
Contributor II
Author

Thanks for the quick reply! I built off of your example using LEN() vs isnull() and got the results I needed. Cheers!

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You could generalize the solution a bit like this:

Data:
LOAD
RecNo() as RecId,
"Col A",
"Col B",
"Col C",
"Col D",
"Col E",
"Col F",
"Col G",
"Col H",
"Col I"
FROM [lib://Data]
(html, utf8, embedded labels, table is @1);

ByCol:
CrossTable (ColName, ColValue, 1)
LOAD *
Resident Data
;
Join (Data)
LOAD
RecId,
-sum(len(ColValue)>0) as DataCount
Resident ByCol
Group By RecId
;

Drop Table ByCol;

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

y_grynechko
Creator III
Creator III

this is much more elegant than what I did:)