VisualStudio 2010 - How do you display only YEAR in a chart? - visual-studio-2010

This is the code I used in my dataset. The result is as shown in the image.
The plan is to display the YEAR without month, day or time. Is this feasible?
SELECT t.Name AS Territoryname,
p.LastName AS SalesPerson,
c.CardType AS PayType,
s.OrderDate,
s.TotalDue
FROM Sales s
JOIN Person p
ON s.SalesPersonID=p.BusinessEntityID
JOIN CreditCard c
ON c.CreditCardID=s.CreditCardID
JOIN Territoryt
ON t.TerritoryID=s.TerritoryID

There are a number of ways to achieve this. The easiest, is to calculate a year value directly in your dataset, and then use this field in your chart. This is a simple matter of adding the following code to the select part of your dataset:
select
...
s.OrderDate,
YEAR(s.OrderDate) AS [OrderYear], -- This is the new field
s.TotalDue
from
...
Alternatively, you can create an expression that does the same thing, either as a calculated field in your dataset, or directly in the chart as the category field.

Related

Google Sheet Date and Time Calculation Question

I have a column that has 34 records of Week Day, Month/Day, and Times. I am looking for two formulas that I can use in a table that will give me the count of weekdays and the time duration per day. Eventually, I would like to just copy and past new dates into column A and have the table automatically calculate. Here is my google sheet example. Is there a way to do this without creating helper columns? If not, no big deal. Anything to help automate the process will be helpful.
https://docs.google.com/spreadsheets/d/1C6N94QJyEgm-2yg2SEDOweIU2fk2h2DLydKb-nH-ObE/edit?usp=sharing
enter image description here
Take a look at the Punches tab in the sample sheet below. It shows what I was mentioning about breaking the columns up. Then, using the QUERY() function I was able to populate the table.
https://docs.google.com/spreadsheets/d/1qbLOjTdzISICTKyUp_jK6gZbQCt-OwtDYYy3HNJygeE/edit#gid=1181136581
G6 Formula
=if(isna(query($A$1:$C, "SELECT COUNT(B) WHERE B ='"&F2&"' LABEL COUNT(B) ''",1)),0,query($A$1:$C, "SELECT COUNT(B) WHERE B ='"&F2&"' LABEL COUNT(B) ''",1))
H6 Formula
=if(G2<>0,query($A$1:$C, "SELECT C WHERE B ='"&F2&"' ORDER BY C DESC LIMIT 1 LABEL C ''",1)-query($A$1:$C, "SELECT C WHERE B ='"&F2&"' ORDER BY C LIMIT 1 LABEL C ''",1),0)

How to create chart with multiple series in Oracle Apex

I have a bar chart that it works fine, but the chart use just one series for all bars and all bars have same color. What should I do for creating different series for each records of my query?
This is my query:
select customeTable.firstname||' '||customeTable.lastname as fullName, customeTable.sumHour as sumHour
from (
select sum(projActivity.ACTIVITY_HOUR) as sumHour, users.FIRST_NAME as firstname, users.LAST_NAME as lastname
from SITA_PROJECT_TASKS_ACTIVITY projActivity
inner join SITA_PROJECT_TASKS projTask on projTask.ID=projActivity.TASK_ID and projTask.PROJECT_ID=:P39_PROJECT_ID
inner join SITA_USERS users on users.ID=projActivity.CREATOR_ID
where
(:P39_FROM_DATE is null or projActivity.ACTIVITY_DATE>=:P39_FROM_DATE)
and (:P39_TO_DATE is null or projActivity.ACTIVITY_DATE<=:P39_TO_DATE)
group by users.FIRST_NAME,users.LAST_NAME
) customeTable
If you have a column in your query that can be used to derive the name of the series, you can set that column as the name of the series. Demo application can be seen here.
You'd do exactly what you said: add another series. How? Right-click the chart region name and select "Create series":
Every series can have its own query, or they can share the region's source - it depends on you. Fill other required properties and you should have several series on the same chart.

Sum of only Distinct values in a Column in DAX

I have table[Table 1] having three columns
OrganizationName, FieldName, Acres having data as follows
organizationname fieldname Acres
ABC |F1 |0.96
ABC |F1 |0.96
ABC |F1 |0.64
I want to calculate the sum of Distinct values of Acres
(eg: 0.96+0.64) in DAX.
One of the problems with doing what you want is that many measures rely on filters and not actual table expressions. So, getting a distinct list of values and then filtering the table by those values, just gives you the whole table back.
The iterator functions are handy and operate on table expressions, so try SUMX
TotalDistinctAcreage = SUMX(DISTINCT(Table1[Acres]),[Acres])
This will generate a table that is one column containing only the distinct values for Acres, and then add them up. Note that this is only looking at the Acres column, so if different fields and organizations had the same acreage -- then that acreage would still only be counted once in this sum.
If instead you want to add up the acreage simply on distinct rows, then just make a small change:
TotalAcreageOnDistinctRows = SUMX(DISTINCT(Table1),[Acres])
Hope it helps.
Ok, you added these requirements:
Thank You. :) However, I want to add Distinct values of Acres for a
Particular Fieldname. Is this possible? – Pooja 3 hours ago
The easiest way really is just to go ahead and slice or filter the original measure that I gave you. But if you have to apply the filter context in DAX, you can do it like this:
Measure =
SUMX(
FILTER(
SUMMARIZE( Table1, [FieldName], [Value] )
, [FieldName] = "<put the name of your specific field here"
)
, [Value]
)

