I want to translate the text columns of an ALV-Grid into different languages.
For example I have following code:
alv->get_columns( )->get_column( 'REVENUE' )->set_short_text( 'Revenue' ) ##NO_TEXT.
alv->get_columns( )->get_column( 'REVENUE' )->set_medium_text( 'Revenue ) ##NO_TEXT.
alv->get_columns( )->get_column( 'REVENUE' )->set_long_text( 'Revenue' ) ##NO_TEXT.
My idea was to use text elements to translate the column names.
alv->get_columns( )->get_column( 'REVENUE' )->set_short_text( TEXT-001 ) ##NO_TEXT.
alv->get_columns( )->get_column( 'REVENUE' )->set_medium_text( TEXT-002 ) ##NO_TEXT.
alv->get_columns( )->get_column( 'REVENUE' )->set_long_text( TEXT-003 ) ##NO_TEXT.
But I'm not a fan of maintaining 3 different text elements.
Is there a better solution for this issue?
Best option is creating your own data element and managing translation on there.
Related
Using ORACLE SQL, I have a query that gives me the output in the following table(posting an image). However, I need to figure out a way to get the percentage change between year, quarter and metric in an additional column.
Example: Year 2022, Q1, apple against Year 2021, Q1, apple.
I'm relatively new to SQL so I'm not sure if I need to sort the output differently to use the function LEAD, or if there is a better way to do it in general.
My current query with my attempt at the percent change with lead (that didn't work) is like this:
`
SELECT s.YEAR
, t.quarter
, CASE WHEN fruits IN ('tangerine','lemon') THEN 'orange'
ELSE fruits
END metric
, COUNT(DISTINCT s.ID) AS COUNT
-- , ROUND((COUNT(UNIQUE s.ID) - LEAD(COUNT(UNIQUE s.ID)) OVER (ORDER BY t.quarter))/COUNT(UNIQUE s.ID)*100,2) pct_change
FROM s
JOIN sc
ON S.KEY = SC.KEY
JOIN c
ON SC.KEY = C.KEY
JOIN t
ON s.quarter = t.quarter
WHERE S.YEAR BETWEEN '2021' AND '2022'
AND s.quarter IN ('1','2','3')
GROUP BY S.YEAR
, t.quarter
,CASE WHEN fruits IN ('tangerine','lemon') THEN 'orange'
ELSE fruits
END
`
With my query as (
...your original query as above goes here...
)
Select curr.year, curr.quarter, curr.metric
, curr.count as current_count
, Case When prior.count is null then prior.count else if prior.count = 0 then null else (curr.count - prior.count)/ prior.count*100 as pct_chg
From my_query curr Left Outer Join my_query prior
On curr.year-1 = prior.year and
curr.qtr=prior.qtr and
curr.metric=prior.metric
I have 2 tables - countries (id, name, continent) and population_years (id, population, year, country_id). The data goes from 2000-2010 and I'm trying to calculate the percentage diff in average population for each continent across this time period. I'm trying to do it by creating a temporary table which produces an output of:
But when I try to calculate the % diff (as you can see from my code below), I don't know how to reference the 'avg pop 2000' and 'avg pop 2010' columns in the code as they haven't been assigned a variable that I can reference. In the code, I've used avg_pop_2010 and avg_pop_2000 to reference these columns - obviously this doesn't actually work.
WITH avg_pop AS( SELECT countries.continent,
ROUND(AVG(CASE WHEN population_years.year = 2000 THEN population_years.population END), 2) as 'avg pop 2000',
ROUND(AVG(CASE WHEN population_years.year = 2010 THEN population_years.population END), 2) as 'avg pop 2010'
FROM countries
JOIN population_years
WHERE population_years.country_id = countries.id
GROUP BY 1)
SELECT countries.continent, ROUND(((avg_pop_2010 - avg_pop_2000)/avg_pop_2000)*100.0, 2) AS '%diff'
FROM avg_pop;
Another option is to repeat the expressions - with a little optimization:
select
c.continent,
round(avg(case when py.year = 2000 then py.population end), 2) avg_pop_2000,
round(avg(case when py.year = 2010 then py.population end), 2) avg_pop_2010,
round(
100.* avg(case when py.year = 2010 then py.population else - py.population end)
/ avg(case when py.year = 2000 then py.population end),
2
) percent_diff
from countries c
inner join population_years py on py.country_id = c.id
where py.year in (2010, 2020)
group by c.continent
Side notes:
don't use single quotes for identifiers! They stand for literal strings in standard SQL; in general, you should prefer identifiers that do not need to be quoted. If quoting is needed, use standard double quotes ("), which SQLite recognizes
prefiltering the relevant years with a where clause makes the query more efficient
use standard join syntax; the join condition goes to the on clause of the join, not to the where clause
rounding, then computing the percent difference is not accurate; compute first, then round
table aliases make the query easier to write and read
WITH avg_pop AS( SELECT countries.continent,
ROUND(AVG(CASE WHEN population_years.year = 2000 THEN population_years.population END), 2) as avg_pop_2000,
ROUND(AVG(CASE WHEN population_years.year = 2010 THEN population_years.population END), 2) as avg_pop_2010
FROM countries
JOIN population_years
WHERE population_years.country_id = countries.id
GROUP BY 1)
SELECT continent, ROUND((( avg_pop_2000 - avg_pop_2010)/avg_pop_2010)*100, 2) AS '%diff'
FROM avg_pop;
Here is a small demo:
DEMO
When checking on other comments and answer I realized you need to give different aliases without '' and all will work...I have updated my answer and demo.
I need to display 'tax wage' column in US $ format IN SQL using FORMAT function.
I am using Microsoft SQL server. Can someone please help?
Getting error:
"Conversion failed when converting the nvarchar value '$17,037.72' to data type int."
Below is the query I wrote:
SELECT EMPLOYEE.ID, EMPLOYEE.NAME, P.DEDCODE,
SUM(CASE WHEN P.DEDCODE ='SS2' THEN FORMAT(P.AMOUNT,'C','EN-US') ELSE 0 END) AS 'TAX WAGE'
FROM EMPLOYEE
JOIN P ON EMPLOYEE.ID = P.ID and EMPLOYEE.COMPANY = P.COMPANY
WHERE
P.DEDCODE ='SS2'
AND P.YEAR ='2018'
GROUP BY
EMPLOYEE.ID,
EMPLOYEE.NAME,
P.DEDCODE
I expect the tax wage column to have $70.5 as output instead of simple number 70.5
Your format function should be on SUM():
FORMAT(SUM(CASE WHEN P.DEDCODE = 'SS2' THEN P.AMOUNT ELSE 0 END),'C','EN-US') AS [TAX WAGE]
You already included WHERE clause with P.DEDCODE ='SS2' then why you need conditional aggregation, it should be only
SELECT . . . ,
FORMAT(SUM(P.DEDCODE),'C','EN-US') AS [TAX WAGE]
. . .
So I have a CASE statement that I've Grouped. But, I was also trying to calculate the percentage of the total for each Grouped CASE result. When I run the commands I made below, it gives
Region Number Percentage
West Coast 11675 0
Not West Coast 104620 0
I don't understand why 'Percentage' comes as '0'.
Here's the code, with the 'problem line' labeled.
With [Summed Region] AS
(
SELECT
[State Province],
CASE [State Province]
WHEN 'Oregon' THEN 'West Coast'
WHEN 'Washington' THEN 'West Coast'
WHEN 'California' THEN 'West Coast'
ELSE 'Not West Coast'
END AS 'Region'
FROM
[WideWorldImportersDW].[Dimension].[City]
)
SELECT
Region,
count(Region) AS Number,
---THE PROBLEM LINE IS BELOW THIS---
count(region)/(select count(*) FROM [WideWorldImportersDW].[Dimension].
[City]) AS Percentage
FROM
[Summed Region]
GROUP BY
Region
What's the problem with that line? If I split out the two pieces, each returns the correct number. But when I divide one by the other I get '0'.
Thanks!
It is called integer division. So add a decimal somewhere:
SELECT Region, count(Region) AS Number,
count(region) * 1.0 / (select count(*) FROM [WideWorldImportersDW].[Dimension].[City]) AS Percentage
FROM [Summed Region]
GROUP BY Region;
You don't need the subquery either, so use window functions:
SELECT Region, count(*) AS Number,
count(*) * 1.0 / sum(count(*)) over () AS Percentage
FROM [Summed Region]
GROUP BY Region;
I'm trying to recreate a view in Tableau as a view in SQL. It requires me pivoting a table based on month and not only summing the amount but I also need to sum by margin and also create a Margin % row.The desired output is
BUSINESS_UNIT CLASS JANUARY FEBRUARY MARCH
202 Cost of Sales 100 (null) 60
202 Revenue 200 80 (null)
202 Margin x xx xxx
202 Margin % x% xx% xxx%
I can pivot based on Month but how do perform twos sums in one pivot table and how would I go about including a percenatge row also?
Code so far
SELECT
*
FROM
(SELECT
[Business_Unit]
,[Class]
,Month as Period
,[Amount]
--,Margin
FROM [sample_table]
where [Class] in ('Revenue','Cost of Sales') )AS T
PIVOT(SUM(Amount)
FOR Period IN ([January],[February],[March])) as Pvt
I have included my code so far http://www.sqlfiddle.com/#!3/06bafc/6
Not the prettiest SQL I've done. but this seems to work...
http://www.sqlfiddle.com/#!3/06bafc/60/0
What it does is build on what you've done by generating a margin line and adding a total column
Using this line and total we can then calculate the % of margin. Grouping SETS allowed me to generate the multiple rows, subtotals and totals, Since I knew the only additional line generated would have a null class, I was able to set the Name of the class to margin when null.
WITH CTE AS (
SELECT
Business_Unit
,case when class is NULL then 'Margin' else class end as Class
,Sum(January) as January
,Sum(February) as February
,Sum(March) as march
,Sum(coalesce(January,0)+coalesce(February,0)+coalesce(March,0)) as Total
FROM (
SELECT
*
FROM
(SELECT
[Business_Unit]
,[Class]
,Month as Period
,[Amount]
--,Margin
FROM [sample_table]
where [Class] in ('Revenue','Cost of Sales') )AS T
PIVOT(SUM(Amount)
FOR Period IN ([January],[February],[March])) as Pvt
) as Base
GROUP BY Grouping sets
((Business_Unit,Class,January,February,March,
coalesce(January,0)+coalesce(February,0)+coalesce(March,0))
,(Business_Unit)
))
SELECT *
FROM CTE UNION
SELECT Business_Unit
,'Margin %'
,January*100.00/Total
,February*100.00/Total
,March*100.00/Total
,Total*100.00/Total
FROM CTE
WHERE CLASS='Margin'