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: 
t_guet01
Contributor II
Contributor II

Can I add a condition to an existing measure I use in another measure?

Hey guys,

 

coming from Power BI, I still find it a little difficult to adapt to conditional measures in QS. I have several questions:

 

  1. Say I would like to compute the absolute margin. I already have formulas for revenue and cost. I could create a new measure saying Margin = [Revenue] - [Costs]. Now, I would only like to compute margin for products from product group 'A'. Is it possible to add a condition like {<ProductGroup='A'>}, to such formula of 'reused' measures without writing the actual formula of revenue and cost again? E.g. like Margin = ( {<ProductGroup='A'>}, [Revenue] - [Costs]) ?
  2. I created a conditional measure counting the revenue of product group "A": Revenue = sum( {<ProductGroup='A'>} [InvoiceAmount]) . I would now like to add a condition stating this measure should ignore the year filter. I can add it as  {1<Year = $::Year>}  but not in combination with the original product group filter. How do I add this "ignore filter" (of year)  to the original product group filter? (I would still like to filter ProductGroup A but ignore the years)
  3. Not all my products have transactions - say 8 out of 10 products have transactions in the past 2 years, which are represented in my dataset. I would now like to compute the average revenue per product. When selecting a year or even both years, only those 8 products with transactions are displayed even though I applied {1<Year = $::Year>}. However, in my computation of the average revenue I would like to take all 10 products into account. How would I include all data?

My examples are obviously made up - I am more interested in the general concept / syntax.

Thanks a lot in advance, guys - that would help my understanding of conditional measures in QS.


Best

T

Labels (2)
1 Reply
hic
Former Employee
Former Employee

1. The simplest way to do this is to just select ProductGroup='A', by clicking on this field value, and then look at the measure value. Selections work globally, so you don't need to hard code them.
However, if you want to hard code the filter into the measure definition, I must unfortunately say that it is not possible, unless you change the definitions of Revenue and Costs. We are however aware of the limitation and are looking into possible solutions.

2. Just use "{<ProductGroup='A', Year=>}" and you will cancel the selection in Year.

3. This can be achieved by using a set expression in the denominator only: "Sum(Revenue) / Count({1} distinct total Product)". The "{1}" will make the denominator insensitive to your selection, and the "total" will make it insensitive to the dimension in the chart (it will return the total in the chart, and not the value for the specific dimensional value).

HIC