Date Format Conversion In Apex - oracle-apex

I have a date item ' Order_TCD' in the form.
My requirement is when user enters Order_TCD it should be in the format:
DD-MON-YYYY HH:MIPM,
But the data in the report should appear in the format DD-MON-YY.

DD-MON-YYYY HH:MIPM
If Order_TCD is DATE data type, then while inserting the row you need to use TO_DATE and required format mask. You must specify the user to enter the date in the format DD-MON-YYYY HH:MIPM. And you need to handle it as:
TO_DATE('05-MAY-2015 11:05AM','DD-MON-YYYY HH:MIPM')
But the data in the report should appear in the format DD-MON-YY.
To display the date in your desired format, you need to use TO_CHAR.
For example,
TO_CHAR(Order_TCD, 'DD-MON-YY')

To set the format mask on the (datepicker!) item, simply edit the item and go to the "Settings" section. You can enter the format mask there.
To display with another format mask in the report, you can set the format mask in the column attributes. Example here for an interactive report.
You could also apply the mask on the column in the source SQL of course. Also note that you can set a global application date format mask in the globalization options of the application.

Related

Oracle Apex 22.21 - Chart Page - Bar Type - Datepicker

I have a table ORDERS which contains column ORDER_DATE. I have created a Chart as a Bar type. I want the chart to show the amount of orders in a given date or range.
I'm following this Youtube tutorial which shows how to create a datepicker that returns a range in a Report. I'm trying to replicate this in a chart.
What I've done so far
Created datepicker items P5_DATE_FROM and P5_DATE_TO
Changed the Series Source Type to SQL Query
select ORDER_ID,
ORDER_NUMBER,
TO_CHAR(ORDER_DATE, 'YYYY-MM-DD') AS ORDERDATE,
STORE_ID,
FULL_NAME,
EMAIL,
CITY,
STATE,
ZIP_CODE,
CREDIT_CARD,
ORDER_ITEMS,
APEX$SYNC_STEP_STATIC_ID,
APEX$ROW_SYNC_TIMESTAMP
from ORDERS_LOCAL
where TO_CHAR(ORDER_DATE, 'YYYY-MM-DD') between :P5_DATE_FROM and :P5_DATE_TO
Source Page Items to Submit added P5_DATE_FROM,P5_DATE_TO
I basically followed the exact steps of the video. However, since the video is for a report and mine is for a chart, the chart isn't actually returning any data.
I think this is because for charts there are additional fields I need to configure. I noticed the video didn't cover Column Mapping and I'm a bit confused to what to enter here.
----------------UPDATE-------------
I've followed Koen's instructions from his answer. It seems like to TO_CHAR function was causing the error. I've updated the SQL Query to below:
select ORDER_ID,
ORDER_NUMBER,
ORDER_DATE,
STORE_ID,
FULL_NAME,
EMAIL,
CITY,
STATE,
ZIP_CODE,
CREDIT_CARD,
ORDER_ITEMS,
APEX$SYNC_STEP_STATIC_ID,
APEX$ROW_SYNC_TIMESTAMP
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P5_DATE_FROM,'YYYY-MM-DD') and TO_DATE(:P5_DATE_TO,'YYYY-MM-DD')
However, on the Page Designer I cannot save and run page until I select Column Mapping - Label and Value. I've set the Label as ORDER_DATE but I am unsure of what to select for the Value.
Setting the Value to ORDER_DATE shows an error Ajax call returned server error ORA-01403: no data found for CHART Count Orders by Date.
and selecting any other Value such as ORDER_NUMBER or ZIP_CODE populates the chart with the actual integer value of the column (ex: ZIP_CODE returns a chart of x-axis: date, y-axis: actual zip code numbers)
I see 2 possible issues.
You submit P5_DATE_FROM and P5_DATE_TO but the source has P1_DATE_FROM and P1_DATE_TO - not sure that is a typo but it should all be the same...
The where clause is wrong. This
from ORDERS_LOCAL
where TO_CHAR(ORDER_DATE, 'MM-DD-YYYY') between :P1_DATE_FROM and :P1_DATE_TO
should be
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P1_DATE_FROM,'MM-DD-YYYY') and TO_DATE(:P1_DATE_TO,'MM-DD-YYYY')
Reason: the column orders_local.order_date is of datatype DATE. If you convert it to a string using TO_CHAR then it will be a string comparison, not a date comparison.
Note that bind variables P1_DATE_FROM and P1_DATE_TO are strings - they're defined in the DOM on the html page and that has no concept of oracle datatypes so everything is just a string. If they're used as such in a date comparison, you're relying on implicit conversion by the database. It's safer to do explicit conversion using the TO_DATE function.
--UPDATE--
Your question starts with "I want the chart to show the amount of orders in a given date or range.". Well... there is your answer. The "Value" is the amount of orders on each day. Update your source query to include a count of the orders and group by day. Then make your value attribute the column that has the count.

