Moving CiviCRM custom fields to different Contact type - import

I would like to take a set of custom fields in CiviCRM which are attached to one Contact type (Individual), and move them to be attached to another Contact type (Organization). The fields are similar, but they are not all identical.
What is the best way of handling this? Export the custom fields and clean up the CSV before importing into the newly created custom fields?

The most efficient way would be straight through SQL:
INSERT INTO civicrm_value_org_stuff
SELECT null as id, c.current_employer_id as entity_id, i.first_field as first_org_field, i.second_field as second_org_field ...
FROM civicrm_value_ind_stuff i
LEFT JOIN civicrm_contact c ON c.id = i.entity_id
LEFT JOIN civicrm_value_org_stuff o ON c.current_employer_id = o.entity_id
WHERE o.id is null AND c.current_employer_id is not null
You'll have to take care of situations where there's already information in the destination table, but otherwise this should work fine. The table names are obviously made up, but they'll begin with "civicrm_value..." and the field names should be clear from that.

Related

data merging in Tableau

I have two sheets in excel. One has CBG (neighborhood) IDs as shown below.
The second sheet has state and county names and IDs as shown below.
Now the first 5 digits in the CBG ID are just the corresponding state and county IDs for that CBG.
I need to to join this data together in Tableau so that I would have the state and county on the CBG sheet for each CBG.
Basically I tried to blend the data and it didn't work. I also tried to perform a join calculation using the 5-digit code in the second sheet and the LEFT function to extract the 5-digits in the CBG code but it didn't seem to work either.
To fix it, just needed to fix the Join calculation on both sides of the join.
Also, it seems that both variables to be joined need to be the same data type.
The data that you analyze in Tableau is often made up of a collection of tables that are related by specific fields (that is, columns). Joining is a method for combining the related data on those common fields. The result of combining data using a join is a virtual table that is typically extended horizontally by adding columns of data.
When joining tables, the fields that you join on must have the same data type. If you change the data type after you join the tables, the join will break.
Please go through the below steps for joining tables:
In Tableau Desktop: on the start page, under Connect, click a connector to connect to your data. This step creates the first connection in the Tableau data source.
In web authoring: Select New Workbook and connect to your data. This step creates the first connection in the Tableau data source.
Select the file, database, or schema, and then double-click or drag a table to the canvas.
Double-click or drag another table to the canvas, and then click the join relationship to add join clauses and select your join type.
Add one or more join clauses by selecting a field from one of the available tables used in the data source, a join operator, and a field from the added table. Inspect the join clause to make sure it reflects how you want to connect the tables.
When you are finished, close the Join dialog.
Thank you.

Tableau Union Joins - Can you un-merge automatically merged fields?

I am attempting to union join 2 tables in my Microsoft NAV data source within Tableau. However, I have two field named "No." that do not contain the same data.
When I apply a union join, Tableau automatically merges these fields and I cannot un-merge them.
Is there a way to un-merge these fields?
Or is there a way of doing a manual union join?
I have tried renaming the field before dragging the second table into the worksheet however I can see that the "Remote Field Name" still remains the same.
Thanks
One approach is to let Tableau merge the fields and then use the generated fields to distinguish between them.
When you perform a Union in Tableau, it adds a few fields to your data source so you can tell which data rows came from which tables. The most useful in your case is called [Table Name]. So when you build your visualizations, you can use the [Table Name] field to know how to interpret the [No.] field.
If that is awkward, you can create 2 calculated fields to represent only those [No.] values that have the same role. For example, define [No. Type 1] as if [Table Name] = “Table 1” then [No.] end. And define, [No. Type 2] similarly. Then you can hide the original [No.] field.
These new fields will only have values for the appropriate data rows, and will be null otherwise. Aggregate functions like SUM(), AVG() etc ignore nulls, so you can use those fields as measures easily.
If you want to use a calculation in a JOIN clause, say after making a UNION, then first specify the tables (or unions of tables) to join, then when you click on the Venn diagram to specify the join keys, and then select either the left or right list of fields --> look at the bottom of the list in small print to either create or edit your Join Calculation.

Using a query to supply an Access form

