Combine to Fields in one Qlik Sense Filter - qlikview

I have 2 Fields and I need to combine them in one field. Is it possible to get this result in Qlik Sense?
I do not want concatenate but get the result in table

It's not particularly clear what the source is and how the data is structured, but you can JOIN without a key to flatten. Example:
[t1]:
LOAD * INLINE [
Activity
A
B];
[t2]:
LOAD * INLINE [
"Activity Code"
A01
B02];
[final]:
LOAD
[Activity] AS [value]
RESIDENT [t1];
JOIN([final])
LOAD
[Activity Code] AS [value]
RESIDENT [t2];
DROP TABLES [t1],[t2];
This will result in a table with the structure of:
value
A
B
A01
B02

Levi's should be accepted as the answer but I just wanted to point out another option, which is to use the CrossTable() prefix, which can be used to "pivot" the values of 2 or more columns into a single column. This method can be useful if the columns you need to combine are already in a single table.
The script you can use in the Data Load Editor may look like this:
[Table 1]:
Load * Inline [
Activity , Activity Code
A , A01
B , A03
C , A05
D , B02
E , B06
, B03
, C01
, C03
, C08
, D24
, D21
, D30
, E11
, E15
, E22
];
[Pivoted table]:
CrossTable ([throwaway 1], [Combined], 1)
Load
1 as [throwaway 2]
, [Activity]
, [Activity Code]
Resident [Table 1];
Drop Fields [throwaway 1], [throwaway 2];
[Table 1] is just the data as it appears in your screenshot. Below that, the [Pivoted table] is a table that loads three fields:
1 as [throwaway 2] - this is so that we have at least one qualifier field, or unchanged dimension, to group the combined columns on (see the Qlik Help page on the CrossTable prefix to read more about why this is needed). I named it [throwaway 2] because we won't need it after this.
[Activity] - One of the columns we want to combine.
[Activity Code] - The other column we want to combine.
The CrossTable() is going to result in an attribute field called [throwaway 1] (so named because we won't need it after this) and a data field called [Combined], which will be our new combined field!
After we load this, our results are just what we'd expect:

Related

How to do subtract column if lot no and item name and percent is same in SQL

I have two View one for issue and other for Receive.
issue View Output
Lot No Operation Item Wt % Fine Wt
2112001 Lot Addition Create 2 Sadak 180.00 91.94 165.49
2112001 Lot Addition Issue 2 Sadak 30.00 91.94 27.58
2112001 Lot Addition Issue 2 Sadak 300.00 99.50 298.50
2201002 Lot Addition Create 3 Hiway 100.00 91.80 91.80
2201002 Lot Addition Issue 3 Hiway 2.00 91.94 1.84
2201003 Lot Addition Create 4 Saran 19.00 91.40 17.37
2201003 Lot Addition Issue 4 Saran 15.00 91.94 13.79
Receive View Output
Lot No Operation Item Wt % Fine Wt
2112001 Lot Addition Receive 2 Sadak 52.00 91.94 47.81
Output View
Lot No Operation Item Wt % Fine Wt
2112001 Lot Addition Create 2 Sadak 158 91.94 145.27
2112001 Lot Addition Issue 2 Sadak 300 99.50 298.50
2201002 Lot Addition Create 3 Hiway 100 91.80 91.80
2201002 Lot Addition Issue 3 Hiway 2 91.94 1.84
2201003 Lot Addition Create 4 Sarangi 19 91.40 17.37
2201003 Lot Addition Issue 4 Sarangi 15 91.94 13.79
if Lot no, Item Name and percent is same from 2 view than issuewt. and receivewt. should be minus for that lot no. Kindly i suggest me select query what I have done is union and subtract. Suggest front end approach will be better or front end vb.net will be better. copy in two different data table and output will be to third data table.
If the columns and data types are the same, then you can use UNION ALL to combine the data from the 2 views.
Then aggregate the combined results.
Query for MS Sql Server :
SELECT
[Lot No]
, MIN([Operation]) AS [Operation]
, [Item]
, SUM([Wt]) AS [Wt]
, [%]
, SUM([Fine Wt]) AS [Fine Wt]
FROM
(
SELECT [Lot No], [Operation], [Item], [Wt], [%], [Fine Wt]
FROM [Issue View Output]
UNION ALL
SELECT [Lot No], [Operation], [Item], -[Wt], [%], -[Fine Wt]
FROM [Receive View Output]
) q
GROUP BY [Lot No], [Item], [%]
ORDER BY [Lot No], [Item], [%];

Auto Generate two new ID column based on other column Values in PostGreSQL database

In my database table i have a table name Household member where the column are
Upzila, union , ward, village , para family_head_name , member_name ,
relation_with_family_head, age , maritial_status.
I want to generate a new table with same structure but with new auto-generate column the column name will be HH_ID , Member_id .Below i will provide simple dataset with the new example column of hh_id and hh_membe_id.
For example the Upazila is Cox Bazar Sadar so i will assume the code is 1 and the union is jhiwanja so jhionja code is 03 then if ward is number 1 and village is Boro chara so code is 01 and the para name is asroyon prokolo that code is 02 so the hh_id will be and the member id will be incremental for example if the house hold contain 3 people so for the first member id (hh_member_id) will be then second member id will be .
I have tried so many approch but i faild to generate that id . last time i have tried to generate the id using excel manually but i faild . so would be the best solution to do that in postgreSQL database .
Simple dataset link : https://docs.google.com/spreadsheets/d/1X33Zh2Yq_9Hz64VbW_u3lRi61-pKfQ5HozkylUsRVMU/edit?usp=sharing

SQL Join correct? Pulling more than I want

I have a system that is storing people applying for jobs. They are in the warehouse. When they apply for a job I create a record for them in the jobTracking table. That is simple. The issue is when someone applies for more then one position they get more then one record clearly in jobTracking. My issue is the ability to make a query to add people to a job internally based on a where clause. Let's say I want to add people to jobID=56 where their degree = "MD" and they haven't already applied. The list of people that appear post query will contain MDs who have already applied for 56 IF they have another record for another job. Who can I tell the query to ignore that applicantID in all records if one is a match? Tables are below. Query is also below that gives incorrect records. applicantID=10 will appear in my query below because he also has a record for job 46.
SELECT applicantWarehouse.first
, applicantWarehouse.last
, applicantWarehouse.title
, applicantWarehouse.ID
, jobTracking.applicantID
, jobTracking.jobID
FROM jobTracking INNER JOIN applicantWarehouse ON jobTracking.applicantID = applicantWarehouse.ID
WHERE Degree="MD"
AND jobTracking.jobID !=56
applicantWarehouse table
ID | First | Last | Degree
job table
jobID | jobTitle
jobTracking table
ID | applicantID | jobID
1 10 56
2 10 46
In your example you want to pull all people who have a degree md AND have not yet applied to jobID of 56. If that is what you need you can do this using not exists.
SELECT applicantWarehouse.first
, applicantWarehouse.last
, applicantWarehouse.title
, applicantWarehouse.ID
, jobTracking.applicantID
, jobTracking.jobID
FROM jobTracking INNER JOIN applicantWarehouse ON jobTracking.applicantID = applicantWarehouse.ID
WHERE Degree="MD"
AND NOT EXISTS (
SELECT 1
FROM jobTracking j
WHERE j.jobID = 56
AND j.applicantID = applicantWarehouse.ID )

How to select columns of different lengths

I have a table of part numbers along with many of their properties like such:
[Part Number] [Type] [Manager] [Cat. Code] [etc...]
AAA-001 A Dave 123
DDD-008 D Chris 153
BBB-003 B Dave 254
CCC-008 C Dave 153
...
I'm trying to make a list of all the unique values of each property so it looks more like this:
[Type] [Manager] [Cat. Code] [etc...]
A Dave 123
B Chris 153
C 254
D
However whenever I try to do this using SELECT DISTINCT * or the like, it fills up all the columns so that they're the same length as the longest one, filled horizontally according to the original table:
[Type] [Manager] [Cat. Code] [etc...]
A Dave 123
B Dave 254
C Dave 153
D Chris 153
How do I stop this from happening, and just keep unique values of each column, even if they might be different lengths?
I think you've misunderstood what DISTINCT does. It will filter your results so that all rows returned are unique, not each column. Depending which columns are named in your SELECT, you'll get different results. For an example, see http://www.techonthenet.com/sql_server/distinct.php and the section "Example - With Multiple Expressions"
For your case, if you want lists of the unique values in each column, then you'll have to do a separate query on each column, e.g.:
SELECT DISTINCT [Type] FROM [Parts]
SELECT DISTINCT [Manager] FROM [Parts]
...etc
If you then want them side-by-side (as per your sample desired output), you'll just have to copy and paste them into a spreadsheet or something.

How to specify row names in MS Access 2007

I have a cross tab query and it pulls only the row name if there is data associated with it in the database. For example, if I have three types of musical instruments:
Guitar
Piano
Drums
Other
My results will show up as:
Guitar 1
Drums 2
It doesn't list Piano because there is no ID associated with Piano in the DB. I know I can specify columns in the properties menu, i.e. "1, 2, 3, 4, 5" will put columns in the DB for each, regardless of whether or not there is data to populate them.
I am looking for a similar solution for rows. Any ideas?
Also, I need NULL values to show up as 0.
Here's the actual SQL (forget the instrument example above)
TRANSFORM Count(Research.Patient_ID) AS CountOfPatient_ID
SELECT
Switch(
[Age]<22,"21 and under",
[Age]>=22 And [AGE]<=24,"Between 22 And 24",
[Age]>=25 And [AGE]<=29,"Between 25 And 29",
[Age]>=30 And [AGE]<=34,"30-34",
[Age]>=35 And [AGE]<=39,"35-39",
[Age]>=40 And [AGE]<=44,"40-44",
[Age]>44,"Over 44"
) AS Age_Range
FROM (Research
INNER JOIN (
SELECT ID, DateDiff("yyyy",DOB,Date()) AS AGE FROM Demographics
) AS Demographics ON Research.Patient_ID=Demographics.ID)
INNER JOIN [Letter Status] ON Research.Patient_ID=[Letter Status].Patient_ID
WHERE ((([Letter Status].Letter_Count)=1))
GROUP BY Demographics.AGE, [Letter Status].Letter_Count
PIVOT Research.Site In (1,2,3,4,5,6,7,8,9,10);
In short, I need all of the rows to show up regardless of whether or not there is a value (for some reason the LEFT JOIN isn't working, so if you can, please use my code to form your answer), and I also need to replace NULL values with 0.
Thanks
I believe this has to do with the way you are joining the instruments table to the IDs table. If you use a left outer join from instruments to IDs, Piano should be included. It would be helpful to see your actual tables and queries though, as your question is kind of vague.
What if you union the select with a hard coded select with one value for each age group.
select 1 as Guitar, 1 as Piano, 1 as Drums, 1 as Other
When you do the transform, each row will have a result that is +1 of the result you want.
foo barTmpCount
-------- ------------
Guitar 2
Piano 1
Drums 3
Other 1
You can then do a
select foo, barTmpCount - 1 as barCount from <query>
and get something like this
foo barCount
-------- ---------
Guitar 1
Piano 0
Drums 2
Other 0