I have a table with column Account.
Return 2 value :
4
2
I tried to divide 2/4 using expression
=Fields!Accounts.Value/Previous(Fields!Accounts.Value)
Something is not work here. Please point out what was wrong with it. Many thanks
Related
I am working with data imported from a pdf file. There is an extra column in the Power Query import (Data.Column7), containing data that belongs in the adjacent columns on either side (Data.Column6 and Data.Column8). Columns 6 and 8 have null values in the cells where the data was pushed into Column 7. I would like to replace the null values in Columns 6 and 8 with the correct data from Column 7, leaving all other values Columns 6 and 8 as is.
After looking at the post here:
Power Query / Power BI - replacing null values with value from another column
and watching this video:
https://www.youtube.com/watch?v=ikzeQgdKA0Q
I tried the following formula:
= Table.ReplaceValue(#"Expanded Data",null, each _[Data.Column7] ,Replacer.ReplaceText,{"Data.Column6","Data.Column8"})
(Note, "Expanded Data" is the last step before this Replace Value step.)
I am not getting any kind of syntax error, but the Replace Value step isn't doing anything at all. My null values in Columns 6 and 8 have not been replaced with the correct data from Column 7.
Any insight into how to achieve replacement would be greatly appreciated. Thank you.
(I should mention, I am a new Power Query user, so please be detailed and assume I know nothing!)
I'm sure there must be some way to do this with the ReplaceValue function, but I think it might be easier to do the following:
1: Create a new column with definition NewData6= if[Data.Column6]=null then [Data.Column7] else [Data.Column6]
2: Do the same thing for 8 : NewData8= if[Data.Column8]=null then [Data.Column7] else [Data.Column8]
3: Delete Data.Column6/7/8
4: Rename the newly made columns if neccesary.
You can do these steps either in the advanced editor, or just use the create custom column button in the add column tab.
If the columns are of the text data type, then it might have empty strings instead of actual nulls.
Try replacing null with "" in your formula.
If I have a CSV file like this:
How can I read this with UTL_FILE package and load the values into one table which have columns: ItemIdentifier, SoldOnWeb, SoldInTheShop?
From my point of view, as CSV files can be edited with MS Excel, I'd suggest you to rearrange the file and uniform it. The way it is now, it contains different headings and - to make it worse - they don't "match" (the same column contains itemidentifier and soldintheshop values; the same goes for the next column).
Add yet another column which would explain what the "sold..." column represents. Finally, you'd have something like this:
itemidentifier amount location
-------------- ------ -------------
1 10 soldOnWeb
2 7 soldOnWeb
3 5 soldOnweb
1 7 soldInTheShop
2 3 soldInTheShop
Doing so, it is a simple task to insert every value where it belongs.
Otherwise, can it be done in PL/SQL? Probably. Will it be difficult? Probably, as you have to "remember" what you're selecting in each row and - according to that - insert values into appropriate columns in the table.
You know how it goes ... garbage in, garbage out.
The output of my sql select statement is a list of Customer ID in column A.
In column B i want to randomly assign each cust ID either bucket A or B to perform A/B testing.
How do I use rand to generate a or b in a new column in my select statement
You could use a solution like the one here:
Generating Random Number In Each Row In Oracle Query which was addressing issues with the use of dbms_random.value.
If you want to get a value that is either 0 or 1, then you can do that like this, assuming your customers are coming from a table named customers:
SELECT customer_id, FLOOR(dbms_random.value+0.5)
FROM customers
The random value is between 0 and 1 (including 0 and not including 1) so adding 0.5 and using floor means you will get half 0's and half 1's.
Notes on using dbms_random in Oracle 11g are available in their manual here: https://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_random.htm
You may need to initialize the seed to guarantee or improve randomness.
And if 0 and 1 are not appropriate, you could then wrap the FLOOR in a CASE or DECODE to turn the numbers 0 and 1 into the letters A and B.
I have a table with 3 columns a, b and c. I want to know how to update the value of third column with concatenate of two other columns in each row.
before update
A B c
-------------
1 4
2 5
3 6
after update
A B c
-------------
1 4 1_4
2 5 2_5
3 6 3_6
How can I do this in oracle?
Use the concatentation operator ||:
update mytable set
c = a || '_' || b
Or better, to avoid having to rerun this whenever rows are inserted or updated:
create view myview as
select *, a || '_' || b as c
from mytable
Firstly, you are violating the rules of normalization. You must re-think about the design. If you have the values in the table columns, then to get a computed value, all you need is a select statement to fetch the result the way you want. Storing computed values is generally a bad idea and considered a bad design.
Anyway,
Since you are on 11g, If you really want to have a computed column, then I would suggest a VIRTUAL COLUMN than manually updating the column. There is a lot of overhead involved with an UPDATE statement. Using a virtual column would reduce a lot of the overhead. Also, you would completely get rid of the manual effort and those lines of code to do the update. Oracle does the job for you.
Of course, you will use the same condition of concatenation in the virtual column clause.
Something like,
Column_c varchar2(50) GENERATED ALWAYS AS (column_a||'_'||column_b) VIRTUAL
Note : There are certain restrictions on its use. So please refer the documentation before implementing it. However, for the simple use case provided by OP, a virtual column is a straight fit.
Update I did a small test. There were few observations. Please read this question for a better understanding about how to implement my suggestion.
I have a simple report (1 Table with 2 small columns)
the report works fine but now I'm trying to repeat the table on the same page but I can't find an example on how to do this.
I also crosses only one question about this problem, so maybe I miss something obviously on how to solve this.
Could somebody please enlight me?
You can 'play' with (a single) Tablix details to simulate table repetition.
For example you can create 3 rows of details like this:
row 1: header
row 2: value
row 3: footer space
To obtain a result like this:
You can also use a different layout, for example:
row 1: label/value for column 1
row 2: label/value for column 2
row 3: footer space
If you have a very small table you can also set report columns to fill horizontal space.
This is the result (simulating table repetitions but you can also use a simple Tablix with standard header/details):
This is the result if you use columns and a simple Tablix with standard header/details: