Query is not technically folding when using the `Value.NativeQuery(Source, Query, null, [EnableFolding=false])` option? - powerbi

I'm attempting incremental load using the following syntax:
Value.NativeQuery(Source, Query, null, [EnableFolding=false])
Steps:
Add SQL server data source
Enter server name, click OK
Right click on database name and click Transform
Click on the Navigation step (step 2 in the list of steps on the right hand side)
Click the fx button to add new step
Enter the query SELECT COL1, COL2, COL3 FROM TBLNAME
Add parameters for range start/end and apply the filters on this table's date column
Configure incremental refresh on the table
On the SQL server I can see the following queries:
select top 0 * from ( SELECT [id] ,[date] ,[ordnum] ,
[customer] ,[amt] ,[gm pc] FROM [DbName].[dbo].[tblSales] ) as [_]
select [_].[id], [_].[date], [_].[ordnum], [_].[customer], [_].[amt],
[_].[gm pc]
from ( SELECT [id] ,[date] ,[ordnum] , [customer] ,[amt] ,[gm pc]
FROM [DbName].[dbo].[tblSales] ) as [_] where [_].[date] >=
convert(datetime2, '2020-01-01 00:00:00')
and [_].[date] < convert(datetime2, '2021-01-01 00:00:00')
So technically the date range filters are applied to the result of the select everything statement that selects everything. So is this really doing an incremental refresh?

Related

Query for listing Datasets and Number of tables in Bigquery

So I'd like make a query that shows all the datasets from a project, and the number of tables in each one. My problem is with the number of tables.
Here is what I'm stuck with :
SELECT
smt.catalog_name as `Project`,
smt.schema_name as `DataSet`,
( SELECT
COUNT(*)
FROM ***DataSet***.INFORMATION_SCHEMA.TABLES
) as `nbTable`,
smt.creation_time,
smt.location
FROM
INFORMATION_SCHEMA.SCHEMATA smt
ORDER BY DataSet
The view INFORMATION_SCHEMA.SCHEMATA lists all the datasets from the project the query is executed, and the view INFORMATION_SCHEMA.TABLES lists all the tables from a given dataset.
The thing is that the view INFORMATION_SCHEMA.TABLES needs to have the dataset specified like this give the tables informations : dataset.INFORMATION_SCHEMA.TABLES
So what I need is to replace the *** DataSet*** by the one I got from the query itself (smt.schema_name).
I am not sure if I can do it with a sub query, but I don't really know how to manage to do it.
I hope I'm clear enough, thanks in advance if you can help.
You can do this using some procedural language as follows:
CREATE TEMP TABLE table_counts (dataset_id STRING, table_count INT64);
FOR record IN
(
SELECT
catalog_name as project_id,
schema_name as dataset_id
FROM `elzagales.INFORMATION_SCHEMA.SCHEMATA`
)
DO
EXECUTE IMMEDIATE
CONCAT("INSERT table_counts (dataset_id, table_count) SELECT table_schema as dataset_id, count(table_name) from ", record.dataset_id,".INFORMATION_SCHEMA.TABLES GROUP BY dataset_id");
END FOR;
SELECT * FROM table_counts;
This will return something like:

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

Create charts from SQL query

I want to create a chart from a join sql query between 2 tables in superset.
for example , I go to SQL Lab and execute this query :
select film, count("film") from rental r, payment p where r.rental_id=p.rental_id group by("film") order by count("film") limit 20;
This returns me a result but how to insert in a chart?
How to create chart from SQL query ?
In order to visualize the results from a query executed in SQL Lab, you first need to click on Explore (underneath the Results tab).
Once you are in exploration mode, you can change the "Visualization Type", under "Datasource & Chart Type".

How to get ID from LOV?

I'm learning APEX 5
I have a control named X_CONTROL, where I want to populate his content with an SQL query.
To do that, I need the ID primary key from a table, which should be the ID of the row selected on a Select List control named MY_LIST_CONTROL.
MY_LIST_CONTROL has a list of values taken from a column of the table "MyTable", which is not the ID primary key.
I tried to populate X_CONTROL with this SQL
Select ID from MyTable where ColumnName=:MY_LIST_CONTROL
It doesn't work, and should not work because ColumnName is not "unique", like ID is.
So, the question is, how do I recover, with SQL, the ID of the selected row which correspond to the selected value in MY_LIST_CONTROL.
It should be SQL, because APEX 5 demands an SQL query to populate the X_CONTROL.
I have set up a simple example here on apex.oracle.com:
Whenever a Department is selected (item P32_DEPTNO), its Location is copied into the second item (P32_LOC).
This is done by a dynamic action on P32_DEPTNO defined as follows:
Event: Change
Selection Type: Item(s)
Item(s): P32_DEPTNO
TRUE Action:
Action: Set Value
Set Type: SQL Statement
SQL Statement:
select loc
from dept
where deptno = :P32_DEPTNO
Items to Submit: P32_DEPTNO

How to get a Apex report (IR) column value in javascript function?

Using Apex 4.2.1
Actually I have a Apex (IR) report and want to create a javascript function where user can see message if two report columns date are not matched. for example, in report I have column date1 and date2 so date1 can not be less than date2. so I have create a link and when click on link then popop window should comeup (javascript) message box where function compare those two dates. so i m struggling how to get report column values in javascript function.
Thx.
Instead of click-popup solution you could use the Highlight and Compute features of IR:
Add a computed column X representing a result of comparison to your report. Actions->Format->Compute, use DECODE or CASE expressions to return 1 when date1 is lesser than date2.
Highlight report rows with X=1. Actions->Format->Highlight, select a condition and a color.
Optionally hide the computed column. Actions->Select Columns.
Save report as default. Actions->Save Report->Save As Default Report Settings.
If you steel want to check column values by JS, use Dynamic Action for report region on After Refresh event. For example, next code goes through rows of IR based on DEPT table and alerts DNAME and LOC columns:
var $dnames = $( 'td[headers=DNAME]', this.triggeringElement );
$( 'td[headers=LOC]', this.triggeringElement ).each( function( indx, El ) {
alert( $( El ).html() + " - " + $dnames.eq( indx ).html( ) );
} )
As you can see, I use report column aliases to filter cells.