How can I turn in data of one single column in to useful information? - sql-update

I had one column of table1 with different activities : process poultry, process meat, export, ....
I want to create another table with 3 column to know how many process poultry, press meat, export in that specific column of table 1.
So far I create a table but don't know what I should do next from this. Please help me
CREATE TABLE meat_activities_type
(
poultry_processing boolean,
meat_processing boolean,
export_certification boolean
);
UPDATE
CREATE TABLE meat_activities_type
(
poultry_processing boolean,
meat_processing boolean,
export_certification boolean
);
UPDATE

Related

Using cte to swap two columns of a table

I want to swap 2nd and 3rd column of one table using CTE.
I'm working with below query, which keeps throwing an error,
no such column: cte.comm1
Table - [SalComm] column: ID, Sal, Comm
with CTE as
(
SELECT ID as id1, sal as sal1, comm as comm1 from SalComm
) UPDATE SalComm SET sal=cte.comm1, comm=cte.sal1 where ID= cte.id1*
Could you please suggest to me the right query?
This answer assumes you are using SQL Server, or some other database, which supports directly updating common table expressions. I don't see the point at all of the aliases inside your CTE. If you want to swap columns values, just use the direct columns names:
WITH cte AS (
SELECT ID, sal, comm
FROM SalComm
)
UPDATE cte
SET sal = comm, comm = sal;
-- no WHERE clause needed, if you really want to cover the entire table
That being said, you could just as easily do the above update on the original table. Updatable CTEs are more useful when they generate some complex derived results which you intend to use as part of a later update. That does not appear to be the case here.

Treatas DAX function not working as expected, It is returning complete blank column

I trying to understand Treatas DAX function. There are two tables Assets and Ticket. Ticket table has parent and child relationship. For each value of Asset[AssetKey], I want to calculate count of childs in Ticket table. There is two relationships between these tables. One active and one inactive.
The Problem: When I use Treatas function complete measure Number of Child is retured blank. I used the formula -
Number of Child = CALCULATE(COUNT(Tickets[AssetKey]),TREATAS(SUMMARIZE(Asset,Asset[AssetKey]),Tickets[ParentId]))
To replicate the scenario follow the below steps:
Step 1: create table Asset:
Asset = DATATABLE("AssetKey",INTEGER,"Name",STRING,{{1,"Australia"},
{2,"Belgium"},
{3,"Canada"},
{4,"Denmark"},
{5,"England"}})
Create table Ticket
Tickets = DATATABLE("AssetKey",INTEGER,"ParentId",INTEGER,"TicketKey",INTEGER,{{3,1,1},
{1,Blank(),1},
{3,1,3},
{2,Blank(),4},
{4,2,5},
{3,1,6},
{2,Blank(),7},
{4,2,8},
{1,Blank(),9},
{5,2,10}})
Step2 : create relationship between Assets and Ticket table(one to many) on column AssetKey.
Step3: Now create the below Measures -
Number Of Tickets = COUNT(Tickets[TicketKey])
Number of Child = CALCULATE(COUNT(Tickets[AssetKey]),TREATAS(SUMMARIZE(Asset,Asset[AssetKey]),Tickets[ParentId]))
Now the problem: Why the Number of Child column comes out to be blank.
The expected output is :
Your problem is not the TREATAS but the SUMMARIZE. TREATAS expects table input so you summarized.
Try the following:
summarizedAsset = SUMMARIZE(Asset,Asset[AssetKey])
This returns you 1,2,3,4,5. Logic because this is what you asked it to do. Now TREATAS is going to do the same on the table Ticket. So it returns a table with one column values "empty",1,2. Exactly what we can expect.
Next thing you do a COUNT on AssetKey, this table just created does not have this column so it returns empty.
What you are looking for is a column what is calculating the children:
Number of Child =
var Akey = Asset[AssetKey]
return CALCULATE(COUNT(Tickets[ParentId]), filter(Tickets, Akey = Tickets[ParentId]))
This returns exactly what you where looking for.
PS: 10 points, you did an excellent job on the question asking, easy for others to reproduce. You work as a pro!!

How to substitute NULL with value in Power BI when joining one to many

