Qlikview Ranking Expression - ranking

Quick question,does anybody know how to set an expression in Qlikview whereby the user could rank as follows:
"Company X first always, followed by all other companies ranked by highest value to lowest value"
Apologies this might seem like a very basic question as I am a novice in Qlikview.
Thank you for your help,
Liam

Set the sorting of the company field to be something like this:
if( company = 'Company6', 1000000, sum(value) )
Having the following data:
Companies:
Load * Inline [
company, value
Company1, 10
Company5, 60
Company2, 50
Company3, 30
Company4, 40
Company6, 20
];
And the result is below

Related

Power Query (M language) 50 day moving Average

I have a list of products and would like to get a 50 day simple moving average of its volume using Power Query (M).
The table is sorted by product name and date. I add a custom column and applied the code below.
if [date] >= #date(2018,1,29)
then List.Average(List.Range(Source[Volume],[Volume]-1,-50))
else ""
Since it is already sorted by date and name, an if statement was applied with a date as criteria/filter. However, an error occurs that says
'Volume' column not found in the table.
I expect to have an added column in the power query with volume 50 day moving average per product. the calculation to be done if date is greater than or equal Jan 29, 2018.
We don't know what your columns are, but assuming you have [product], [date] and [volume] in Source, this would average the last 50 days of [volume] for the identical [product] based on each [date], and place in a new column
AvgAmountAdded = Table.AddColumn(Source, "AverageAmount", (i) => List.Average(Table.SelectRows(Source, each ([product] = i[product] and [date]<=i[date] and [date]>=Date.AddDays(i[date],-50)))[volume]), type number)
Finally! found a solution.
First, apply Index by product see this post for further details
Then index again without criteria (index all rows)
Then, apply below code
= Table.AddColumn(#"Previous Step", "Volume SMA(50)", each if [Index_byProduct] >= 50 then List.Average(List.Range(#"Previous Step"[Volume], ([Index_All]-50),50)) else 0),
For large dataset, Table.Buffer function is recommended after index-expand step to improve PQ calculation speed

Exchange rates for ENDOFMONTH

I have an Exchange Rate table that I'm trying to get the ending months calculation
It's using a minimum of 3 currencies lets use GBP USD EUR
I need to return when selecting that currency the End of month Currency
So something like k
EOMCcy=:IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE([Exchange Rate],ENDOFMONTH('Exchange Rates'[Date]) ,BLANK()))
I know I need to validate the currency somewhere and I'm trying many thinks as I have a fromCcy and toCccy column e.g GBP USD
This would show in the [Exchange Rate] column =1.22
I was hoping someone can point me in the right direction or offer a better method with my code
Thank all
So I think I solved it
EOMCcy:=IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE (
SUM ([ExchangeRate]),
FILTER (
ALL ( 'Exchange Rates'[Date]),
'Exchange Rates'[Date] = ENDOFMONTH('Exchange Rates'[Date])
)
),BLANK())

MDX: Calculating MONTH COVER (of Stock) in a performant way

this is my dataset:
I want to calculate the "Cover Month". Therefore I have to look for Stock(in this example in january 2016 = 5,000), then have a look for each future month if current stock(january 2016) is bigger than "cum. Sales" of following month. If yes, then remember value = 1. This should be done for each future month. After this step all remembered values should be added, so result is 4 (Cover Month). Stock will be enough for 4 following months.
Next step system should do this for next month - dynamically for each month...
How can I do this in a performant way?
Is this the right way:
Filter([TIME].[Year to Month].currentmember : NULL,
[Measures].[cum Sales] < [Measures].[Stock])
?
Maybe anybody can give me a hint? Or maybe I need another alternative formula to get a subtotal and then do another calculation?
Thanks in advance, Andy
If you just require a 1 or 0 then can things not be simplified:
IIF(
SUM(
{[TIME].[Year to Month].currentmember : NULL},
[Measures].[cum Sales]
)
< ([Measures].[Stock],[TIME].[Year to Month].&[Jan-2016]) //<<amend to the date format used in your cube
,1
,NULL
)

Count amount separately depends on field value in Crystal Report VS2010

I am a beginner for Crystal report. I do not know how to work with formula editor.
My question is,
Table Name - Expenses
Field Name - Date, Purpose(Text), Less(Boolean), Amount(Double)
I want to count Less(Yes) Amount separately and Less(No) Amount separately. How to count this.
Please help me..
You will need two formulas:
Formula will show 1 for each record that has Less = True:
if less = True then 1
else 0
Formula 2 will show 1 for each record that has Less = False:
if less = False then 1
else 0
Now put those two formulas in your detail section and then do a sum on each one in your group footer. You can suppress the formulas in the detail section if you don't want to see them.
Hope that helps,
Chris

Visual Studio 2008 Report Designer (complex general ledger)

I'm combining reports to create a single general ledger report, currently it consists of 84 seperate reports. My idea is the end user will have a drop down for the department and month. These are my columns:
Account Number Account Description Current Period Actual
YTD Actual YTD Budget YTD Budget Variance
Total YR Budget Account Status
I have most of it figured out, but can't understand how to figure YTD Actual and YTD Budget since these will require a Sum of multiple Fields depending on what month and department is selected.
My where statement goes something like this and takes care of the current period actual and account number:
Where
( gl_master.acct_cde = gl_master_comp_v.acct_cde ) and
( gl_master.budget_officer = budget_off_mstr.budget_officer ) and
( ( gl_master_comp_v.acct_comp1 = '01' ) AND
( budget_off_mstr.budget_officer IN (#BudgetOfficer) ) ) AND
((#Month = 1 AND gl_master.post_bal_mon_1) OR
(#Month = 2 AND gl_master.post_bal_mon_2)...
How can I have the query recognize what needs to be put into the column when there are multiple fields being summed.
Thanks for any insight. If you made something like this before a small sample of it would be very helpful.
I worked it out.
It needs to be done in a calculated field within the dataset. Then a sum can be done on the field in the textbox.
small chunk of calculated field:
=Cdec(Switch(Parameters!Month.Value = 1, Fields!post_bal_mon_1.Value,
Parameters!Month.Value = 2, Fields!post_bal_mon_2.Value + Fields!post_bal_mon_1.Value,
Parameters!Month.Value = 3, Fields!post_bal_mon_3.Value + Fields!post_bal_mon_1.Value + Fields!
post_bal_mon_2.Value,
Parameters!Month.Value = 4, Fields!post_bal_mon_4.Value + Fields!post_bal_mon_1.Value + Fields!
post_bal_mon_2.Value + Fields!post_bal_mon_3.Value,...))
textbox for sum(I place this in footer):
=SUM(Fields!post_bal_mon_1.value, "DataSet1")

Resources