Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Creating a Column based on a condition

Hi,

I have loaded some columns in Qlik Sense Desktop which are:

  1. "Date",
  2. Description,
  3. "Short Description",
  4. Segment,
  5. "Sub Segment",
  6. "Transaction Value",

Segment has values like Home and Entertainment.

I want to create another column where the columns is named "Home" and the values are from Transaction Value IF the Segment contains Home. Hopefully this table makes it clear.

SegmentTransaction ValueHome (new column)
Entertainment (new column)
Home $100$100
Entertainment$200$200
Entertainment$300$300
Home$400$100

Any help here would be appreciated.

1 Solution

Accepted Solutions
sunny_talwar

Try this:

LOAD "Date",

          Description,

          "Short Description",

          Segment,

          "Sub Segment",

          "Transaction Value",

         If(Segment = 'Home', "Transaction Value") as Home

          If(Segment = 'Entertainment', "Transaction Value") as Entertainment

FROM Source;

View solution in original post

5 Replies
Not applicable
Author

In your Home field put :

if(Segment='Home',[Transaction Value],'')

sunny_talwar

Try this:

LOAD "Date",

          Description,

          "Short Description",

          Segment,

          "Sub Segment",

          "Transaction Value",

         If(Segment = 'Home', "Transaction Value") as Home

          If(Segment = 'Entertainment', "Transaction Value") as Entertainment

FROM Source;

Gysbert_Wassenaar

You can create extra fields in the script as Sunny showed above. You can also use three expressions in a straight table with Segment as dimension:

  • sum([Transaction Value])
  • sum({<Segment={'Home'}>}[Transaction Value])
  • sum({<Segment={'Entertainment'}>}[Transaction Value])

talk is cheap, supply exceeds demand
Not applicable
Author

Thanks Sunny,

This worked perfectly. You're a legend.

Not applicable
Author

Thanks Gysbert,

This seems to work as an alternative as well. Appreciate your help as well.

Thanks a lot

Delzad