QlikView Calculated Dimension - qlikview

I have the following table:
enter image description here
I need to add a calculated dimension ProductEntryDate based on the following condition:
If the DrugSubstanceFlag = 'Y', then the ProductEntryDate is the Maximum of the 'Patent Expiry Date'. I will also need to add a calculated dimension 'RestrainingPatent' which is the Patent Number matching the ProductEntryDate. So in this case the ProductEntryDate will be '24/11/2016' and the RestrainingPatent will be '7326708'. How can this be accomplished in QlikView? Thanking you in advance

Related

Complex Filter on SSAS calculated Member

I Tried to create a calculated measure inn my SSAS cube with complex filters as the following:
([Measures].[Amount],[Scenarios].[Scenario Key].&[1],[AccountType],[AccountType].[Account Type].&[Bank],[AccountType].[Account Type].&[Cash],[AccountType].[Account Type].&[NotesReceivable],[JE Type].[JE Type].&[CI],[JE Type].[JE Type].&[NR])
I want to Get the summation of amount value which has:
Scenario Key = 1
Account Type IN ("Bank","Cash","NotesReceivable")
JE Type IN ("CI","NR")
But i Get this measure as Null So can any one can help to solve this?
It's not working because you are doing an intersection of the same dimension hierarchy:
[AccountType].[Account Type].&[Bank],[AccountType].[Account Type].&[Cash]
means in MDX: Account Type = Bank AND Account Type = Cash at the same time.
Just use set of members and SUM function.
Try this one:
SUM(
{[AccountType].[Account Type].&[Bank]
,[AccountType].[Account Type].&[Cash]
,[AccountType].[Account Type].&[NotesReceivable]}
*
{[JE Type].[JE Type].&[CI]
,[JE Type].[JE Type].&[NR]}
,([Scenarios].[Scenario Key].&[1],[Measures].[Amount]))
Explanation:
SUM - aggregate function
Dimension1 filter * Dimension2 filter - gave all combinations
(Dimension3,measure) - filters out single-selected dimensions

In a pivot table: how to ignore dimension in an expression using a variable that depends on that dimension

I'm trying to rank (A,B,C) a list of customers according to their profitability , which is calculated as the amount of each sale multiplied by the product profitability (each product has a profitability value assigned). Hence, Profit = SaleAmount*ProductProfitability
To rank every customer, I have a pivot table with the customer id (CustID) as dimension and two expressions:
1)
= SaleAmount*ProductProfitability
2) = if(SaleAmount*ProductProfitability > $(vPercentile75Profit),'A', if(SaleAmount*ProductProfitability > $(vPercentil25Profit),'B','C'))
Expression 2) works correctly if I fix the values of vPercentile75Profit and vPercentile25Profit, but obviously I need this to be dynamic.
For that I've defined those variables as (same for both, just switching 0.75 with 0.25):
vPercentile75Profit =Fractile(aggr(sum({$<ProductProfitability = {'>0'} >} SaleAmount*ProductProfitability/100),CustID), 0.75)
If I understand well, this calculates a list of each customer profitability and then performs the 75 percentile of that list (which is a single value). This works great if I show the value in a Text box for example, however, if I use it in my table, it takes a different percentile for each customer (since CustID is in the dimension).
How can I bypass this? The percentiles must be the same for each customer, but I cannot find the way.
Thanks in advance, any help will be greatly appreciated!
Nothing works better to find the answer than asking your question to others. It was as simple as adding TOTAL to the variable definition:
vPercentile75Profit =Fractile(TOTAL aggr(sum({$<ProductProfitability = {'>0'} >} SaleAmount*ProductProfitability/100),CustID), 0.75)

Advice needed on weighted averaging in power query or power pivot