I have a Microsoft Access form that is being supplied (somehow) by a query. The query contains three tables linked together via their respective primary and foreign keys, and the form displays data quite happily.
The strange thing (as far as I'm concerned) is the ability of the form to then allow data entry using the query.
However, if the user creates a new record, the whole thing seems to have problems due to a required field in the [table2] table.
SELECT [table1].*
,[table2].JobNo
,[table2].PlannedDateOC
,[table3].DateJobStarted
,[table1].PlanNo
FROM (
[table1] LEFT JOIN [table2] ON [table1].PlanNo = [table2].PlanNo
)
LEFT JOIN [table3] ON [table2].JobNo = [table3].JobNo
ORDER BY [table2].PlannedDateOC
,[table1].PlanNo;
According to the users, this form worked perfectly prior to conversion from Access 97/2003 format to Access 2010 (2007 file format).
Could anyone clarify whether this (the fact that it should work) is legitimate, and if this process would work in either version of Access, if so? The concept of being able to use a query for data entry is quite alien to me.
Let me know if you need further clarification.
NOTE:
One thing of note, here, is that I did move some of the fields into the form header so that they were always visible as the rest of the form scrolls. I don't know if this will have any side effects on the performance of the form.
Above query will allow you to insert data into [table1] when all not null fields have their values and make sure only table1.fields are getting dirty when new record is inserted.

Can't remap fields - map fields window is missing new table

I have a Crystal Report with a database command:
The command has a join clause that can be removed and read from a table in the database, because it represents static data. I add this table (called _System) to the database expert:
Now I edit the command to remove the join and columns that reference this table. Since the report fields that depended on these columns are no longer mapped, this causes the Map Fields window to appear:
...which does not have the new table in it. If I cancel out of this I am back to where I originally was. If I hit OK without mapping, all of the unmapped fields on the report are deleted (suffice it to say... I was not expecting this >:( )
I have tried adding links between the command and the new table, and refreshing report parameters, but these have had no effect.
One workaround is to manually replace every field in the report, but this is very labour intensive.
Here is the outline of the command before:
SELECT ACT.Account_Code, ACT.Company, ACT.FName, --etc
STM.CompanyName AS 'DLRName', STM.Address_1 AS 'DLRAddress', STM.City AS 'DlrCity' --etc
FROM Accounts AS ACT
JOIN _System AS STM ON 1 = 1
GROUP BY ACT.Account_Code, ACT.Company, ACT.FName, --etc
STM.CompanyName, STM.Address_1, STM.City --etc
And after:
SELECT ACT.Account_Code, ACT.Company, ACT.FName, --etc
FROM Accounts AS ACT
GROUP BY ACT.Account_Code, ACT.Company, ACT.FName --etc
I have removed the JOIN on the _System table, and all referenced columns.
It appears to not be recognizing your _system table as a new source.
I would :
1) leave your command object SQL unchanged & get the issue worked out with the _System table, then
2) ensure that you are able to establish a join between the command object fields and the _System table fields, and lastly
3) then remap the fields.
Step two I suspect is the source of the problem, as your join condition is "ON 1 = 1" which I assume to mean that you may not have a common key field in both tables.
Note that your original command SQL selects STM.Companyname AS 'DLRName'.
Hence, crystal now know of a field called DLRName, but does not know of a field called CompanyName, hence it cannot make the association between DLRName in the old source, and CompanyName in the new source...
Likewise with the rest of the fields that are being moved from the command object to an attached table. if no name match exists...Crystal cant make the connection. However...it would list all unmatched fields that are on the report, and all unused fields in the recognized data sources, and allow you to specify the matches yourself.
But it does not...which tells me that something has gone wrong with the attempt to attach/open the _System table. Hence..you need to get that worked out first, then make the field adjustments.
If this doesnt get you thru...then show some sample data so I can see how the two tables are relating ( ensure some examples exists where there is a row match from both tables ).
I had the same problem a while ago.
Unfortunately I can't find anything online that helps, or maybe wasn't looking hard enough. I just noticed that in my case, that particular field that isn't showing in the map field dialogue box has nvarchar(max) as its datatype (in view).
I tried to force the datatype with CAST(missingfieldname as nvarchar(20)) as missingfieldname (I did this in the view), and voila, it magically appears in the map field dialogue box.
It seems that field mapping dialogue box aren't showing fields with blob texts.
I know this question was asked 4 years ago. But hopefully, this comment could help future solution seekers regarding this absurd and weird problem. I just got lucky seeing what's unique about that particular missing field.

changing a record to a different area

I hope yo can point me in the right direction.
I have a SSRS report organized by Continent/Country/Customer and I need to change (force?) some of the customers to appear in a different region/country from the DB. ie:
I have a local NZ customer in the right Region/Country (australasia/New Zealand) but I want this one to show up in a different Region/Country namely (Asia/China) as this customer buys locally but exports all to China.
There are some others customers that needs to be manually organized, following the same criteria, of course.
any idea on how can I do this?
and will be the best option to do it through SQL-Server or SSRS?
Thanks in advance.
Eric
I would create a new table called something like AreaOverride with the following columns:
CustomerId
Continent
Country
Then link to this in your query using a left outer join and replace the Continent and Country with the overridden values if they exist:
Select CustomerId,
Case when AreaOverride.Continent is not null then AreaOverride.Continent else Customer.Continent end as Continent,
Case when AreaOverride.Country is not null then AreaOverride.Country else Customer.Country end as Country
From Customer
Left outer join AreaOverride On AreaOverride.CustomerId = Customer.CustomerId
You might want to make this a view if you are going to use it in several reports or other places.
Then whenever you need to override a customer's details you simply add a row for them in this table and the values will be overridden in your reports.
Note that if you are dealing with a vendor database rather than your own you don't want to be messing with their database structure but you can still do this by creating a new database and put the AreaOverride table in it. Then you add the database name to your join. For example if your database was called MyStuff then your join looks like this:
Left outer join MyStuff.dbo.AreaOveride On ...