How to concatenate two columns in oracle select query? - oracle19c

The following is the sample data of my table which I created it in Oracle 19c.
id
first_numbers
second_numbers
10
123
111
10
122
123
10
111
124
11
333
111
11
444
222
11
222
124
In above table some duplicate values are existed for each id, I want to remove the duplicate values for each id and I want the values of both columns to be shown in one column in the result query
The expected result which I want is:
id
concatenated_colums
10
123
10
111
10
122
10
124
11
333
11
111
11
222
11
124

Use a UNION statement:
SELECT id, first_numbers "concatenated_colums" FROM table
UNION
SELECT id, second_numbers "concatenated_colums" FROM table

Related

How to compare values by different dates in PowerBI

My problem is related with PowerBI report
It is example table, Real table contains 10000+ results
user
salary
date
1
123
14-10-2022
2
455
11-10-2022
3
333
13-10-2022
4
222
12-10-2022
5
111
10-10-2022
desired output:
user
salary
date
salary (date-1 day)
salary (date-3 days)
1
123
14-10-2022
333
455
2
455
11-10-2022
111
3
333
13-10-2022
222
111
4
222
12-10-2022
455
5
111
10-10-2022
How can I achieve it in PBI ?
I tried to merge tables but the dashboard was very slow after try like that.
I would do this in DAX, not Power Query.
Add a date dimension (search on this if you aren’t familiar with date dimensions), then create these DAX measures.
Salary (date-1 day) = CALCULATE( SUM(TABLE[salary]), DATEADD(DateDim[DateKey],-1,day) )
Salary (date-3 day) = CALCULATE( SUM(TABLE[salary]), DATEADD(DateDim[DateKey],-3,day) )

How to select data from a table based on multiple expressions?

I have a view by the name of info and it's structure and data sample is the following:
id
name
contacts
1
ali
1234
1
ali
122
2
john
133
2
john
144
2
john
122
3
mike
111
4
khan
444
5
jan
122
5
jan
155
So I am using the above view data in oracle apex report. I want to search data by id for example I search for id=1, it contains two values in contacts column one of the value which is 122 is also included in another records so the result should also contain all the other records which contain 122 in their contacts column.
The expected result which I want is:
id
name
contacts
1
ali
1234
1
ali
122
2
john
133
2
john
144
2
john
122
5
jan
122
5
jan
155
We can phrase your requirement as wanting to return any record with id = 1 or any record whose contacts overlap with the contacts of id = 1.
SELECT id, name, contacts
FROM yourTable
WHERE id = 1 OR
id IN (
SELECT id
FROM yourTable
WHERE contacts IN (SELECT contacts FROM yourTable WHERE id = 1)
)
ORDER BY id;
Demo

DISCOUNT with multiple criteria in Power BI

I have two tables are Data and Report.
Data Table: In the Data table, two columns are Item, Qty, and Order. The Item columns contain as a text & number and qty and number column stored as text and number.
The item column is repeated according to the order and the same item column contains two different qty according to the order column.
Report Table:
I have a unique item column.
Data and Report file looks like.
Data
ITEM QTY ORDER
123 200 1
123 210 0
5678 220 1
5678 230 0
5555 240 1
6666 250 1
9876 260 1
2345 270 1
901 280 1
901 280 1
902 300 1
902 300 1
123456 200 1
123456 200 1
123456 210 1
123456 210 1
123456 0 1
567 200 1
567 210 1
567 210 1
567 0 1
453 5000 1
453 5000 1
453 5000 1
453 5000 1
112 5000 1
112 5000 1
112 5000 1
112 5000 1
116 5000 1
116 5001 1
116 0 1
116 0 1
116 5000 0
116 5001 0
116 0 0
116 0 0
Report
ITEM DESIRED RESULT (QTY)
123 200
5678 220
5555 240
6666 250
9876 260
2345 270
901 280
902 300
123456 MIXED
567 MIXED
4444 NA
12 NA
10 NA
453 5000
112 5000
116 MIXED
Expand snippet
Desired Result
I would like to pull the qty against the order “1” from the data table into the report table according to the item.
If the item is found in the data table then return the qty in the report table according to the item. {Please refer to the “Data” and “Report table for item 123 and 5678 etc….}
If an item is not found in the data table then return “NA” in the report table according to the item. {Please refer to the “Data” and “Report table for item 10, 12,444}
The same item contains two different qty then returns as a text “Mixed” in the report table according to the item. {Please refer to the “Data” and “Report table for item 123456,116 & 567}
Currently I am using the following calculated column CURRENT DAX FOR QTY = LOOKUPVALUE(DATA[QTY],DATA[ITEM],'DESIRED RESULT'[ITEM],DATA[ORDER],1,"NA") enter image description here
It’s almost working fine but it’s giving the wrong result “NA” were two different qty for the same item & two different order (0,1) or (1) or (o) {Please refer to the “Data” and “Report table for item 123456, 116 & 567} but the desired result is “Mixed” those three items.
Note: I convert the qty column from number to text otherwise it gives an error, is there any alternative option to achieve my result.
Herewith attached the PBI file for your reference https://www.dropbox.com/s/hf40q27pvn3ij2g/DAX-LOOKUPVALUE%20FILTER%20BY.pbix?dl=0.
If I'm understanding correctly, this can be done with the method I suggested previously with the addition of a filter for DATA[ORDER] = 1.
IF (
CALCULATE ( DISTINCTCOUNT ( DATA[QTY] ), DATA[ORDER] = 1 ) > 1,
"MIXED",
CALCULATE ( SELECTEDVALUE ( DATA[QTY], "NA" ), DATA[ORDER] = 1 )
)

How to sum by group in Power Query Editor?

My table look like this :
Serial WO# Value Indicator
A 333 10 333-1
A 333 4 333-2
B 456 5 456-1
A 334 1 334-1
A 334 5 334-2
I want to create a new column that sums up the Values based on WO#. It should look like this:
Serial WO# Value Indicator SumValue
A 333 10 333-1 14
A 333 4 333-2 14
B 456 5 456-1 5
A 334 1 334-1 6
A 334 5 334-2 6
Eventually I will remove duplicates on the WO# and remove the Value and Indicator Columns from the data. I can't seem to find a function in M that allows for sum by group. Thanks in advance!
If you load the data with Power Query, there is a Group command on the ribbon that will do just that.
Make sure to use the Advanced option and add all columns you want to retain to the grouping section. Screenshot from Excel ....
.... and from Power BI

Reshape/pivot pandas dataframe

I have a dataframe with variables: id, 2001a, 2001b, 2002a, 2002b, 2003a, 2003b, etc.
I am trying to figure out a way to pivot the data so the variables are: id, year, a, b
The 16.2 documentation refers to some reshaping and pivoting, but that seemed to speak more towards hierarchical columns.
Any suggestions?
I am thinking about creating a hierarchical dataframe, but am not sure how to map the year in the original variable names to a created hierarchical column
sample df:
id 2001a 2001b 2002a 2002b 2003a etc.
1 242 235 5735 23 1521
2 124 168 135 1361 1
3 436 754 1 24 5124
etc.
Here is a way to create hierarchical columns.
df = pd.DataFrame({'2001a': [242,124,236],
'2001b':[242,124,236],
'2002a': [242,124,236],
'2002b': [242,124,236],
'2003a': [242,124,236]})
df.columns = df.columns.str.split('(\d+)', expand=True)
df
2001 2002 2003
a b a b a
0 242 242 242 242 242
1 124 124 124 124 124
2 236 236 236 236 236