how to change back color of rows in Grid control - gridcontrol

I am Using Devexpress Grid Control . i Just want to know how to change the back colour of some particular rows on load the data in grid .
e.g
like in this table Only Male User rows become Green and Female rows Yellows
User Class Gender
User1 7 Male
User2 7 Female
User3 7 Male
I want to know how this will be Accomplish?
Thanks

You can use the CustomDrawCell event (I believe) and check for the gender in the focused row, specific column. You can then set the back color (I believe the parameter e will contain the Appearance.BackColor) to the desired color.

Related

Wrong calculations for rows in Power BI matrix

I am trying to calculate market share, but struggling with doing it correctly.
I have a matrix where I have Category, Name as rows, Channel as column, and Market Share as value.
Also In my dataset I have columns ABS_COMPANY (with sales inputted there if company = "A", so there are some blank ones), and ABS_TOTAL (with sales inputted in each row)
so my measure Market Share:
Market Share = SUM(table\[ABS_COMPANY\]) / SUM(table\[ABS_TOTAL\])
This correctly calculates values for each Category, but when I open the drop-down to see Name, Market Share of each Name equals to 100%. What is the problem and how to fix it?
e.g. What is now:
Market Share
Pens 43%
pen 1 100%
pen 2 100%
pen 3 100%
Pencils 29%
penc 1 100%
penc 2 100%
penc 3 100%
I've tried using Calculate(), but it does not work in a way I want to.
Unfortunately, I cannot share the data as it is sensitive.
Structure of dataset:
NAME STRING
CATEGORY STRING
CHANNEL STRING
ABS_COMPANY DECIMAL(20,2) - value of sales for each name
ABS_TOTAL DECIMAL(20,2) - it is a value grouped by CHANNEL AND CATEGORY at the backend

How to deal with multiple ids multiple categories table to reach THIS on Power BI