How to conditionally format text in PowerBi

Is there a way to conditionally format my table so I can add a bar like below? (it was created in excel)
Image I want to create:
I am currently stuck with the following - I highlighted the dates but need to know how I can highlight the holidays in my table with that grey color. (the picture below uses Thanksgiving as the example). My goal is to highlight each individual holiday in the table in grey.
Image I need to conditionally format
Here is what I tried with the formula provided below:
Attempt
You need a date dimension that has an attribute like isHoliday.
Create a measure where you specify the color in the Hex Code format ("#A1A1A1")
for instance:
measure_color_coding_holiday = SWITCH ( TRUE (), 'Date'[IsHoliday] = "yes", "#808080", 'Date'[IsHoliday] = "No", "#FFFFFF" )
Go to the conditional formatting for the column > Background Color. Choose Field value and pick the new measure.
/Tom

Oracle apex grid calculations to_number hampering DA

I have another requirement where the grid query is:
select to_char(kpi_1,'999,999,999,999.99'), to_char(kpi_2,'999,999,999,999.99'), to_char(kpi_3,'999,999,999,999.99') from kpi;
The KPI_1,KPI_2,KPI_3 columns are float in database but on grid they need to be represented in comma separated format. Therefor to_char is used.
And in processing they are changed back to to_number format to store in database.
Now i need to add dynamic action that would be kpi_2-kpi_1 = kpi_3.
So when i use dynamic action, set value: KPI_2-KPI_1, nothing happens.
Also when i use: to_number(kpi_2,'999,999,999,999.99') - to_number(kpi_1,'999,999,999,999.99')
For values input there/existing data, there is no change in kpi_3 column which should have been calculated.
What am i doing wrong here?
Try to return to_number(kpi_2,'999,999,999,999.99') -to_number(kpi_1,'999,999,999,999.99') value using debug or in plsql raise_applicaiton_error.
if value return then try to set value using set value dynamic action.

How to write a query based on the Date item, in interactive grid

I have a date field and a interactive grid. I am trying to generate the Interactive grid based on the value inputted in the date field.
I am trying to write the query as below :
select pap.effective_start_date , pap.effective_end_date
from per_all_people_f pap
where :SELECT_DATE between pap.effective_start_date and
pap.effective_end_date
Here, SELECT_DATE is the name of the Date field (datatype Date picker). I am writing a dynamic action on Change of Date field, and refreshing the interactive grid region.
But when I change the value in Date field, it doesn't return any rows.
I have done a similar change where my interactive grid was based on a dropdown. There I had to set the "page action on selection" to Submit, and it worked. But here, since it is a Date field, the "Page Action on selection" property doesn't appear on the page .
Can somebody please suggest, how can I achieve this.
You need to explicitly convert your bind variables, which are treated as strings, to dates.
to_date(:SELECT_DATE)
The format mask will come from the application properties, or you can be explicit with that, too.

DAX - how to convert a date string from another locale into a date type

I have a date string that fails to import because it is in a different format to that expected my the machines locale (i.e. US dates to a UK machine).
How do I tell DAX to convert this string into a date, but using a specified format or locale, different to the machines default.
For example, I would like to import
3/27/2008 11:07:31 AM
as
27/3/2008 11:07:31 AM
You have two options.
First option, use the basic Formatting tab functionality in Power BI.
Select the column and use the below settings in the Formatting tab:
Second option (recommended), use PowerQuery to import the text column in datetime data type.
The following expression will split the text by "/" character, then will convert dd/mm/yyyy string to the datetime data type.
Table.AddColumn(#"Changed Type", "DateTime",
each Text.Split([#"#(001A)Date Import"],"/"){1} & "/"
& Text.Split([#"#(001A)Date Import"],"/"){0} & "/" &
Text.Split([#"# (001A)Date Import"],"/"){2})
In this case I've added an additional column in order to import the column in the required datetime type, you can apply the changes to the same column though.
Date import column is the actual text column, DateTime is the column I've added to import Date Importas Datetime type.
If you get stuck check the official documentation about PowerQuery.
Let me know if this helps.
I think the most practical solution is in the Query Editor, but complex formula are not required.
I would Right-click the column and choose Change Type / Using Locale. Then I would specify Data Type = Date and Locale = English (United States).