I am looking to extract the numbers of hours in a column TXT however PQ is unable to find a pattern due to the inconsistency in the structure of text. I have used Columns by Example but hasnt helped.
Is there a M code or combination of M code I can use?
Sample data:
TXT
Contract Staff w/e 26.06.21- Carer 9.5hrs- MNL
Contract staff w/e02.07.21 - Physio- 19.34hrs- ARK
Contract Staff w/e 04.07.21 - RN 13.25- MNL
Contract Staff w/ e 04.07.21 - carer 6- MNL
Contract Staff w/e25.06.21 - carer 12.5 - KLTL
Contract Staff w/e04.07.21 - RN 34hrs- KLTL
Contract Staff w/e04.07.21 - AIN 25.5hrs- KLTL
Contract Staff w/e26.06.21- Carer - 6hrs- MNL
Contract Staff w/e11.07.21 - 6hrs- MNL
Contract Staff wie 24.06.21 - Carer 8hrs - ARK
Contract Staff w/e 16.06.21 - EN 5.50- GL
Contract Staff w/e 16.06.21 - RN 5.25- GL
Contract Staff w/e 11.07.21 - RN 22hrs- MNL
Contract Staff w/e 11.07.21 - carer 27.75- MNL
Contract Staff w/e04.07.21 - RN 22.25hrs- KLTL
Contract Staff w/e04.07.21 - AIN 69.67 - KLTL
Contract Staff w/e04.07.21 - RN 5.75- KLTL
Contract Staff w/e10.07.21 - RN 16hrs- KLTL
Contract Staff w/e10.07.21- Carer 6hrs- KLTL
Contract Staff w/e11.07.21 - AIN 38.50- KLTL
Contract Staff w/e18.07.21 - RN 46-KLTL
Contract Staff w/e18.07.21 - AIN 17 -KLTL
Contract Staff w/e18.07.21 - Cleaner 24.50 -KLTL
Contract Staff w/e18.07.21 - AIN 19.5- MNL
contract staff w/16.07.21 - RN23.25hrs - MNL
contract staff WIE 25.07.21 - carer - 42.25hrs- MNL
contract staff w/E 18.07.21 - AIN 24.5 - KLTL
contract staff WIE 18.07.21 - Domestic 6- KLTL
Contract Staff w/e 13.07.21 - RN 6.25hrs- KLTL
Contract Staff w/e25.07.21 - RN 19.5- KLTL
Contract Staff w/e25.07.21 - AIN 13.5- KLTL
Contract Staff w/e18.07.21 - AIN 6hrs- ARK
You don't need regex for this:
Add column, extracting text after "-"
Remove all letters and remaining "-"
Convert text to number
#"Inserted Text After Delimiter" = Table.AddColumn(
Source,
"hours",
each Text.AfterDelimiter([TXT], "-"), type text
),
#"Remove Letters" = Table.TransformColumns(
#"Inserted Text After Delimiter",
{{"hours", each Text.Remove(_, {"A".."z", "-"})}}
),
#"Changed Type to number" = Table.TransformColumnTypes(
#"Remove Letters",
{{"hours", type number}}
)
Related
I have the following table, which shows how many MH(Mental Health type) and/or SA (Substance Abuse type) diagnosis for a particular client:
For, example - Client with the ClientID = 22 has 2 diagnosis category (MH and SA); while ClientID = 23 has only 1 diagnosis category (SA)
Diagnosis:
Client_ID Diagnosis_Desc Diagnosis_Cat
22 Bi-Polar MH
22 Alcohol SA
23 Cocaine SA
24 Scizophrenia MH
24 Alcohol SA
25 Nicotine SA
25 PTSD MH
25 Stress MH
I also have measure, which calculates number of Diagnosis_Cat (Diagnosis category) per client:
So, if I populate my data with [# Category per Client] measure, it'll look as:
Client_ID Diagnosis_Desc Diagnosis_Cat [# Category per Client]
22 Bi-Polar MH 2
22 Alcohol SA 2
23 Cocaine SA 1
24 Scizophrenia MH 2
24 Alcohol SA 2
25 Nicotine SA 2
25 PTSD MH 2
25 Stress MH 2
My goal is to create a Cross Matrix table, where
X = SA diagnosis,
Y = MH diagnosis,
value = # of Clients that have SA-MH diagnosis pair (crossed pair).
This is the measure for my value:
# Dual Diagnosed Clients = CALCULATE(
DISTINCTCOUNT('Diagnosis'[ClientID]),
FILTER(
'Diagnosis',
'Diagnosis'[# Category per Client] = 2
)
)
I also created 2 tables with MH and SA unduplicated data and throwing them into my Matrix - Attrib_1 and Attrib_2
So, the visual looks like (shows total # of unduplicated, dually diagnosed (MH-SA) clients)-
While I expected to see in this cross-matrix -
Alcohol-Bi-Polar = 1 Client (ClientID 22);
Alcohol-PTSD = 0 Clients (or just an empty cell)
Alcohol-Scizophrenia = 1 Client (ClientID 24), etc.
Plz, help to adjust my measure.
Our Employee benefits have 5 Plan_Types, I need to put all the data into a view that looks like this:
`EMPLID YEAR SK PB VTO BV CT VC
-----------------------------------------------------
0199990 2017 23 22 5 0 169
0000004 2018 22 0 2 5 65
0199990 2017 5 34 34 0 55
0000004 2018 23 0 19 5 0
----------------------------------------------------
`
Here is the SQL for the above pivot table
`SELECT * FROM (SELECT b.emplid,
b.empl_rcd,
EXTRACT (YEAR FROM B.ACCRUAL_PROC_DT)
AS year,
DECODE (b.plan_type,
'50', 'SK',
'52', 'PB',
'5V', 'VTO',
'5Y', 'BV',
'5Z', 'CT',
'51', 'VC')
BANK,
B.HRS_CARRYOVER
+ B.HRS_EARNED_YTD
- B.HRS_TAKEN_YTD
+ B.HRS_ADJUST_YTD
+ B.HRS_BOUGHT_YTD
- B.HRS_SOLD_YTD
- B.HRS_TAKEN_UNPROC
+ B.HRS_ADJUST_UNPROC
+ B.HRS_BOUGHT_UNPROC
- B.HRS_SOLD_UNPROC
BALANCE
FROM ps_leave_accrual b)
PIVOT (SUM (balance) AS bal
FOR (bank)
IN ('SK', 'PB', 'VTO', 'BV', 'CT', 'VC'))
WHERE emplid in ('0199990','0000004');`
How do I turn this into a view I can use in PS Query. If I put this code into the view SQL, It fails at the Pivot point - "SQL command not properly ended "
To use non-standard code in views, we have different options:
We create the record definition and in the SQL we put the SQL, but comment it out, and reference our migration package information. When we build, we build manually as part of the migration process. I've seen folks use DMS to build the views.
We can create a SQL Object and reference it in the view sql using %SQL(M_CUSTOM_VIEW_SQL), that way the code is migrated with the project.
So, I'm really having a hard time with a report.
I need a report grouped by year. For example, we want to show how many cars are sold per year. So, the report has a column Year, the type/model of the car, and the quantity. However, I also want to show a row with null/zero value, so even when no car of a specific type was sold, I want it to show the row, but with 0.
The problem is, this query is based on a lot of views, which shows each transaction. So, my actual query works fine except it doesn't show a type when none of that type was sold in a year.
When I pivot this report using Oracle APEX, it almost works. It shows all the types, but if I filter per year, then they are gone.
I have all the years I need, but I don't have the data for that year. I take all the data from multiple views with the specifics of the sales. Some of the models/types were not sold in some years, so when I query the report, it doesn't show up, which is expected. For example:
What I get is
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
What I want
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2018 - MODEL 3 - 0
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
Any ideas?
You can conjure rows, and outer join to them.
with years as (
select add_months(date '1980-1-1', (rownum-1)*12) dt
from dual
connect by level < 5
)
select y.dt, count(e.hiredate)
from scott.emp e
right outer join years y
on y.dt = trunc(e.hiredate,'yy')
group by y.dt
DT COUNT(E.HIREDATE)
------------------- -----------------
01-01-1982 00:00:00 1
01-01-1983 00:00:00 0
01-01-1981 00:00:00 10
01-01-1980 00:00:00 1
I have rollup output of month-wise average sales of products in a quarter as shown below:
Rollup output:
Product Month Sales
------------------------------
Product1 MAY 101.27
Product2 MAY 5.47
Product1 JUN 1481.19
Product2 JUN 84.95
ALL QTR 836.44
I need final output in the following format:
Product1 Product2 AverageSales
May 101.27 1481.19 (null)
Jun 5.47 84.95 (null)
Jul 0 0 (null)
ALL (null) (null) 836.44
I tried to apply pivot on month but since month name is a dynamic value based on the quarter selected, I tried to pivot on the product:
select * from (rollup output)
PIVOT MIN(Sales) FOR Product IN ('Product1' AS Product1_sales, 'Product2' AS Product2_sales, 'ALL' AS Average Sales');
I received the following output:
MONTH Product1_sales Product2_sales Average Sales
MAY 5.47 (null) (null)
MAY (null) 101.27 (null)
JUN 84.95 (null) (null)
JUN (null) 1481.19 (null)
Qtr (null) (null) 836.44
However, I need data in the final format mentioned above. How can I achieve this?
Also, if data for a given month of the quarter is not available, I want to display its value as 0 (also shown in the final format above). How can I achieve that, considering that month name is dynamic?
Edit: I can pivot using product as well since I do not want xml output that comes out of dynamic pivot.
I'm not sure why it needs to be dynamic since the number of months is unlikely to change. Why not just:
select product
, nvl(jan,0) as jan
, nvl(feb,0) as feb
, nvl(mar,0) as mar
, nvl(apr,0) as apr
, nvl(may,0) as may
, nvl(jun,0) as jun
, nvl(jul,0) as jul
, nvl(aug,0) as aug
, nvl(sep,0) as sep
, nvl(oct,0) as oct
, nvl(nov,0) as nov
, nvl(dec,0) as dec
from rollup_output
pivot (min(sales) for (month) in
( 'JAN' as jan, 'FEB' as feb, 'MAR' as mar, 'APR' as apr, 'MAY' as may, 'JUN' as jun
, 'JUL' as jul, 'AUG' as aug, 'SEP' as sep, 'OCT' as oct, 'NOV' as nov, 'DEC' as dec)
);
SQL Fiddle
I have a table with columns :
Table Name: IdentityTable
ID Dest_Name Dest_Reference_Id Format IG
31231231 India Delhi XKHYGUI 21
12313131 USA Washington XHKOWKG 1
34645542 India Mumbai XKLWOFH 1
31231314 USA California XLGJDJG 21
31234531 India Delhi XKHIHUI 21
12375671 USA Washington XHKLHKG 21
12574613 USA Washington XLKWMKG 1
and so on...
I want to query this table to retrieve information in this form:
Dest_Name Dest_Reference_Id Total_Format Format IG
India Delhi 2 XKHYGUI 21
India Delhi 2 XKHIHUI 21
USA Washington 3 XHKOWKG 1
USA Washington 3 XHKLHKG 21
USA Washington 3 XLKWMKG 1
India Mumbai 1 XKLWOFH 1
USA California 1 XLGJDJG 21
I did:
select dest_name, dest_reference_id, count (format)
from IdentityTable
Group By dest_name, dest_reference_id;
I could retrieve all information required except Format column in the result. How should I modify my query to return expected result ?
Make two sub-queries and join em up.
SELECT counts.dest_name,
counts.dest_reference_id,
counts.total_format,
idents.format,
idents.IG
FROM
(
select dest_name, dest_reference_id, count (format) as total_format
from IdentityTable
Group By dest_name, dest_reference_id;
) counts
join
(
select distinct dest_name, dest_reference_id, format, IG
from identitytable
) idents
on counts.dest_name = idents.dest_name
and counts.dest_reference_id = idents.dest_reference_id
count(*) over(partition by dest_name, dest_reference_id)
and without a group by. google "oracle analytic functions".