I need to create a weighted average that multiplies a column of volume manufactured for multiple manufacturing plants by a column containing the cost to manufacture at each plant, and returns one weighted average value for a specific product type for all plants.
I've tried adding this as a calculated column using:
=sumx('Plant','Plant'[Cost]*'Plant'[Tonnage])/sum('Plant'[Tonnage])
But this goes row by row, so it doesn't give me the full over riding average that I need for the company. I can aggregate the data, but really want to see the average lined up against individual plant for benchmarking
Any ideas how I can do this?
You can do this in multiple ways. You can either make a single more complex calculation, or you can make a few calculated columns to make the final calculation more transparent. I will pick the latter approach here, because it is more easy to show what is going on. I'm going to use the following DAX functions: CALCULATE, SUM, and ALLEXCEPT.
First, create three new calculated columns.
The first one should contain the [Volume] times [Cost] for each record:
VolumeTimesCost:=[Volume] * [Cost]
The second one should contain the sum of [VolumeTimesCost] for all plants within a given product type. It could look like this:
TotalProductTypeCost:=CALCULATE(SUM([VolumeTimesCost]),ALLEXCEPT([Product Type]))
Using the ALLEXCEPT([Product Type]) removes the filter from all other columns than the [Product Type] column.
The third calculated column should contain the SUM of [Volume] for all plants within a given product type. It could look like this:
TotalProductTypeVolume:=CALCULATE(SUM([Volume]),ALLEXCEPT([Product Type]))
You can then create your measure based on the two calculated columns [TotalProductTypeCost] and [TotalProductTypeVolume].
I hope that helps you solve the issue correctly. Otherwise feel free to let me know!

How can I create filter based on two different fields with OR operator between them in Power View?

For example I want to filter my data based on next filter expression:
lead_veh_of_interest starts with 'BMW 1'
OR
sale_model starts with 'BMW 1'
how can I achieve this?
Are these fields both in the same table? If so you could create a calculated column that performs that conditional. Then filter the view on the resulting calculated column.
For example you could create the following calculated column.
Calculated Column: "Starts With BMW 1"
Equation:
=IF(OR(Left([lead_veh_of_interest starts], 5) = "BMW 1", Left([sale_Model], 5) = "BMW 1"), 1, 0)
Then in the view set the filter so that [Starts With BMW 1] = 1
I found acceptable solution (thanks for all suggestions - it was very helpful).
First of all I redesigned my model and (how #Mike_Honey suggsts me) created dedicated table with consolidated information I want to filter. Next I connected this new table with existing tables and created hierarchy from fields I want to give to the end users for step-wise filtering (previously I split down old fields contained information I want to filter into more granular level). Now it is possible to filter data by any combination of models in any combination of request types (sale, lead, competitor, etc) using hierarchy.

SSRS Expression Sum Between Numbers

I am seeking assistance with creating a VB expression in SSRS that subtracts SUMS. I have a dataset that has accounts and corresponding money/amount values. I need help creating an expression that sums up the money/amount values from one group of the accounts in a specified range, and then subtracts it from the money/amount total of another range. Specifically:
(Sum(amt) where acct between 40000 and 49999) -
(Sum(amt) where (acct between 50000 and 59999) or (acct between 66000 and 69999)) -
(Sum(amt) where acct between 76000 and 79825) -
(Sum(amt) where acct between 89000 and 90399)
Really need help translating this SQL logic into a VB expression to be used for a textbox in SSRS. Any advice would be extremely helpful! Thanks!
textbox can only capture the first value of the dataset, so if you go to the expression builder for the textbox, you can see there are no fields from the dataset available. But, aggregate functions on dataset fields are available.
So you can create a calculated field to your dataset and add amount values to it with appropriate signs such that the sum of all the values in this calculated field represents your desired solution.
For example, add a new calculated field to your dataset. In the field source, add an appropriate expression like:
=IIF(Fields!acct.Value>=40000 AND Fields!acct.Value<=49999, CInt(Fields!amt.Value),
IIF( (Fields!acct.Value>=50000 AND Fields!acct.Value<=59999) OR
(Fields!acct.Value>=66000 AND Fields!acct.Value<=69999) OR
(Fields!acct.Value>=76000 AND Fields!acct.Value<=79825) OR
(Fields!acct.Value>=89000 AND Fields!acct.Value<=90399),
CInt(0 - Fields!amt.Value), CInt(0)
)
)
This keeps the values between 40000 and 49999 as they are. Makes all values needed to be subtracted into negative values. And everything else you don't wish to consider as 0.
Therefore when you call
Sum(Fields!calcfield.Value, "your dataset name")
from the textbox, you add the values between 40000 and 49999, and subtract values in ranges you wanted.
Please change the expression for the calculated field as per your need, the procedure will work.
You shouldn't go through all the values in a dataset directly from a textbox.
Hope it helps.