Is it possbile to restrict a Role in Dimension Data by allowing him to see only siblings in the parent-child Hierarchy?
Example Hierarchy:
EMEA 100
UK 50
London 30
Southampton 20
France 50
Paris 10
Lyon 40
To see only:
EMEA 100
UK 50
France 50
I've received the expected result with the following MDX statement
NONEMPTY(
descendants(
[Dim Branch Hierarchies].[Branch Hierarchy]
,,leaves
)
, (
[Measures].[GrantedHi]
,StrtoMember(
"([Dim Users].[Account Name].[Account Name].["+ Username()+ "])"
)
)
)
Related
The dataset I have is currently like so:
country
itemid
device
num_purchases
total_views_per_country_and_day
day
USA
ABC
iPhone11
2
900
2022-06-15
USA
ABC
iPhoneX
5
900
2022-06-15
USA
DEF
iPhoneX
8
900
2022-06-15
UK
ABC
iPhone11
10
350
2022-06-15
UK
DEF
iPhone11
20
350
2022-06-15
total_views_per_country_and_day is already pre-calculated to be the sum grouped by country and day. That is why for each country-day pair, the number is the same.
I have a Quicksight analysis with a filter for day.
The first thing I want is to have a table on my dashboard that shows the number of total views for each country.
However, if I were to do it with the dataset just like that, the table would sum everything:
country
total_views
USA
900+900+900=2700
UK
350+350=700
So what I did was, create a calculated field which is the average of total_views. Which worked---but only if my day filter on dashboard was for ONE day.
When filtered for day = 2022-06-15: correct
country
avg(total_views)
USA
2700/3=900
UK
700/2=350
But let's say we have data from 2022-06-16 as well, the averaging method doesn't work, because it will average based on the entire dataset. So, example dataset with two days:
country
itemid
device
num_purchases
total_views_per_country_and_day
day
USA
ABC
iPhone11
2
900
2022-06-15
USA
ABC
iPhoneX
5
900
2022-06-15
USA
DEF
iPhoneX
8
900
2022-06-15
UK
ABC
iPhone11
10
350
2022-06-15
UK
DEF
iPhone11
20
350
2022-06-15
USA
ABC
iPhone11
2
1000
2022-06-16
USA
ABC
iPhoneX
5
1000
2022-06-16
UK
ABC
iPhone11
10
500
2022-06-16
UK
DEF
iPhone11
20
500
2022-06-16
Desired Table Visualization:
country
total_views
USA
900 + 1000 = 1900
UK
350 + 500 = 850
USA calculation: (900 * 3)/3 + (1000 * 2) /2 = 900 + 1000
UK calculation: (350 * 2) /2 + (500 * 2) /2 = 350 + 500
Basically---a sum of averages.
However, instead it is calculated like:
country
avg(total_views)
USA
[(900 * 3) + (1000*2)] / 5 = 940
UK
[(350 * 2) + (500 * 2)] / 4 = 425
I want to be able to use this calculation later on as well to calculate num_purchases / total_views. So ideally I would want it to be a calculated field. Is there a formula that can do this?
I also tried, instead of calculated field, just aggregating total_views by average instead of sum in the analysis -- exact same issue, but I could actually keep a running total if I include day in the table visualization. E.G.
country
day
running total of avg(total_views)
USA
2022-06-15
900
USA
2022-06-16
900+1000=1900
UK
2022-06-15
350
UK
2022-06-16
350+500=850
So you can see that the total (2nd and 4th row) is my desired value. However this is not exactly what I want.. I don't want to have to add the day into the table to get it right.
I've tried avgOver with day as a partition, that also requires you to have day in the table visualization.
sum({total_views_per_country_and_day}) / distinct_count( {day})
Basically your average is calculated as sum of metric divided by number of unique days. The above should help.
This request might be asked many times but I have done a search last night to figure out but I came up with nothing.
I have three tables
Table A
ID
City
1
LA
2
NY
3
LV
Table B
ID
Job
11
Programmer
22
Engineer
33
Database Administrator
44
Cyber Security Analyst
Table C
ID
Job level
111
Junior
222
Associate
333
Senior
444
Director
Final table
ID
EmployeeName
City_ID
Job_ID
Level_ID
1000
Susie
1
11
333
1001
Nora
2
11
222
1002
Jackie
2
22
111
1003
Mackey
1
11
444
1004
Noah
1
11
111
I’d like to have a crosstab query using Microsoft Access that returns the following result ( based on city )
LA Table
Jobs
Junior
Associate
Senior
Director
Programmer
1
-
1
1
Engineer
-
-
-
-
Database Administrator
-
-
-
-
Cyber Security Analyst
-
-
-
-
How can I do it?
The best approach for this is always:
Create a "base" query that joins the base tables and returns all data columns that you will need for the crosstab query.
Run the crosstab query wizard using the "base" query as input.
I am working on a problem where I have the following table:
+----------+ | +------+ | +------------+
company_id | country | total revenue
1 Russia 1200
2 Croatia 1200
2 Italy 1200
3 USA 1200
3 UK 1200
3 Italy 1200
There are 3 companies in this table, but company '2' and company '3' have offices in 2 and 3 countries respectively. All companies pay 1200 per month, and because company 2 has 2 offices it shows as if they paid 1200 per month 2 times, and because company 3 has 3 offices it shows as if it paid 1200 per month 3 times. Instead, I would like revenue to be equally distributed based on how many times company_id appears in the table. company_id will only appear more than once for every additional country in which a company is based.
Assuming each company always pays 1,200 per month, my desired output is:
+----------+ | +------+ | +------------+
company_id | country | total revenue
1 Russia 1200
2 Croatia 600
2 Italy 600
3 USA 400
3 UK 400
3 Italy 400
Being new to SQL, I was thinking this can maybe be done through CASE WHEN statement, but I only learned to use CASE WHEN when I want to output a string depending on a condition. Here, I am trying to assign equal revenue weight to each company's country, depending on in how many countries a company is based in.
Thank you in advance for you help!
Below is for BigQuery Standard SQL
#standardSQL
SELECT company_id, country,
total_revenue / (COUNT(1) OVER(PARTITION BY company_id)) AS total_revenue
FROM `project.dataset.table`
If to apply to sample data from your question - output is
Row company_id country total_revenue
1 1 Russia 1200.0
2 2 Croatia 600.0
3 2 Italy 600.0
4 3 USA 400.0
5 3 UK 400.0
6 3 Italy 400.0
I need a calculated measure(SSAS MD) to calculate the percentage of count values.
I have tried below expression but I did not get the desired output.Let me know if I missing anything and I want to calculate the percentage of the age for the group by the car total:
( [DimCar].[Car], [DimAge].[Age], [Measure].[Count])/
sum([DimCar].[Car].[All].children), ([DimAge].[Age].[All], [Meaures].[Count])}*100
Below are the sample date values in cube:
Car Age Count
----- ----- -----
Benz 1 2
Camry 37
Honda 1 18
Honda 6 10
Expected output:
Car Age Count Percent TotalCount
----- ----- ----- ------ ----------
Benz 1 2 100% 2
Camry 37 100% 37
Honda 1 18 64.28% 28
Honda 6 10 35.71% 28
Forumula to calculate percentage:
18/28*100 =64.28%
10/28*100 =35.71%
Honda 1 18 64.28% 28
Honda 6 10 35.71% 28
with Member [Measures].[Total Sales Count]
as iif (isempty([Measures].[Sales]),NUll, sum([Model].[Modelname].[All].children ,[Measures].[Sales]))
Member [Measures].[Total Sales%]
as ([Measures].[Sales]/[Measures].[Total Sales Count]),FORMAT_STRING = "Percent"
select {[Measures].[Sales],[Measures].[Total Sales Count],[Measures].[Total Sales%]
}on 0
,non empty{[Car].[Carname].[Carname]*[Model].[Modelname].[Modelname]} on 1
from [Cube]
Output :
Car Model Sales Total Sales Count Total Sales%
Benz New Model 2 2 100.00%
Camry Old Model 37 37 100.00%
Honda New Model 18 28 64.29%
Honda Top Model 10 28 35.71%
Instead of "Age" attribute I have added "Model" dimension.
Below code get exact output which is expected.
enter image description here
My understanding is that for a particular car example honda, you want to divide by the total honda's irrespective of their Age. In this case 28. So for Age:six honda you use 10/28. Where as for Benz, since all Benz are Age: 1 you use 2.
Use the following code
Round(
(
( [DimCar].[Car].currentmember, [DimAge].[Age].currentmember, [Measure].[Count])
/
([DimCar].[Car].currentmember,root([DimAge]),[Measure].[Count])
)*100
,2)
Below is a similar example on adventure works
with member
measures.t as
(
( [Product].[Category].currentmember, [Delivery Date].[Calendar Year].currentmember, [Measures].[Internet Order Quantity])
/
([Product].[Category].currentmember,root([Delivery Date]),[Measures].[Internet Order Quantity])
)*100
select {[Measures].[Internet Order Quantity],measures.t}
on columns ,
non empty
([Product].[Category].[Category],[Delivery Date].[Calendar Year].[Calendar Year])
on rows
from [Adventure Works]
A table name player having some columns & data in the table are as follows:
**PID**|**PNAME**|**CITY**|**TEAM**|**SALARY**|**NO_OF_PENALTIES**
1001 ozil istanbul germany 500000 1
1002 messi madrid arsenal 500000 2
1003 ronaldo manc uk 600000 1
1004 puyol sussex germany 400000 3
1005 fabregas manchester uk 450000 2
1006 costa ankara turkey 400000 3
1007 beckham london uk 600000 2
This is the table.Write a query I want record if team name is "germany" & no_of_penalties=1 then I want to get the record.If team name is "uk" & no_of_penalties=2 then I don't want to get the record.
Mean according to the above records as per the query I want to get the record having pid=1001 & pid=1003.
But when I write the query as shown below:
select * from player where (team='germany' and no_of_penalties=1) or not (team='uk' and no_of_penalties=2) and team in ('germany','uk');
Then after execute above query the output looks like having pid=1001, 1003, 1004 as shown below
**PID**|**PNAME**|**CITY**|**TEAM**|**SALARY**|**NO_OF_PENALTIES**
1001 ozil istanbul germany 500000 1
1003 ronaldo manc uk 600000 1
1004 puyol sussex germany 400000 3
So could you please solve me the problem?
Try this one
select * from player
where (team='germany' and no_of_penalties=1)
or (team='uk' and no_of_penalties!=2)
Select * From Player Where
(Team = 'Germany' AND No_Of_Penalties = 1)
AND NOT
(Team = "UK" AND No_Of_Penalties = 2)
Forgive me if I am wrong as I find your question hard to understand clearly but you put "If team name is "uk" & no_of_penalties=2 then I don't want to get the record" meaning you dont want the value of 2 however the answer you selected will show those with value of 2
Try out
select * from player
where (team='germany' and no_of_penalties=1)
union all
select * from player
where (team='uk' and no_of_penalties!=2)
These are mutually exclusive data, so it should be with AND (not OR). Try this
SELECT *
FROM player
WHERE (
team = 'germany'
AND no_of_penalties = 1
)
AND NOT (
team = 'uk'
AND no_of_penalties = 2
)
AND team IN (
'germany'
,'uk'
) );