using Crystal reports 10 linked to an excel document. Would like to pull the dinner field but also pull country and Company name from row that dont have it, this are linked via Bookingref. Example below. I've tried sub-reports and supressing unwanted fields but can't get it right. Also I can't make changes in excel doc as it's 1000+ records, which is exported from an online system weekly.
Id BookingRef Country CompanyName Surname Forname Dinner
1 001 UK Company1 John Andrews
2 001 Mary Jane 1
3 001 Tom Andrews 1
4 002 Germany Company2 Lee Jones
5 003 Germany Company3 Peter Lee 1
6 003 Sofie Lee 1
OK I am not sure I understand the full extent of your problem but let's start with the Country and Company name and see if I can get you moving forward. Instead of putting the Country field directly on the report you could use a formula field and do something like this:
IF {#BookingRef} = "001" Then
"UK"
Else IF {#BookingRef} = "002" Then
"Germany"
Else
"Unnamed"
Now you just put the formula field where the country field used to be and it will put the right country in bases on the BookingRef code. This, however, is only practical if you are working with a small number of Country / Company Names or possibly a big list that never changes although I would caution against the latter.
The other thing you could do is create a table in any database that holds the BookingRef, Company and Country values, link the BookingRef fields from both "databases" and then just drop the fields on your report.
If I am missing the point of your question please be real specific about what it is you are trying to accomplish and what is and is not working in your current solution.
Related
I'm currently having an issue trying to make a query such that it displays the fields only if both parts are unique. For example, lets say the fields to be displayed currently are as goes:
SELECT
Name,
CompanyName,
JobStartDate,
Birthday,
Age,
Favorite Ice Cream,
Height
From 'sample_person_data'
How would I set this so that it only displays fields where both CompanyName and JobStartDate are both distinct?
At first, I thought just putting distinct would be enough, but came to the realization that would not work, I then thought what if I make it so that it has to check both CompanyName + JobStartDate as unique fields, so only showing the fields where both those two things are unique, but could not go about implementing it.
Essentially what I'm aiming to achieve is if there was a large dataset with some repeated values, how could I help display only the unique fields. I use CompanyName and JobStartDate as examples here, but I understand that people can start at the same company on the same day, therefore this would be a concept which could expand into adding more comparisons.
Thank you for your time.
EDIT: Based on comments I am trying to provide further detail by example
Say this is the sample data:
Name
CompanyName
JobStartDate
Birthday
Age
Favorite Ice Cream
Height
John
Google
04-17-00
01-01-78
50
Vanilla
5-7
John
Google
04-17-00
01-01-78
50
Chocolate
5-7
John
Microsoft
04-17-00
02-01-95
30
Chocolate
5-8
Nancy
Google
06-27-00
04-01-78
50
Vanilla
5-2
Joanna
Google
08-19-00
05-01-78
50
Vanilla
5-0
So here we see the same John from Google filled the form twice because say he decided to change his favorite ice cream. How do I edit the query such that it displays such as the following:
Name
CompanyName
JobStartDate
Birthday
Age
Favorite Ice Cream
Height
John
Google
04-17-00
01-01-78
50
Vanilla
5-7
John
Microsoft
04-17-00
02-01-95
30
Chocolate
5-8
Nancy
Google
06-27-00
04-01-78
50
Vanilla
5-2
Joanna
Google
08-19-00
05-01-78
50
Vanilla
5-0
I don't really care if his favorite ice cream shows up as Chocolate or Vanilla, but rather that only 1 entry of a John from google shows up, using the current company + job start date as the identifying fields for example.
Use below simple approach
select * from your_table
qualify 1 = row_number() over(partition by CompanyName, JobStartDate)
if applied to sample data in your question - output is
I have been practicing data manipulation in SQL Server Express 2017, and I have been provided with a data source I can't seem to make sense of. I was hoping there might be someone more familiar here that might be able to point me in the right direction. I need to work on some SQL queries on the dataset, but I haven't the faintest idea on where to start.
The data looks like this for instance:
Company Code - Field - Value (3 fields)
1001 - Vendor Name - 7 Eleven
1001 - Vendor Name - Bob Jane
1001 - Vendor Name - Krispy Kreme
1001 - Vendor Address - 102 Reservoir Street
1001 - Vendor Address - 110 Pitt Road
1001 - Vendor Address - 23 Foxy Place
Usually, I would expect to see it in a somewhat relational type of table like
Company Code Vendor Name Vendor Address
1001 7 Eleven 102 Reservoir Street.
1001 Bob Jane 110 Pitt Road.
What you have appears to be a design called EAV - entity attribute value. That term you can google. Unfortunately either you left out important information or your design is fundamentally broken. Given what you posted, there is no way to know that "Bob Jane" goes with "110 Pitt Road". Rows in a table have no reliable or specific order. You need a column in your table to define "order" if you want to associate rows based on "order".
I have following data set as data Model.
Country City AssetCount
USA Newyork 50
USA Washington 40
USA California 30
India Bangalore 100
India Delhi 50
India Bombay 30
I want to show one row showing sum of Assetcount at country level & city level on the same row.
There are two slicers for slicing City & Country as below:
USA Newyork
India Washington
California
Bangalore
Delhi
Bombay
So when I select country as India it should show sum of Asset-Count at country(India) level.
In the same way when I select City as Delhi it should show Asset-Count at City(Delhi) level.
India Delhi
180 50
Is it possible using PowerPivot using DAX?
Related content from their question on MSDN
Actually your solution is not working. I have created the hierarchy as Country-->City & kept that in Rows. So when I select a particular Country & City it showing like this:
Row Labels AssetCount
USA 40
Washington 40
Grand Total 40
But I want
USA Washington
120 40
or may be like
USA 120
Washington 40
I have tried some aggregate functions like below:
=SUMX(VALUES(Query[City]),CALCULATE(SUM(Query[AssetCount])))
=CALCULATE(SUM(Query[AssetCount]),SUMMARIZE('Query',Query[City]))
Here Query is table for Data Model & City can be replaced by Country.
but not working.
So showing such counts on same row is possible or not?
Sounds like you are just getting started with Power Pivot. You might browse through the links on this page for more help.
I took the data you provided and pasted it into Excel.
Selected the data and clicked Add to Data Model and checked the box for My Data Has Headers.
I made sure the AssetCount Column had a data type of whole number. Then clicked the Pivot Table button and created a pivot table on my existing spreadsheet.
I put AssetCount in the values and made sure it was set to Sum in the Field Value Settings.
I selected my pivot table and then went to the Analyze tab under PivotTable Tools and clicked the Insert Slicer button.
I selected both Country and City as slicers.
This gives your desired result.
If you want the two numbers in a row, that's pretty straightforward. Keep in mind, that all those slicers do is putting filters on the pivot table.
Therefore to get your city result, you could use either an implicit measure or explicit measure that simply sums up AssetCount.
For the country result, you'd wish to overload the city filter like this:
=calculate(SUM(Query[AssetCount]),ALL(Query[City]))
If you also need the country and city names there, it gets a bit tricky.
I have 3 tables:
Clients
User_Defined_Definitions
User_Defined_Data
The Clients table has basic information:
ClientID, Name, Address...
The User_Defined_Definitions has the title for the user def fields:
StartDate, SalesRep, Website...
Then the User_Defined_Data table contains the data to fill those fields for each client in the client table.
I've built a query which pulls all the data I need, but it pulls one row for each of the User_Defined_Data rows that exist for that client. What I would like to do is pull one row for each client, and append as many columns as needed to fill all the user defined fields into the one row.
ClientID Name Address Description Data
155555 Calvin 123 Fake St StartDate 10/10/2013
155555 Calvin 123 Fake St SalesRep Tom
155555 Calvin 123 Fake St Website http://www.fakesite.com
155556 Steve 456 Root Rd StartDate 8/5/2013
155557 Kathy 715 Main St StartDate 5/5/2010
155557 Kathy 715 Main St SalesRep Jessica
155557 Kathy 715 Main St Website http://www.fakesite2.com
155558 Jenny 345 Fake St StartDate 9/9/2012
155558 Jenny 345 Fake St Website http://www.fakesite3.com
The first three columns come from the Client table. The Description column comes from the User_Defined_Definitions table. And the Data comes from the User_Defined_Data table.
And I'd like to see it similar to this
ClientID Name Address StartDate SalesRep Website
155555 Calvin 123 Fake St 10/10/2013 Tom http://www.fakesite.com
155556 Steve 456 Root Rd 8/5/2013
155557 Kathy 715 Main St 5/5/2010 Jessica http://www.fakesite2.com
155558 Jenny 345 Fake St 9/9/2012 http://www.fakesite3.com
I know this is possible using sql, but I've just usually written scripts to deal with the data after the export. But this time I need to be able to do it in Access so the table can be re-opened 2 months from now and it will re-query the data in the same way.
Let me know if there's anything else I can provide to help get the right result.
ADDON
I took the long way around and made individual queries for each of the UDF's, then consolidated them all by running a query agains't each to place them all in one line. I am still curious how to do this with SQL though because right now I'm in the midst of changing CRM and Accounting software for my organization, and it's become a daunting task.
Here's the query I was using to pull the UDFs onto separate lines like outlined above.
SELECT dbo_AMGR_Client_Tbl.Client_Id, dbo_AMGR_Client_Tbl.Name,
dbo_AMGR_Client_Tbl.Address_Line_1, dbo_AMGR_Client_Tbl.Address_Line_2,
dbo_AMGR_Client_Tbl.City, dbo_AMGR_Client_Tbl.State_Province,
dbo_AMGR_Client_Tbl.Zip_Code, dbo_AMGR_User_Field_Defs_Tbl.Description,
dbo_AMGR_User_Fields_Tbl.DateCol, dbo_AMGR_User_Fields_Tbl.NumericCol,
dbo_AMGR_User_Fields_Tbl.AlphaNumericCol
FROM dbo_AMGR_User_Field_Defs_Tbl INNER JOIN (dbo_AMGR_Client_Tbl INNER JOIN
dbo_AMGR_User_Fields_Tbl ON dbo_AMGR_Client_Tbl.Client_Id =
dbo_AMGR_User_Fields_Tbl.Client_Id) ON (dbo_AMGR_User_Field_Defs_Tbl.Type_Id =
dbo_AMGR_User_Fields_Tbl.Type_Id) AND (dbo_AMGR_User_Field_Defs_Tbl.Code_Id =
dbo_AMGR_User_Fields_Tbl.Code_Id)
GROUP BY dbo_AMGR_Client_Tbl.Name_Type, dbo_AMGR_Client_Tbl.Client_Id,
dbo_AMGR_Client_Tbl.Name, dbo_AMGR_Client_Tbl.Address_Line_1,
dbo_AMGR_Client_Tbl.Address_Line_2, dbo_AMGR_Client_Tbl.City,
dbo_AMGR_Client_Tbl.State_Province, dbo_AMGR_Client_Tbl.Zip_Code,
dbo_AMGR_User_Field_Defs_Tbl.Description, dbo_AMGR_User_Fields_Tbl.DateCol,
dbo_AMGR_User_Fields_Tbl.NumericCol, dbo_AMGR_User_Fields_Tbl.AlphaNumericCol
HAVING (((dbo_AMGR_Client_Tbl.Name_Type)="C") AND ((dbo_AMGR_Client_Tbl.Name) Not Like "*HOUSE*"))
ORDER BY dbo_AMGR_Client_Tbl.Name;
It seems you have multiple rows related to one clientID in the User_Defined_Data table.
Why don't you rebuild that table so that it contains all the fields you require and is one-to one with Clients?
Otherwise you may use CASE statement in your query and filter its contents by description.
I want to structure a table to mimic column level filters as row level filter just to avoid adding new columns.
Let's say i have following table to store cars' details
-------------------------------------
Type Color Year
-------------------------------------
Mini Silver 2010
Standard Silver 2011
Fullsize White 2011
Luxury Black 2010
Sports Red 2011
Convertible Red 2009
If i want to store Make of these cars as well and for this i have to add an additional column and another column if i have automobiles other than cars.
So the question is how can i structure this table to avoid adding new columns? The structure should require only to add rows to define properties of my records.
[Hint] The structure may have multiple tables, one to store rows/records and other to store columns/properties and then some kind of mapping between them OR entirely new structure.
EDIT
Some of the properties of my data are fixed and some are dynamic. Fixed properties can be mapped to the given sample Car model as Availability, Condition and the dynamic could be anything which a person may ask about an automobile. Now i don't need all columns to be mapped as rows but few and these are dynamic and i don't even know all of them. My apologies that i didn't mention this earlier.
You could use the entity-attribute-value design (EAV).
entity attribute value
1 Type Mini
1 Color Silver
1 Year 2010
1 Make Foobar
2 Type Standard
2 Color Silver
etc...
You may also wish to store the attribute names in a separate table.
However you should consider carefully if you really need this, as there are a few disadvantages. The value column must have a type that can store all the different types of values (e.g. string). It is much more cumbersome to write queries as you will need many joins, and these queries will run more slowly as compared to a traditional database design.
To give you a head start: Think about redesigning to allow multi-colored vehicles like motorbikes:
vehicle
Id Year vehicle_type vehicle_make
-------------------------------------------
1 2010 1 1
2 2011 2 2
color
Id Name
-----------
1 Black
2 White
3 Red
4 Blue
vehicle_color
vehicle_id color_id
-----------------------
1 3
2 1
2 2
vehicle_type
Id Name
-----------
1 Car
2 Motorbike
vehicle_make
Id Name
-----------
1 Porsche
2 BMW
Bonus
Since I'm quite familiar with the car domain, I'll throw in an extension for your vehicle colors: There are tons of color names ("Magentafuzzyorangesunset") invented by manufacturers and you'll want to map them to "real" base color names ("Red, "Blue", "Green", etc.) to enable searching for both.
Your color table then could look like that
Id Name base_color
-----------------------------
1 Midnight 1
2 Snow 2
and you'll add a base_color table
Id Name
-----------
1 Black
2 White