Discussion Board for collaboration on QlikView Scripting.
I have a requirement explained as below,
In my table I have columns like ID and Code and using this code I have created two calculated dimensions as below,
If(Match(Code,'A','B'),Code) as 'AB',
If(Code='C',Code) as 'C'
Now I am getting result as
ID AB C
123456 Code1 -
123456 - Code2
123456 - -
Multiple rows for a single ID. But I would like to get a single row for a ID as below,
ID AB C
123456 Code1 Code2
Can anyone help me to implement the same?
Thanks in advance.
Go to Solution.
I have attached a solution from my side.
Can you share raw data of how it looks? I want to see how Code field look like?
Hi Leni, from that simple table you can create the expected result using a group by:
MinString(AB) as AB,
MinString(C) as C
Resident YourPreviousTable Group By ID;
This will keep only one [AB] and value for each ID (the first one alphabetically sorted). If Codes are numbers you can use Min() instead of MinString()
Thanks for your reply.
Please find the attached sample data and sample qvw file.
In the qvw file I have showed how I m getting the data currently. But I want the result to be shown in a single row.
Please let me know if you need further more details.
Thanks for your reply Ruben.
I just tried your solution with my dummy data and it is giving as I expected but I found data missing when I used the same.
For the same ID if I have Codes as MBNR,NAWD,FOOC,ABUA
for the calculation If(Match(Code,'NAWD','MBNR'),Code) as [NAWD/MBNR Codes] it should return value for both MBNR & NAWD
but once I used your solution it is showing data only for the first occurrence and not for the second.
Attached screenshot for your reference.
Please help me to resolve the issue.
Thank you for your solution.
I try to implement the same in my actual code. If any doubts will get back to you
I will mark your answer as Correct once it worked out in my actual code
Hi Leni, yes, it was intented as i advised: "This will keep only one [AB] and value for each ID (the first one alphabetically sorted)."
If you want all values concatenated use Tamil's solution, If you want NBNR and NAWD in different rows you can use something like:
LOAD ID, Subfield([NAWD/MBNR], ',') as [NAWD/MBNR], [FOOC Code]; //This LOAD reads from below LOAD
LOAD ID, Concat([NAWD/MBNR], ',') as [NAWD/MBNR], Minstring([FOOC Code]) as [FOOC Code]
FROM... Group by ID;
Thank you so much Tamil, It worked as expected in my code
I used Tamil's solution itself as I want it a single row.
Thank you for your help