Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Nolgath
Creator
Creator

If values exist in other fields

Hi, i have this issue I've been trying to solve:

Script:

sales:
LOAD
buyervat,
sellervat,
name
FROM [lib://AttachedFiles/salescustomer.xlsx]
(ooxml, embedded labels, table is Sales);

customers:
LOAD
VAT,
Id
FROM [lib://AttachedFiles/salescustomer.xlsx]
(ooxml, embedded labels, table is Customers);

I need to create a new field that will flag things for me:

if VAT exists in buyervat and sellervat then i get "Buyer/Seller".
if VAT exists only in one of them then i get "Buyer" or "Seller".
if VAT does not exist in either i get "-".

I have tried if(exists()) but not success I get wrong or missing matches..

Data used is attached, if have then the original data that i way bigger but i am trying to do with a smaller db first to understand this concept

 

Labels (2)
2 Solutions

Accepted Solutions
steeefan
Luminary
Luminary

One possible solution with the two tables already created:

LEFT JOIN (sales) LOAD
  VAT as buyervat,
  1 AS buyervatFlag
RESIDENT
  customers;

LEFT JOIN (sales) LOAD
  VAT as sellervat,
  1 AS sellervatFlag
RESIDENT
  customers;

sales2:
LOAD
  buyervat,
  sellervat,
  name,
  If(buyervatFlag and sellervatFlag, "Buyer/Seller",
    If(buyervatFlag and Not(sellerVatFlag), "Buyer",
      If(sellerVatFlag and Not(buyervatFlag), "Seller",
        Null()
      )
    )
  ) AS BuyerSeller
RESIDENT
  sales;

DROP TABLE sales;

View solution in original post

Ahidhar
Creator III
Creator III

try this

sales:
LOAD
buyervat,
sellervat,
name
FROM [lib://DataFiles/salescustomer.xlsx]
(ooxml, embedded labels, table is Sales);

map1:
mapping Load Distinct
buyervat as VAT,
1 as Flag
resident sales;

map2:
mapping load Distinct
sellervat as VAT,
1 as Flag1
resident sales;
customers:
LOAD
VAT,
Id,
if(Applymap('map1',VAT)=1 and Applymap('map2',VAT)=1,'Buyer/Seller',
if(Applymap('map1',VAT)=1,'Buyer',
if(Applymap('map2',VAT)=1,'Seller',null()))) as Flag
FROM [lib://DataFiles/salescustomer.xlsx]
(ooxml, embedded labels, table is Customers);

View solution in original post

2 Replies
steeefan
Luminary
Luminary

One possible solution with the two tables already created:

LEFT JOIN (sales) LOAD
  VAT as buyervat,
  1 AS buyervatFlag
RESIDENT
  customers;

LEFT JOIN (sales) LOAD
  VAT as sellervat,
  1 AS sellervatFlag
RESIDENT
  customers;

sales2:
LOAD
  buyervat,
  sellervat,
  name,
  If(buyervatFlag and sellervatFlag, "Buyer/Seller",
    If(buyervatFlag and Not(sellerVatFlag), "Buyer",
      If(sellerVatFlag and Not(buyervatFlag), "Seller",
        Null()
      )
    )
  ) AS BuyerSeller
RESIDENT
  sales;

DROP TABLE sales;
Ahidhar
Creator III
Creator III

try this

sales:
LOAD
buyervat,
sellervat,
name
FROM [lib://DataFiles/salescustomer.xlsx]
(ooxml, embedded labels, table is Sales);

map1:
mapping Load Distinct
buyervat as VAT,
1 as Flag
resident sales;

map2:
mapping load Distinct
sellervat as VAT,
1 as Flag1
resident sales;
customers:
LOAD
VAT,
Id,
if(Applymap('map1',VAT)=1 and Applymap('map2',VAT)=1,'Buyer/Seller',
if(Applymap('map1',VAT)=1,'Buyer',
if(Applymap('map2',VAT)=1,'Seller',null()))) as Flag
FROM [lib://DataFiles/salescustomer.xlsx]
(ooxml, embedded labels, table is Customers);