query of calculate the annual profit growth in qlikview by using text object - function

I want to calculate the annual average profit growth rate for 5 years by using a text object. Qlikview does not seem to support nested aggregation... I am new to QlikView, can anyone can help me?
Tried query:
='Annual Growth Rate (2003-2007) :' & avg((sum(Profit_per_Product)/sum(Total_Retail_Price))*100)
Thanks in advance!

QlikView does support nested aggregation and can fulfil your requirements if you utilise the AGGR function. This function allows you to perform aggregation over a set of dimensions that you specify and in its simplest form, can be use as follows:
=aggr(expression,dimension)
This means that expression is evaluated for each value of dimension. For example, in your case if you used sum(Profit_per_Product)/sum(Total_Retail_Price) as your expression, and used your dimension that contained your data's year, then aggr would result in five different values (one for each change in your year). As you wish to take the average, then the AVG function happily takes these five values and provides you with your desired result.
Therefore, all you need to do is to slightly change your expression to the following (here I assumed that your dimension that contains the year is named Year):
='Annual Growth Rate (2003-2007):' & num(avg(aggr(sum(Profit_per_Product)/sum(Total_Retail_Price),Year)),'0.00%')
I also added the NUM function to format your result as a percentage.
More information on Advanced Aggregation (i.e. AGGR) may be found in section 25.2 of the QlikView Reference Manual (in my copy it's on page 291).

Related

IF function in DAX PBI

I am trying to translate the following function from Qlikview (text object properties) to DAX PBI:
=if(SUM(TOTAL)>= 400000,
num((((SUM(TOTAL)-400000)*0.0118)+12000),'€ #.##0'),
How do I do this? Thank you.
The formula is incomplete. It doesn't state what you want to return if the condition is not met. The DAX syntax would be
=If(SUM(TableName[Total])>=40000,((SUM(TableName[Total])-40000)*0.0118)+12000,null)
The "null" is returned when the sum of the total is less than 40000. Adjust as required. You can use formatting to apply the desired currency format. In DAX, the format is not applied inside the formula.
Also, you may want to use an initial measure to calculate the total, then re-use that measure in other calculations. It is more efficient.
Create a measure for the total, for e.g.
Total Turnover = SUM(TableName[Total])
Then use that in the formula for the calculation measure
WhateverName = If([Total Turnover]>=40000,(([Total Turnover]-40000)*0.0118)+12000,null)

How to calculate % in table

I am trying to find-out % in the column level which should 4121/7975-52% similar to other also but somehow it is not working & showing 13%. Kindly help me out.
You will need to use a scope in the expression you are using to calculate the percentage. Month, in the example below, is the scope.
=Fields!qty.Value/Sum(Fields!qty.Value, "Month")
Since I don't have your RDL, you will need to determine what the scope name should be based on the group name for the months (Jan, Feb. etc.). This can get a little tricky, so you may have to try a few different scopes to get what you need. Chances are it will be whatever the name of the field is you are using for the month values. The group properties for that column will show the name, too.

How can I add an aggregate percentage to an SSRS report based on two specific columns in a matrix?

I am somewhat new to SSRS and I have built a matrix report that looks fairly simple:
Supplier [AccDate]
[SupplierName] Sum(PurchasingCredit)
Total <<Expr>>
The actual report shows month-by-month sales data for a year in addition to Current YTD and Previous YTD columns (joined via UNION clause in base query) in addition to a column showing Year-over-Year % as difference between the Current YTD and Previous YTD columns (also joined via union).
I was able to apply a dynamic format to the Year-over-Year column using the following expression in the Format property to show the YOY column as a percentage and the others as dollar amounts:
=IIF(Fields!AccDate.Value <> "YOY", "'$' #,0.00;'$' -#,0.00", "#,0.00 %;-#,0.00 %")
The last thing I need to do is to show the column totals, which are working for each column with the exception of the year-over-year percentages using the following:
=IIF(Fields!AccDate.Value <> "YOY", SUM(Fields!PurchasingCredit.Value), 0)
In the year-over-year (YOY) column, a sum of percentages doesn't make sense: I need it to recalculate this value based on the sums of the "CYTD" and "PYTD" columns, but I can't seem to figure it out. Any help would be greatly appreciated. I am guessing it is probably an application of scope, but the MS articles that attempt to explain this are very confusing.

SSRS subtotalling columns with expressions

Using Visual Studio 2010 and SQL Server 2012
I have made an SSRS report that requires a custom method to subtotal and arrive at a grand total for Percent of Assets and other calculations derived from Percent of Assets. I cannot simply use the Add Total Function because it is grayed out as is typical when summing expressions. I cannot manually calculate the subtotals because I get a nested aggregate error.
The software I'm using to make this SSRS report provides various stored procedures and functions to make reports using derived computations. The stored procedure contain a Percent of Assets column but because the report is filtered to show only common stock, the percentage of Assets function is incorrectly still counting unfiltered assets in its calculation. The assets under consideration make up 59.7 % of total holdings but I need the report to behave as if they were 100% of holdings.
To understand some of the math in this report please look at the following report output. Note that the report I want only includes common stock which make up 59.7 Percent of total assets as mentioned.
This report represents the desired output which is currently being calculated in a different reporting program. The report has two tables
% Company Sales is a hard coded value that represents the percent of sales that are either domestic or international. You see this and % Portfolio Assets in both the international and domestic tables.
% Portfolio Assets is calculated by multiplying the percent of assets of a given holding by the hard coded company sales value. In the first example McDonald's 2.1% Portfolio Assets is 6.6% * 32%.
6.6% is the percent of Assets McDonald's represents in the portfolio is if you only count common stock (exclude cash)
McDonald's Value Total Portfolio Value %
4,950.00 / 73,919.50 = 6.6000%
Domestic/ International Percentage breakdown
Total % Sales %Split Region
6.60% 32% 2.1% Domestic
6.60% 68% 4.5% International
Now here is my report output. It differs slightly from the design layout I will be showing because I added columns and changed the headers for explanatory purposes in this preview example. So far I am just trying to get the Domestic table to work. Once that is working I will build the international table. I have a few extra colums that I'm using for troubleshooting.
I have tried several methods to Calculate Portfolio Assets. I can get the individual row values to be correct but I cannot get the subtotal value to be correct using different methods due to a nested aggregate error (summing and already summed expression when a data scope is used) The grand total is also important but for now I'm just trying to get subtotal working.
Here is one method to get the row detail value for Percent of Assets. This is used in the calculated Percent Column. This column is the one that won't allow me to subtotal without a nested aggregate error.
When I try to use the following expression to get the subtotal I get the nested aggregate error
=SUM(Fields!MarketValue.Value/Sum(Fields!MarketValue.Value, "DataSet1"))
ERROR Error 2 [rsInvalidNestedDataSetAggregate] The Value expression for the text box ‘Textbox39’ has a nested aggregate that specifies a dataset scope. Inner aggregates cannot specify a dataset scope.
If use the PercentAssets field which is included in the Stored Procedure I can subtotal and get grand total without errors but the value is the filtered value which only sums to 59.7 if I multiply this filtered percent by the company sales the value is wrong.
Last I tried to use custom VBA code to get my subtotal and grand totals. However this provides a running total of the calculated percents not the subtotals I need for the SectorName groups.
Here is the VBA Code I used which I found on the web here:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1d3c5ec1-89cb-4108-8637-ff434027b1ec/sum-an-expression-value-ssrs
Dim public nettotal as Double
Public Function Getvalue (ByVal subtotal AS Double) AS Double
nettotal = nettotal+ subtotal
return subtotal
End Function
Public Function Totalvalue()
return nettotal
End Function
Code deployed
In summary I need to multiply the calculated Percent column's values by the Company sales. I need to subtotal the result of these calculations.
If you look in the Information Technology Sector Grouping you can see the original report correctly arrives at 32.8 as the subtotal.
My report incorrectly arrives at 100% because that is the running total tally of the Calculated percents.
Here is a link to the original rdl
https://dl.dropboxusercontent.com/u/87501202/InternationalDomestic.rdl
It looks like your code:
=SUM(Fields!MarketValue.Value/Sum(Fields!MarketValue.Value, "DataSet1"))
isn't quite correct... Try this instead:
=SUM(Fields!MarketValue.Value)/Sum(Fields!MarketValue.Value, "DataSet1")
Breaking it down slightly, the second piece of code is expression / expression; now it's just two SUM expressions with different scopes as required - the first one looks like the syntax is off slightly, hence your error.

Using running totals in MS access report cumulatively

I am developing a db (MS access 2010) to support a school with a well-defined model for tuition quotation. The list of products is assembled for each quote, then various discounts are applied. The discounts may be a percentage or an absolute dollar amount. So far, so easy. The problem is that their business logic requires:
No limit on number of discounts.
Specific discounts to be applied in a defined sequence (implemented in my case with a "discount ordinal" column, values 1 (first applied) to 100 (last applied).
Each sequential application of a discount is to the running total of the quote. Eg: Total products $1000. Discount: 50%. Value: $500. Subtotal $500.
Subtotal: $500. Discount: $25. Value: $25. Subtotal: $475.
Subtotal: $475. Discount: $10%. Value: $47.50. Subtotal: $427.50.
This appears to be a variation of the "get the value of the field in the previous row" problem, but with the added twist that the "value of the field" is actually a cumulative calculation. It has the flavor of recursion: while discounts remain, subtotal(previous subtotal).
I have no clear idea how to implement this in a report, because the calculation as noted above is self-referential. I'm not looking for code here, just guidance on the general approach to the problem (ie, some kind of global variable, using VBA - in which case, I'm not sure what the "glue" between the query in VBA and the report would be - or some trick with a calculated field although I've spent a lot of time trying to figure one out). Any thoughts?
In that kind of situations, I always create a new table, that will get filled up when the report opens, and base the report in that table, not the original one. That way I can do all the calculations I need, even making several passes. The report then is simply a "dump" of the table. Complex totals can be additional columns, that will be shown only in the totals section.
You could have table for purchase history using an integer to link each purchase since an autonumber by itself will not link each discount stage.
So in excel I would use something like this:
v = Starting Value
i = 1
Do Until i = Last Discount
d = ws.Cells(i, 9).Value
v = v * (1 - d)
ws.Range("B2").Value = v
i = i + 1
Loop
At each stage you could write to the table (using docmd.runsql) the discount applied (d) and the value (v) but it could be quite slow. You could then order the table by purchase identifier then descending by value since sequential discounts will inherently order correctly.