In my model I have table AssignedToUser that don't contain any NULL values.
Table TotalCounts contains number of tasks for each User.
Those two table joined on UserGUID, and table TotalCounts contains NULL value for UserGUID.
When I drop everything in one table there is NULL value for AssignedToUser.
How can I substitute value NULL for AssignedToUser for "POOL".
Under EditQuery I tried to Create additional column
if [AssignedToUser] = null then "POOL" else [AssignedToUser]
But that didnt help.
UPDATE:
Thanks Alexis.
I have created FullAssignedToUsers table, but when I try to make a relationship with TotalCounts on UserGUID - it doesnt like it.
Data in new a table looks like this:
UPDATE:
File .ipbx can be accessed here:
https://www.dropbox.com/s/95frggpaq6tce7q/User%20Open%20Closed%20Tasks%20Experiment.pbix?dl=0
I believe the problem here is that your join has UserGUID values that are not in your AssignedToUsers table.
To correct this, one possibility is to replace your AssignedToUsers table with one that contains all the UserGUID values from the TotalCounts table.
FullAssignedToUsers =
ADDCOLUMNS(VALUES(TotalCounts[UserGUID]),
"AssignedToUser",
LOOKUPVALUE(AssignedToUsers[AssignedToUser],
AssignedToUsers[UserGUID], TotalCounts[UserGUID]))
The should get you the full outer join. You can then create the custom column like you described in the table and use that column in your visual.
You'll probably want to break the relationships with the original AssignedToUsers table and create relationships with the new one instead.
If you don't want to take that extra step, you can do an ISBLANK inside your new table formula.
FullAssignedToUsers =
ADDCOLUMNS(VALUES(TotalCounts[UserGUID]),
"AssignedToUser",
IF(
ISBLANK(
LOOKUPVALUE(AssignedToUsers[AssignedToUser],
AssignedToUsers[UserGUID], TotalCounts[UserGUID])),
"POOL",
LOOKUPVALUE(AssignedToUsers[AssignedToUser],
AssignedToUsers[UserGUID], TotalCounts[UserGUID])))
Note: This is equivalent to doing a right outer join merge on the AssignedToUsers table in the query editor and then replacing the nulls with "POOL". I'd actually recommend approaching it that way instead.
Another way to approach it is to pull the AssignedToUser column over to the TotalCounts table in a custom column and use that column in your visual instead.
AssignedToUsers =
IF(ISBLANK(RELATED(AssignedToUsers[AssignedToUser])),
"POOL",
RELATED(AssignedToUsers[AssignedToUser]))
This is equivalent to doing a left outer join merge on the TotalCounts table in the query editor, expanding the AssignedToUser column, then replacing nulls with "POOL" in that column.
In Dax missing values are Blank() not null. Try this:
=IF(
ISBLANK(AssignedToUsers[AssignedToUser]),
"Pool",
AssignedToUsers[AssignedToUser]
)

Informatica : something like CDC without adding any column in target table

I have a source table named A in oracle.
Initially Table A is loaded(copied) into table B
next I operate DML on Table A like Insert , Delete , Update .
How do we reflect it in table B ?
without creating any extra column in target table.
Time stamp for the row is not available.
I have to compare the rows in source and target
eg : if a row is deleted in source then it should be deleted in target.
if a row is updated then update in target and if not available in source then insert it in the target .
Please help !!
Take A and B as source.
Do a full outer join using a joiner (or if both tables are in the same databse, you can join in Source Qualifier)
In a expression create a flag based on the following scenarios.
A key fields are null => flag='Delete',
B key fields are null => flag='Insert',
Both A and B key fields are present - Compare non-key fields of A and B, if any of the fields are not equal set flag to 'Update' else 'No Change'
Now you can send the records to target(B) after applying the appropriate function using Update Strategy
If you do not want to retain the operations done in target table (as no extra column is allowed), the fastest way would simply be -
1) Truncate B
2) Insert A into B

vaadin: moving data from selected row of table1 to table2

I have two questions:
I have two tables, table1 and table2. I need to design an application in such a way that a selected row of table 1 when clicked should get displayed in table 2.
How do I call a custom table? Suppose I have a class Table with empty constructor and I will pass arguments like Table(pagination). It has to show the table with pagination,
Similarly, Table(lazyloading) has to show lazy loading table. Table(pagination, Lazy loading,search) must show all three properties.
What you have to do for nr 1 is that you attach a Clicklistener to your table1 and on a Clickevent you take the selected Object ni table1 and add it to table2. Also add an if to not add rows that already exist in table 2.
This is how you copy data
public void copydata(){
Object o = table1.getValue();
if(!table2.getItemIds().contains(o))
table2.addItem(o);
table2.setContainerDataSource(table2.getContainerDataSource());
}
When it comes to your second question I have no clue what you are talking about, but I looks like you want to extend the Table class in vaadin to get your own features.