I'm trying to create a waterfall style report using the matrix style in SSRS with an unknown number of columns and they are all named m1, m2, m3, m4, etc. Each m value contains the total paid for that time frame. How can I specify the custom field name in the matrix.
(Column_Group)
| Date Arrived | Cost | Payment | [ArriveDate] |
|---------------------------------|---------------|
| [ArriveDate] | [Cost] | [Pay] | [m1] |
Example of what I'd like to see:
| Date Arrived | Cost | Payment | 2018/05 | 2018/06 |
|---------------------------------|-----------------------------|
| 2018/05 | $200 | $100 | $25.00 | $75.00 |
| 2018/06 | $400 | $200 | $100.00 | $100.00 |
SQL Dataset Sent To Report:
| ArriveDate | Cost | Pay | m1 | m2 |
---------------------------------------
| 2018/05 | 200 | 100 | 25 | 50 |
| 2018/06 | 400 | 200 | 100 | 100 |
Related
To check a patient's status in a medical test(high, low, average), I have to keep range values for the tests in a table
For a test there can be several ranges.
| range | status |
|-----------|---------|
| 0 - 100 | Low |
| 101- 200 | Average |
| 201 - 300 | High |
For another test, ranges can be different according to the gender
| range | Gender | status |
|-----------|--------|---------|
| 0 - 100 | Male | Low |
| 0 - 105 | Female | Low |
| 100- 200 | Male | Average |
| 105 - 210 | Female | Average |
| 200 - 300 | Male | High |
| 210 - 300 | Female | High |
There can be range data as age, gender, status as well.
How can I map the ranges in database which enables to check which range user is in for a given test result. As an example For a Sugar Test a male user may have a result 45. I need whether the test value is high, low or average.
My initial table solution is shown below. I don't think this is a good solution.
| test | min_age | max_age | range_upper | range_lower | Gender | status |
|------|---------|---------|-------------|-------------|--------|---------|
| 1 | 1 | 10 | 0 | 100 | Male | Low |
| 1 | 1 | 10 | 100 | 200 | Male | Average |
| 1 | 1 | 10 | 200 | 300 | Male | High |
| 1 | 1 | 10 | 0 | 100 | Female | Low |
| 1 | 1 | 10 | 100 | 200 | Female | Average |
| 1 | 1 | 10 | 200 | 300 | Female | High |
Please sorry for my English.
Why do not use range reference instead of pair of values?
Table status_ranges
| id | range_min | range_max | status |
|----|-----------|-----------|---------|
| 1 | 0 | 100 | Low |
| 2 | 101 | 200 | Average |
| 3 | 201 | 300 | High |
Table of tests
| test | value_1 | gender | id_status_of_value_1 | . . .
|------|---------|--------|----------------------|-----
| 1 | 10 | Male | 1 | . . .
| 1 | 120 | Male | 2 |
| 1 | 235 | Male | 3 |
| . . .
I have a sliding commission rate calculation in excel / googlesheet I am trying to port to MYSQL/PHP
I have this table in range B3:E9 (excel/google sheets)
+---+----------+-----------+-----------+----------+
| A | B | C | D | E |
+---+----------+-----------+-----------+----------+
| 3 | Tier Min | Tier Max | Com. Rate | Dif Rate |
| 4 | 0 | 50,000 | 10.00% | 0.10 |
| 5 | 50,000 | 100,000 | 15.00% | 0.05 |
| 6 | 100,000 | 200,000 | 20.00% | 0.05 |
| 7 | 200,000 | 300,000 | 25.00% | 0.05 |
| 8 | 300,000 | 500,000 | 30.00% | 0.05 |
| 9 | 500,000 | 1,000,000 | 35.00% | 0.05 |
+---+----------+-----------+-----------+----------+
+----------------+----------------+
| Sales | $ 160,000.00 |
+----------------+----------------+
| Commission US$ | $ 24,500.00 |
| Global Rate % | 15.31% |
+----------------+----------------+
I input "Sales" amount in H4 and I have the formula to calculate the Commission US$:
=SUMPRODUCT(--(H4>$B$4:$B$9),--(H4-$B$4:$B$9),$E$4:$E$9)
Now my question. If I have One table called "Sales"
+----+------------+--------------+
| ID | Date_Sales | Sales_Amount |
+----+------------+--------------+
| 1 | 2015-01-31 | 160000 |
| 2 | 2015-02-28 | 142000 |
| 3 | 2015-03-31 | 430222 |
| 4 | 2015-04-30 | 234000 |
+----+------------+--------------+
And another "commission table" (structure to define), which reflects my tier rate table above (0-50 000, 10%, etc...)
What would be the best way in mySQL (combined with php if necessary) to calculate the correct commission for January 2015, which should amount to $24 500?
Thanks in advance for your help and suggestions.
I guess you're after something like this:
SELECT s.id
, SUM((s.sales_amount - r.tier_min) * r.dif_rate) x
FROM sales s
JOIN commission_rates r
ON r.tier_min <= s.sales_amount
GROUP
BY s.id;
+----+----------+
| id | x |
+----+----------+
| 1 | 24500.00 |
| 2 | 20900.00 |
| 3 | 96566.60 |
| 4 | 41000.00 |
+----+----------+
I have to fetch data from a MySql Sales table comparing sales of each sales person.
My Sales table is like this -
DateOfSale |SalesPersonId| Value
>------------------------------------------
>20150324 | 300014 | 5600 | |
>20150324 | 300011 | 5400 | |
>20150324 | 300014 | 4900 | |
>20150323 | 300011 | 4100 | |
>20150324 | 300012 | 4200 | |
>20150324 | 300014 | 1600 | |
>20150323 | 300011 | 4300 | |
>20150324 | 300014 | 5200 | |
>20150324 | 300011 | 7900 | |
>20150323 | 300014 | 4800 | |
>20150324 | 300012 | 4900 | |
>20150323 | 300012 | 4600 | |
>20150324 | 300011 | 4200 | |
>20150322 | 300011 | 5400 | |
>20150324 | 300014 | 3500 | |
>20150324 | 300012 | 1800 | |
>20150324 | 300014 | 8700 | |
>20150322 | 300011 | 3300 | |
>20150324 | 300014 | 3400 | |
>20150322 | 300014 | 2700 | |
I would like to make a comparative report of all sales persons, something like this
360012 360013 360014 ---- (SalesPersonId)
-----------------------------------------------
DateOfSale1 | Value | Value | Value |
| | | |
DateOfSale2 | Value | Value | Value |
| | | |
DateOfSale3 | Value | Value | Value |
What would be the fastest query to achieve this?
If the number of SalesPersonID is known and it's relatively small, then you will use CASE statements. Something like:
SELECT
DateOfSale,
SUM(CASE WHEN SalesPersonID = '360012' THEN Value END) AS `360012`,
SUM(CASE WHEN SalesPersonID = '360013' THEN Value END) AS `360013`,
....
If the SalesPersonIDs are more dynamic then you'll have to get a bit craftier. Check out this article: http://buysql.com/mysql/14-how-to-automate-pivot-tables.html on how to get MySQL to do a dynamic pivot table. It's not for the faint of heart...
Generally, this type of data transformation is best left to your front end/display software since it's more of a presentation type of thing.
Would like to display query result from different tables:
Confirmed Orders: Confirmed Order Details:
+-------+--------+-------+ +--------+------+-------+------+
|COID |Customer|Payment| | CODID| COID | Items | Qty |
+-------+--------+-------+ +--------+------+-------+------+
| 1 | Jack | 11000 | | A | 1| Crack | 5 |
| 2 | Jill | 3000 | | B | 2| Weed | 7 |
+-------+--------+-------+ | C | 2| Beer | 7 |
+--------+------+-------+------+
Purchase Orders:
+--------+----------+---------+
| POID | PO Amount| Vendor |
+--------+----------+---------+
| 6 | 100 | Puffy.D |
| 7 | 500 | Bud Wise|
+--------+----------+---------+
And based on the values from a table named "DataMatrix":
DataMatrix:
+--------+--------------------+---------+--------------------------+
| DataID | table1 | DataID2 | table2 |
+--------+--------------------+---------+--------------------------+
| 1 | Confirmed Orders | A | Confirmed Order Details |
| 6 | Purchase Orders | A | Confirmed Order Details |
| 6 | Purchase Orders | 1T | Tracking |
| 2 | Confirmed Orders | B | Confirmed Order Details |
| 2 | Confirmed Orders | C | Confirmed Order Details |
| 7 | Purchase Orders | B | Confirmed Order Details |
| 7 | Purchase Orders | C | Confirmed Order Details |
| 7 | Purchase Orders | 2T | Tracking |
| 7 | Purchase Orders | 3T | Tracking |
+--------+--------------------+---------+--------------------------+
So hoping the result will be displayed into one table, such as below:
+--------+------+-------+-------+--------+-------+--------+----------+---------+
| CODID| COID | Items | Qty |Customer|Payment| POID | PO Amount| Vendor |
+--------+------+-------+-------+--------+-------+--------+----------+---------+
| A | 1| Crack | 5 | Jack | 11000 | 6 | 100 | Puffy.D
| B | 2| Weed | 7 | Jill | 3000 | 7 | 500 | Bud Wise|
| C | 2| Beer | 7 | Jill | 3000 | 7 | 500 | Bud Wise|
+--------+------+-------+-------+--------+-------+--------+----------+---------+
Self-taught MySQL, learned mostly from StackOverflow. I tried
max(case when (criteria) then...etc.
But the result can only be displayed in one column? Is what I am seeking even possible just using MySQL?
I have an access table containing over 100,000 records. My problem is that many of the records have duplicate information. I would like to merge/combine the records into record.
I have a field (CommonField) that can be used to identify the duplicates (sometimes more than two records). Each field needs to be considered on an individual basis. For instance:
If the date fields are not equal, I would prefer to keep the most recent date.
If the count fields are not equal, I would prefer to keep the larger value.
If the company names are not equal, I would prefer to keep both names unless one is within the other.
CLICK HERE for a sample of the data:
+------------------+-------------+-------+-------+------------------+-----------+------------+--------+-----------------------------+
| Existing Records | | | | | | | | |
+------------------+-------------+-------+-------+------------------+-----------+------------+--------+-----------------------------+
| ID | CommonField | First | Last | Email | Date | Currency | Count | Company |
| 1 | AA123 | John | | | | $465,000 | | ABC Company Ltd |
| 2 | AA123 | John | | John#gmail.com | 1-Mar-78 | $465,000 | 87,000 | ABC Company |
| 3 | AA123 | | Doe | | 14-Mar-78 | $465,000 | 88,000 | |
| 4 | BB456 | Dave | Smith | | 1-Apr-92 | $1,200,000 | 5,000 | Carter Company |
| 5 | BB456 | | Smith | Dave#aol.com | 1-Apr-92 | $1,200,000 | 5,000 | Simpson Ltd |
| 6 | CC568 | | | Jane#hotmail.com | 1-Sep-05 | $60,000 | | Woods Holdings |
| 7 | CC568 | | Woods | Jane#hotmail.com | | | 40,000 | Woods |
| 8 | CC568 | Jane | Woods | | 1-Sep-05 | | | |
| 9 | DD211 | Bob | Burns | Bob#gmail.com | 5-Aug-01 | $678,100 | 21,400 | |
| | | | | | | | | |
| Desired Result | | | | | | | | |
| ID | CommonField | First | Last | Email | Date | Currency | Count | Company |
| 10 | AA123 | John | Doe | John#gmail.com | 14-Mar-78 | $465,000 | 88,000 | ABC Company Ltd |
| 11 | BB456 | Dave | Smith | Dave#aol.com | 1-Apr-92 | $1,200,000 | 5,000 | Carter Company, Simpson Ltd |
| 12 | CC568 | Jane | Woods | Jane#hotmail.com | 1-Sep-05 | $60,000 | 40,000 | Woods Holdings |
| 13 | DD211 | Bob | Burns | Bob#gmail.com | 5-Aug-01 | $678,100 | 21,400 | |
+------------------+-------------+-------+-------+------------------+-----------+------------+--------+-----------------------------+
I am interested in hearing your suggestions as to the best way of tackling this project.
Ugly.
I think for the name fields, you may need another table to combine names. I'd start by making a new table from a group by query on both the common id and the company name. Add an extra field for the standardized name to the table, then use a find duplicates query to look at all the common ids with more than one name and manually assign a standardized name.
Then you can bring both the original data table and the company names table into a group by query and pull the standardized name into the final result. For the data and count fields, you can use max(date) and max(count). This should work for the first, last and email text fields also - but you will want to manually examine the results pretty carefully.