How to aggregate non numerical values on power bi? - powerbi

I have a matrix with numerical values assigned to securities ratings.
Let's say B- = 16 and B+ = 14, with both weighing 50% of the portfolio. In that case, the overall portfolio score would be 15 ((14 + 16)/2), which is assigned to a B rating.
How can I 'convert' back that 15 weighted average to a letter on the grand total?

Related

Converting text million value into number - power bi

I did a few steps in Power BI. I have annual revenue column with high values as 600000000 and more..so I converted this column with number values into new column with million values:
I created new column annual revenue in millions using formula: AnnualRevenue(Millions) = format('Reporting HubSpotCompanyCurrentValueView'[annualrevenue], "#,0,,") so I got values like: 1, 10, 716 etc. but all these values are text values not number so my question here how is it possible to convert into numeric values? I need to numeric value as I want to create range based on annual revenue and count values in specific range. When I'm trying to convert new column with million values I got error that it's not possible. Anyone can help me?
annual revenue
annual_revenue(millions)
100000000
100
2879430000
2879,43
Note that you are using different terms for the same thing:
"annual revenue" vs. "annualrevenue"
"annual_revenue(millions)" vs. "AnnualRevenue(Millions)"
In Power BI this would cause problems.
To convert your annual revenue to a number of multiples of millions you could use either expression:
Annual Revenue (Millions) as Number = 'Table'[annual revenue] / 1e6
Annual Revenue (Millions) as Number = VALUE('Table'[annual_revenue(millions)])

How to calculate average win rate among all the student using DAX in PowerBI

Hi everyone,
I have a sample data as shown in the screenshot above. There are 3 students with different ID : student 123, student 234, student 456. The profit column in the table is how much they earn in each trade.
Winning trade = profit > 0
Losing trade = profit < 0
Based on the definition above for the winning trade and losing trade, I want to calculate the average winning rate for all the students.
Student 123 - the winning rate is 50% (2 negative profit and 2 positive profit)
Student 234 - the winning rate is 33.3% (2 negative profit and 1 positive profit)
Student 456 - the winning rate is 100% (0 negative profit and 2 positive profit)
So, the final answer, average winning rate among all the students is:
(50% + 33.3% + 100%)/3 = 61.1%
61.1% is the final output that I want, then I will put this value into a Donut chart. I'm relatively new to DAX, any help or advise will be greatly appreciated!
Please paste text rather than images when providing sample data.
You shouldn't really add averages together like that but if that is definitely what you want, use Measure 2.
If you want a more traditional average to be calculated, use Measure 1.
Measure 1 =
VAR total = CALCULATE( COUNTROWS('Table'), ALLEXCEPT('Table','Table'[Student]))
VAR pos = CALCULATE(COUNT('Table'[Profit]), ALLEXCEPT('Table','Table'[Student]),'Table'[Profit] > 0)
RETURN pos/total
Measure 2 =
VAR students = CALCULATE(DISTINCTCOUNT('Table'[Student]), ALLEXCEPT('Table','Table'[Student]))
RETURN SUMX(VALUES('Table'[Student]), [Measure 1]/students)

DAX AVERAGE % SAVED IN A MATRIX FOR GROUP AND SUB-GROUP (ENTITY X USERS) Powerbi

I need the average % discount of a group of condominiums taking into account the following rule
Add the monthly average totals of discounts for each person, and divide by the total nr of months of all the people in the condominium, that is, if person A made transactions in 4 months, and B made it in 2 months, and C made it in 4 months, the total number of months is 10. So, to get the average, just take the accumulated total of the % saved and divide by these 10 months.
I have the correct average for people (sum of monthly averages, divided by the number of months), using the following DAX codes
Redução Tx do Usuário =
AVERAGEX(
KEEPFILTERS(VALUES('Dcalendario'[MesAno])),
CALCULATE([% ECONOMIZADO USUARIO])
)
where % user saved is the following DAX measure
% ECONOMIZADO USUARIO =
IF(
NOT(HASONEVALUE(clientes[Nome])),
AVERAGEX(
VALUES(clientes[Nome]),
[media economizado tx]
),
[media economizado tx]
where the average saved is the division of the penultimate column by the second, on 11.08.2021, the value is 0.10 divided by 325.00 = 0.10%
In the case of the image that I present to improve understanding, the % discount for Alcantara (condominium) is presented as 1.5%, when the correct one would be 1.12%
The total average of users, in this case, is 11.25%, divided by 10 months, which is the sum of the months in which transactions occurred by all users of this condominium, giving an average of 1.12%, the final objective is to have the average of each condominium and of the other condominiums that participate in the calculation, keeping the information of the average per user, and per month (both are already ok).
Value is wrong at condominium level
In this case, for the Alcantara calculation to be ok, I have to add the % of Aline + the % of Edevilson and 2 other people, which will total 11.25 and divide by 10 months (Aline's 4 months, Aline's 2 months Edevilson and 2 other people with 2 months each).
How should the DAX code be correct, so that the group total is ok, keeping the average number of people who are already ok?
And how can I get the total of these months (sum) to present on a card, I want the grand total of months of all transactions (sum of the months of each user).

Grand Total Value changing When Apply Any Filter In Power BI DAX

I am trying to do percentage of grand total. When i created the measure like
= Calculate(DistinctCount(ColumnName1),AllSelected(ColumnName2))
It gives me Overall Grand Total for that. But when i select perticular week then the Grand Total changes
For example rand Total is 23872
when i select week number from filter for week number 23 then it showing Grand Total 1232
I want to subtract the week number total from grand total i.e 1232/23872.
The 23872 this grand total should not change when apply any filter.

Calculating the average value for everything not selected

I'm having issues creating a measure which calculates the total average.
I have a total teams column (team a, team b, team c) and a goals scored column ( 1, 3, 2)...
I created a measure which computes the total goals scored (by date) of the selected team (selected via a filter), and I need to compare that against the total average goals scored (by date).
Measure for total goals
= CALCULATE([TotalGoalScored],ALLSELECTED(Teams[Teams]))
and the subsequent
AverageGoals Scored = AVERAGEX('Teams',[TotalGoalScored])
However, when I drag both of these values to a viz, and select a "team" both values are the same, (i.e. it is computing the average goals scored for only the selected team which = total goals scored). When I select "All" teams, the average is being computed correctly. What alternate formula can I use to computer average?
So the problem is in the "AverageGoals Scored" measure, which shouldn't be affected by team filter?
If so, how about like this:
AverageGoals Scored = CALCULACE(AVERAGEX('Teams',[TotalGoalScored]), ALL(Teams[Teams]))