Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
adecora
Contributor II
Contributor II

Group By - with an added condition

````

Dummy:
LOAD * INLINE [
    Customer, Sales, Flag
    A, 100, 2
    A, 150, 2
    A, 300, 0 
    B, 50, 3
    B, 100, 2
    B, 30, 1
];

```

Hi, I want to group this dummy data by customer, but with the condition to sum just register where each customer Flag has is top value.

So for customer A registers must sum only where Flag = 2 and for customer B registers where Flag = 3.

is there any way to do it dynamically?

 

```

// Dummy table solution

// A, 250, 2
// B, 50, 3

```

 

Labels (1)
1 Solution

Accepted Solutions
Kushal_Chawda

@adecora  try below

Data:
LOAD * INLINE [
    Customer, Sales, Flag
    A, 100, 2
    A, 150, 2
    A, 300, 0 
    B, 50, 3
    B, 100, 2
    B, 30, 1
];

Inner Join(Data)
Load Customer,
     max(Flag) as Flag
Resident Data
Group by Customer;

Final:
load Customer, 
     sum(Sales) as Sales
Resident Data
Group by Customer;

Drop Table Data;

 

View solution in original post

2 Replies
Kushal_Chawda

@adecora  try below

Data:
LOAD * INLINE [
    Customer, Sales, Flag
    A, 100, 2
    A, 150, 2
    A, 300, 0 
    B, 50, 3
    B, 100, 2
    B, 30, 1
];

Inner Join(Data)
Load Customer,
     max(Flag) as Flag
Resident Data
Group by Customer;

Final:
load Customer, 
     sum(Sales) as Sales
Resident Data
Group by Customer;

Drop Table Data;

 

adecora
Contributor II
Contributor II
Author

Thanks, this was exactly what i was looking for.