Type wise summation and subtracting in oracle

I have two table of my store and working on Oracle. Image First table describe about my transaction in store, there are two types of transaction (MR & SR), MR means adding products in Store and SR means removing products from my storage. What I wanted to do get the final closing of my storage. After transaction final Quantity every products as shown in Image. I have tried many solution but can't finish it. so I could not show now. Please help me to sort this problem. Thanks
You can use case as below to decrease and increase the quantity based on type and then group by Name and find the sum of quantity derived from the case statement to get your desired result.
select row_number() over (order by a.Name) as Sl,a.Name, sum(a.qntity) as qntity
from
(select t2.Name,case when t1.type='MR' then t2.qntity else -(t2.qntity) end as qntity
from table1 t1,table2 t2 where t1.oid=t2.table01_oid) a
group by a.Name;
This query will provide result as below:
SL NAME QNTITY
1 Balls 0
2 Books 6
3 Pencil 13

Selecting data from one table or another in multiple queries PL/SQL

The easiest way to ask my question is with a Hypothetical Scenario.
Lets say we have 3 tables. Singapore_Prices, Produce_val, and Bosses_unreasonable_demands.
So Prices is a pretty simple table. Item column containing a name, and a Price column containing a number.
Produce_Val is also simple 2 column table. Type column containing what type the produce is (Fruit or veggie) and then Name column (Tomato, pineapple, etc.)
The Bosses_unreasonable_demands only contains one column, Fruit, which CAN contain the names of some fruits.
OK? Ok.
SO, My boss wants me to write a query that returns the prices for every fruit in his unreasonable demands table. Simple enough. BUT, if he doesn't have any entries in his table, he just wants me to output the prices of ALL fruits that exist in produce_val.
Now, assuming I don't know where the DBA who designed this silly hypothetical system lives (and therefore can't get him to fix this), our query would look like this:
if <Logic to determine if Bosses demands are empty>
Then
select Item, Price
from Singapore_Prices
where Item in (select Fruit from Bosses_Unreasonable_demands)
Else
select Item, Price
from Singapore_Prices
where Item in (select Name from Produce_val where type = 'Fruit')
end if;
(Well, we'd select those into a variable, and then output the variable, probably with bulk-collect shenanigans, but that's not important)
Which works. It is entirely functional, and won't be slow, even if we extend it out to 2000 other stores other than Singapore. (Well, no slower than anything else that touches 2000 some tables) BUT, I'm still doing two different select statements that are practically identical. My Comp Sci teacher rolls in their grave every time my fingers hit ctrl-V. I can cut this code in half and only do one select statement. I KNOW I can.
I just have no earthly idea how. I can't use cursors as an in statement, I can't use nested tables or varrays, I can't use cleverly crafted strings, I... I just... I don't know. I don't know how to do this. Is there a way? Does it exist?
Or do I have to copy/paste forever?
Your best bet would be dynamic SQL, because you can't parameterize table or column names.
You will have a SQL query template, have a logic to determine tables and columns that you want to query, then blend them together and execute.
Another aproach, (still a lot of ctrl-v like code) is to use set construction UNION ALL:
select 1st query where boss_condition
union all
select 2nd query where not boss_condition
Try this:
SELECT *
FROM (SELECT s.*, 'BOSS' AS FRUIT_SOURCE
FROM BOSSES_UNREASONABLE_DEMANDS b
INNER JOIN SINGAPORE_FRUIT_LIST s
ON s.ITEM = b.FRUIT
CROSS JOIN (SELECT COUNT(*) AS BOSS_COUNT
FROM BOSSES_UNREASONABLE_DEMANDS)) x
UNION ALL
(SELECT s.*, 'NORMAL' AS FRUIT_SOURCE
FROM PRODUCE_VAL p
INNER JOIN SINGAPORE_FRUIT_LIST s
ON (s.ITEM = p.NAME AND
s.TYPE = 'Fruit')
CROSS JOIN (SELECT COUNT(*) AS BOSS_COUNT
FROM BOSSES_UNREASONABLE_DEMANDS)) n
WHERE (BOSS_COUNT > 0 AND FRUIT_SOURCE = 'BOSS') OR
(BOSS_COUNT = 0 AND FRUIT_SOURCE = 'NORMAL')
Share and enjoy.
I think you can use nested tables. Assume you have a schema-level nested table type FRUIT_NAME_LIST (defined using CREATE TYPE).
SELECT fruit
BULK COLLECT INTO my_fruit_name_list
FROM bosses_unreasonable_demands
;
IF my_fruit_name_list.count = 0 THEN
SELECT name
BULK COLLECT INTO my_fruit_name_list
FROM produce_val
WHERE type='Fruit'
;
END IF;
SELECT item, price
FROM singapore_prices
WHERE item MEMBER OF my_fruit_name_list
;
(or, WHERE item IN (SELECT column_value FROM TABLE(CAST(my_fruit_name_list AS fruit_name_list)) if you like that better)

Resources