I have a problem that i was trying to solve 3 days ago and i'm not able to.
I have the following tables:
Companies
company_id
sales
1
2000
2
3000
3
4000
4
1000
Categories
company_id
category
1
medical
1
sports
2
industrial
3
consumption
4
medical
4
consumption
All i want to reach is a COLUMN CHART with a CATEGORY SLICER where i choose the category and i see the TOP 5 companies by category and sales. Yes, in this example the TOP is not needed but in my real case i have 400 companies so i want to:
Select and Show only the required category.
In that category, show only the 5 better companies by sales.
The problem here is Power BI takes all the companies for the TOP N filter so if i choose a category, and also try a top 5, if the companies are not in the TOP5 all companies list, it doesn`t show anything.
Thanks!
If you always want to show the same Top N values in your visual, you can use the filter pane to achieve that.
Below a walk through:
The to add the Top N filtering, I add the following:
It is in Dutch, so a little clarification:
I add a 'filter on this visual'
I selected Populairste N, which is Top N
And as a value I drag and dropped the maximum of sales.
Results:
Things to keep in mind:
You are using a many to many relationship, make sure that this is activated in the Power BI model.
Make sure the direction of filtering is from category to sales, otherwise the slicer will not work. It looks like this:

add a new column based on other columns in sas

I'm new to SAS and would like to get help with the question as follows:
1: Sample table shows as below
Time Color Food label
2020 red Apple A
2019 red Orange A,B
2018 blue Apple A,B
2017 blue Orange B
Logic to return label is:
when color = 'red' then 'A'
when color = 'blue' then 'B'
when food = 'orange' then 'B'
when food = 'apple' then 'A',
since for row 2, we have both red and orange then our label should contains both 'A,B', same as row 3.
The requirement is to print out the label for each combination. I know that we can use CASE WHEN statement to define how is our label should be based on color and food. Here we only have 2 kind of color and 2 different food, but what if we like 7 different color and 10 different food, then we would have 7*10 different combinations. I don't want to list all of those combinations by using case when statement.
Is there any convenient way to return the label? Thanks for any ideas!(prefer to achieve it in PROC SQL, but SAS is also welcome)
This looks like a simple application of formats. So define a format that converts COLOR to a code letter and a second one that converts FOOD to a code letter.
proc format ;
value color 'red'='A' 'blue'='B';
value food 'Apple'='A' 'Orange'='B' ;
run;
Then use those to convert the actual values of COLOR and FOOD variables into the labels. Either in a data step:
data want;
set have ;
length label $5 ;
label=catx(',',put(color,color.),put(food,food.));
run;
Or an SQL query:
proc sql ;
create table want as
select *
, catx(',',put(color,color.),put(food,food.)) as label length=5
from have
;
run;
You do not need to re-create the format if the data changes, only if the list of possible values changes.

Calculate Total male Total Female in powerbi report

I want to count the total number of males and females in a powerbi report
eg.
Name Gender
std1 Female
std2 Male
std3 Female
std4 Male
std5 Male
std6 Male
The result I want is:
Female 2
Male 4
To get the results you are looking for, follow these steps:
Make a second table using the New Table button with the following code:
GenderCounts = DISTINCT(TableName[Gender])
Make a relationship from the newly create table back to the original table
Add a new column to the GenderCounts table with the following code:
Count = COUNTROWS(RELATEDTABLE(TableName))
And there you have a second table containing the counts of each gender.
For more information and other possibilities, check out a related Power BI Community forum post here and Stackoverflow questions here and here.

Transpose keeping all combinations of multiple values for id variable in SAS

I want to transpose a table from long to wide but I have more than one value for each Key. I want the transposed table to have one line for each combination of Id and Key, so for this example item, I'd have 8 lines after transposition. The Id variable would be preserved, each distinct Key would be all combinations of different values for the same key. So 2 * 2 * 1 * 1 * 1 * 2 = 8 lines.
data grades;
input Id Key $ Value $;
cards;
219381 Category Something
219381 Category Another
219381 Color White
219381 Color Black
219381 Sport Football
219381 Gender Male
219381 Size Big
219381 Quality Good
219381 Quality Bad
;
run;
This is what I want to come out after this complex transposition:
Id Category Color Sport Gender Size Quality
219381 Something White Football Male Big Good
219381 Something White Football Male Big Bad
219381 Something Black Football Male Big Good
219381 Something Black Football Male Big Bad
219381 Another White Football Male Big Good
219381 Another White Football Male Big Bad
219381 Another Black Football Male Big Good
219381 Another Black Football Male Big Bad
Any ideas how I can achieve this?
I've tried many things without success.
To me this looks like you want a cartesian product for different keys that are stored in one table. While not very SAS-like, one way you can get the result you're looking for is by using PROC SQL with joins on the same table, simulating individual tables for these different key types.
PROC SQL;
CREATE TABLE grades_combos AS
SELECT DISTINCT
g.id, category.value as category, color.value as color, sport.value as sport,
gender.value as gender, size.value as size, quality.value as quality
FROM grades g
INNER JOIN grades category ON category.id = g.id AND category.key = 'Category'
INNER JOIN grades color ON color.id = g.id AND color.key = 'Color'
INNER JOIN grades sport ON sport.id = g.id AND sport.key = 'Sport'
INNER JOIN grades gender ON gender.id = g.id AND gender.key = 'Gender'
INNER JOIN grades size ON size.id = g.id AND size.key = 'Size'
INNER JOIN grades quality ON quality.id = g.id AND quality.key = 'Quality'
ORDER BY id, category, color, sport, gender, size, quality
;
QUIT;
You could probably make this more flexible and generic, perhaps wrapping this in a macro that generates the JOIN statements based on an arbitrary set of keys.
From the top of my head, I can think of the following two approaches:
Use a by-statement? (requires sorted data)
Create a third variable which is the concatenation of the other 2
variables and use that one.