Interactive Report - aggregate sum of multiple columns from one table multiply by values from another Table - aggregate

I have a challenge in Oracle Apex - I would to sum multiple columns to give 3 extra rows namely points, Score, %score. There are more columns but I'm only choosing a few for now.
Below is an example structure of my data:
Town | Sector | Outside| Inside |Available|Price
Roy-----Formal----0----------0----------1------0
Kobus --Formal----0 ---------0--------- 1------0
Wika ---Formal----0----------0--------- 1------0
Mevo----Formal----1----------1----------1------0
Hoch----Formal----1----------1----------1------1
Points------------2----------2----------5------1
Score------------10---------10---------10------10
%score-----------20---------20---------50------10
Each column has a constant weighting (which serves as a factor and it can change depending on the areas). In this case, the weighting for the areas are in the first row of the sector Formal:
Sector |Outside| Inside |Available|Price
Formal----1----------1 ----------1-----1
Informal--1----------0 ----------2-----1
I tried using the aggregate sum function in apex but it wont work because I need the factor in the other table. This is where my challenge began.
To compute the rows below the report
points = sum per column * weighting factor per column
Score = sum of no of shops visited (in this case its 5) * weighting factor per column
% score = points/Score * 100
The report should display as described above. With the new computed rows below.
I kindly ask anyone to assist me with this challenge as I have tried searching for solutions but haven't come across any.
Thanks a lot for your support in advance!!

Related

Tableau How to evenly split a Ranking Table into two

I am trying to evenly split a ranking table into two.
I tried to create a calculated field using rank to divide the data into two groups.
The problem with this approach is that there are too many entries in the first column because they are tie with rank 1.
I don't want to break the tie but display evenly in both columns.
So, desired output will look like...
25 states with Rank 1 are displayed in column 1, and the rest 12 rank 1 states and the other states from rank 38 to 49 are displayed in column 2.
In order to split your rows within a specif number (say 25) you can't rely just on rank due to same values for multiple rows.
Even though your Rank calculated field must be shown in the chart, you can add another calculated field based on rank_unique which will provide you a progressive number for rows having the same value for the specified metric.
Just use the specified function:
RANK_UNIQUE(SUM([Value]),'desc')
And then use the calculated field as a filter to "split" the results as you need (in this example 1-4, 5-8).

Percentage of total changes on applying filter

I have a data table with three dimensions and one measure. For each row, I am trying to calculate the percentage of total (calculated by taking the sum of rows) using a calculated field.
As seen in the screenshot attached, For the column titles 'Dec-19' I want the values to be a percentage of current value / grand total (calculated at the bottom as 122,187)
Screenshot of DataTable:
So e.g. for the Column B value of 2000, the Dec-19 column should be (97/122,187) * 100 = 0.079.
I have achieved this by creating a calculated field with the formula: SUM (sales) / MAX ({EXCLUDE (Column B): Sum (sales}), where sales is the measure used in the datatable.
However, upon application of filter on column B, the percentage value changes. e.g. if I select the value 2000 in my filter for column B, I get the percentage as 100%. It seems as if the percentage is being calculated based on only the rows in the filter.
Since you haven't included any sample data, I created some sample data like this, hope this resemble yours.
Thereafter, I built a cross-tab view in tableau, somewhat like yours
If that is the scenario, use a calculated field, say CF like this, instead of yours
([Sales])/
{FIXED [Col1], DATETRUNC('month', [Col3]) : sum([Sales])}
Dragging it in the view
and thus, filtering won't affect your calculation

Tableau: Calculate the average value for the last 3 records

I have a time series data fro the different products. i like to calculate the average for each products based on only last 3 values. can you please help me.
Thanks
Kathir
Use SIZE() - INDEX() + 1
Drag it to your row or column and convert as discrete. Use table calc if needed
Now you will have an index for each row. Create another calculated field which will be using fix LOD of the above calculated field and when Index = 1 or 2 or 3, it sums it
You will be able to calculate average by diving the field with the sum of fix LOD created

Dividing AVG of column1 by AVG of column2

I am trying to divide the average value of column1 by the average value of column 2, which will give me an average price from my data. I believe there is a problem with my syntax / structure of my code, or I am making a rookie mistake.
I have searched stack and cannot find many examples of dividing two averaged columns, and checked the postgres documentation.
The individual average query is working fine (as shown here)
SELECT (AVG(CAST("Column1" AS numeric(4,2))),2) FROM table1
But when I combine two of them in an attempt to divide, It simply does not work.
SELECT (AVG(CAST("Column1" AS numeric(4,2))),2) / (AVG(CAST("Column2" AS numeric(4,2))),2) FROM table1
I am receiving the following error; "ERROR: row comparison operator must yield type boolean, not type numeric". I have tried a few other variations which have mostly given me syntax errors.
I don't know what you are trying to do with your current approach. However, if you want to take the ratio of two averages, you could also just take the ratio of the sums:
SELECT SUM(CAST(Column1 AS numeric(4,2))) / SUM(CAST(Column2 AS numeric(4,2)))
FROM table1;
Note that SUM() just takes a single input, not two inputs. The reason why we can use the sums is that average would normalize both the numerator and denominator by the same amount, which is the number of rows in table1. Hence, this factor just cancels out.

DAX: Averaging multiple % Columns

I'm new to Power BI and Dax, having some difficulty with the below scenario.
test a b c d AVERAGE
aa 51.97% 46.61% 49%
I have 4 columns, a-d, and I simply want the average of the 4 columns in the AVERAGE column. Dependent on the row different columns may be blank. Each of the columns are measures pulling through a % value into the table.
I'm sure there must be a simple solution to this but any help would be much appreciated.
Try creating a column like this:
AVERAGE = ([a]+[b]+[c]+[d])/4
UPDATE: BLANK measures don't affect average result.
AVERAGE = DIVIDE(([a]+[b]+[c]+[d]),
(IF(ISBLANK([a]),0,1) + IF(ISBLANK([b]),0,1) +
IF(ISBLANK([c]),0,1) + IF(ISBLANK([d]),0,1)))