How to add the dynamic pivot table columns in apex interactive grid? - oracle-apex

Is it possible to add dynamic pivot columns in the APEX interactive grid query?
PL/SQL function body returning SQL query:
DECLARE
l_piv_col VARCHAR2(1000) := NVL(:P1_DEP_PIVOT,'10 DEP1');
l_statement VARCHAR2(4000):=
q'~
select rownum row_num,JOB,MGR,DEP1,DEP2,DEP3
from
(select JOB,
MGR,
SAL,
DEPTNO
from EMP
)
src
--PIVOT (sum(sal) for deptno IN (10 DEP1,20 DEP2,null DEP3)) Piv
PIVOT (sum(sal) for deptno IN (##PIV_COL##)) Piv
~';
BEGIN
RETURN REPLACE(l_statement,'##PIV_COL##',l_piv_col);
--RETURN l_statement;
END;
P1_DEP_PIVOT -> (10 DEP1, 20 DEP2, null DEP3)
In the pivot deptno in, I need to use the dynamic columns.
sum(sal) for deptno IN (##PIV_COL##)
I am not sure, how to add the dynamic pivot columns in APEX Interactive grid?
Any help is greatly appreciated.
Thanks

Thanks for the reproducible case.
Classic Report is the only APEX Component which supports the query returning a changing set of result columns. Interactive Reports and Interactive Grid do not support this.
In classic report, pick the region source as PL/SQL function body returning SQL query and enable the Generic Columns switch. Then configure the maximum amount of columns, and you're good to go.
There are a couple of workarounds that I can think of if you really need an interactive grid (IG).
Store the results of the query in a collection, create an IG on top of the collection and have a server side condition to hide the columns that should not be displayed
Make sure your query always returns a fixed number of columns and have page item (to manage hide/show) for each of the columns. If a column should not be in the pivot, hide it based on the page item.

Related

APEX Column value to change based on LOV in IG

Screenshot of my settings. On Interactive Grid - I have column-a "TaskID" and other column-b is "Predecessors", which is LOV of “TaskID” column. Each TaskID has a start date in Column-C. When I change the column-b value, the column-C date should change. I mean it should look for the TaskID column and return the corresponding date.
Any suggestions would be greatly appreciated. May be a dynamic action or SQL query.. I don’t know
Column a (TaskID), Column b (Predecessors), Column c (StartDate)
Yes, using a dynamic action will be the easiest way to do this.
Create an on change dynamic action on your predecessors column:
Then create a Set Value Action using the corresponding SQL query:

Making column reference via slicer

I have a table with two choices 'FLOW_CONTEXT' and 'TEST_NAME'.
I want to let the user select one of these values using a slicer. I then want to have a calculated formula point to either the 'FLOW_CONTEXT' or the 'TEST_NAME' column in another table. There is a 1:1 relationship between the 'FLOW_CONTEXT' and the 'TEST_NAME' columns in the table.
Here is the column formula I have, which always defaults to false, even though the SELECTEDVALUE part of the IF statement does work (checked via a card):
COLUMN_POINTER = IF(
SELECTEDVALUE(TEST_NAME_FIELD[TEST_NAME_FIELD]) = "FLOW_CONTEXT",
CCD_BINNING_TEST_RESULTS_LAST_RANK[FLOW_CONTEXT],
CCD_BINNING_TEST_RESULTS_LAST_RANK[TEST_NAME]
)
I have tried doing this with a measure but measures only see non-categorical columns. Thx much.
Columns are only calculated at refresh time - they do not respond to slicers filters in this way. You cannot re-calculate a column based on a selected value in a table visual.
You need to transform your use-case into a measure-friendly approach.

How to sort in Oracle Apex 19.1 Interactive Grid

I'm using Oracle Apex 19.1 on a 18.c platform.
I have a page with two regions: 1) Interactive Grid and 2) Interactive Report
I use the Interactive Grid to display a list of Producer names. When the user selects one of the names, the Interactive Report refreshes and displays the events assigned to that Producer. I use a Dynamic Action to update the Interactive Report.
This all works fine, except for the list in the Interactive Grid. It seems to display names in order by the table's PRIM_KEY and I want to sort the Interactive Grid by last name. The Source Code for the IG doesn't accept an Order By clause.
Select ac.first_name || ' ' || ac.last_name PRODUCER
From aff_contact ac, aff_contact_role acr
Where ac.prim_key = acr.contact_fkey
And acr.role = 'Producer'
;
The problem is, the column names in the IG toolbar's Actions / Data / Sort never populate. I wondered if the dual column in the Select statement was the problem, so I tested it with a simpler query for the Source:
Select last_name
From aff_contact
;
That still didn't produce columns to select for the sort. I receive a screen like the one below:
The Column select field has nothing to pull down. That holds true for both the original and the simplified query.
How can I get the IG to sort based on the LAST_NAME field? Is there another way to achieve this goal?
Thanks for looking at this.
After further checking, it seems that a VARCHAR2 column with a width <= 99 is selectable as a Sort or Control Break. A VARCHAR2 column with a width >= 100 is NOT selectable for Sort or Control Break in an interactive grid.
To identify the fields in the report Source I used the syntax:
cast( first_name as varchar2(32)) "FIRST_NAME",
cast( last_name as varchar2(32)) "LAST_NAME"
to avoid the default column width.
To sort by column:
01. Click the Actions menu, select Data, then Sort. The Sort dialog appears.
02. In the Sort dialog: Select a column, the sort direction (Ascending or Descending), and the null sorting behavior (Default, Nulls Always Last, or Nulls Always First).
a. Column - Select a column.
b. Direction - Select Descending or Ascending.
c. Nulls - Select First or Last.
03. To add another sort rule, click the Add button (+).
04. Click Save.
05. Click Report
06. Click Save
The interactive grid reloads.
Note:To ensure column sorting active. To ensure that you are login developer mode, otherwise it is not show other user

Fetch Returns only 1 Row - Interactive Grid - Oracle Apex

I have an interactive grid which has a dynamic action to fetch returns from another table
begin
for c in (select
REW_SIZE,
IN_STOCK,
DESCRIPTION,
FINANCIAL_YEAR_ID
into
:REW_SIZE,
:IN_STOCK,
:DESCRIPTION,
:FINANCIAL_YEAR_ID
from
T_SORDER_PROFOMA_REWINDING
where so_id = :so_id)
loop
:REW_SIZE := c.REW_SIZE;
:IN_STOCK :=c.IN_STOCK;
:DESCRIPTION:=c.DESCRIPTION;
:FINANCIAL_YEAR_ID:=c.FINANCIAL_YEAR_ID;
end loop;
end;
When I had simple select into query, it gave "exact fetch returns more than requested number of rows" thn I applied the above code but it returns only 2nd row. I have 2 rows in the table for this ID.
For what I understand, you want to get some extra data columns. Your best shot is to create a view to join these table and deliver the columns you need. If you need editing, you will have to create an instead of trigger on the view as well, to do a correct dml on one or both tables.
create view which joins both tables
create instead of trigger (if you need editing)
query of the Interactive Grid should be on the view
This solution adds the extra data columns to the source of the IG, which is better and easier in my opinion.

Trying to Reorder Columns in Data View in Power BI

Is there a way I can reorder columns in 'Data View' within Power BI? I tried doing it in Power Query first but when the data loads into the table, the columns automatically rearrange.
Edit after comment.
There is easy fix to enforce column order just as in Power Query:
In Power Query Editor > Disable Query Load. Close and Apply.
Open the Query Editor again, enable the Query Load. Refresh the Query. Then Close and Apply.
Answer to misunderstood question.
This may be interesting solution in M PowerQuery. The function below let you reorder columns by only stating few columns from the whole set of columns. Add this in blank query and rename it to FnReorderColumnsSubset.
(tbl as table, reorderedColumns as list, offset as number) as table =>
Table.ReorderColumns
(
tbl,
List.InsertRange
(
List.Difference
(
Table.ColumnNames(tbl),
reorderedColumns
),
offset,
reorderedColumns
)
)
Use it as this:
= FnReorderColumnsSubset( Source, { "Region", "RegionManager", "HeadCount" }, 0 )
Found it here:
https://datachant.com/2017/01/18/power-bi-pitfall-4/
It is extremely stupid way, but it is working - i found it by accident:
In edit query view remove the column, then save changes. You will see that in data view that column was removed as well.
Now again in edit query view remove from applied steps the action that removed the column. Save it again.
You will see that removed previously column was added to the end of the table.
This way you can arrange your columns to have it the way you want it in data view.
Hope it helped.
I don't know that you can rearrange an existing table, but if you re-create it as a new table, you can pick the order you want.
NewTable =
SELECTCOLUMNS (
OldTable,
"Column1", OldTable[Column1],
"Column2", OldTable[Column2],
"Column3", OldTable[Column3]
)
I think most here have misunderstood the problem, except #Jacko. So far as I know it is now possible to re-arrange columns in Power Query and load to the model and the table will load in the column order you specified in PQ. The problem is in dataview in the modelling layer of PBi. Here you can add many calculated columns, but, any new column you add is always placed at far right and can't be moved. Yes, I know about SELECTCOLUMNS but it isn't a solution as the new table does not have the editable formulae. A solution is a drag and drop feature of some sort. PBi users are still waiting for it despite the problem being flagged in MS Forums some years ago. No progress TIKO other than the limp SELECTCOLUMNS solution.