Power BI - Average Per Category - powerbi

I am brand new to Power BI, and I could use a bit of help. I have this sample data:
I then want to get the [Average Total Billed Per Profession], which I got using:
Then, ideally, I would [Total Billed]/[Average Total Billed Per Profession]. But when I drop it in a table, it breaks. On the left, are the values I would want in the calculation. On the right, the values I get:
How would I set up the calculation correctly? Any help is appreciated. Thanks.

To have the average per profession in a table where also the Name is present, it's necessary to remove the filter context over Name, so a possible solution is
Average Total Bille Per Profession =
CALCULATE(
AVERAGEX(
SUMMARIZE( StaticData, StaticData[Profession], StaticData[Name] ),
CALCULATE( SUM( StaticData[Price] ) )
),
ALLEXCEPT( StaticData, StaticData[Profession] )
)
The CALCULATE inside AVERAGEX is required to trigger a context transition to transform the row context on the StaticData columns to a the corresponding filter context, that's needed to filer the StaticData[PriceColumn] rows to be used in the SUM.

It looks like profession + name doesn't make each row unique. If you just want "Average Total Billed Per Profession", then you can use something like the following.
Average Total Bille Per Profession =
AVERAGEX(
VALUES( StaticData[Profession] ),
SUM( StaticData[Price] )
)
It's just making sure you're considering unique profession for the metric you're calculating.

Related

POWER BI Measure for dividing total sales by each person by total sales

I have made an measure for showing total sales by each person. I can't figure how to make an measure for dividing total sales by each person BY total sales. For example, for the person "bmo" I want to calculate 303/3153 and so on.
I have tried using the same measure as I use on "Totalt antall salg" and use the Show value as, but that just shows the correct value, and does not calculate it, and I need to use the number for later.
You can ignore filter context by using ALL to get total sales:
VAR _TotalSales =
CALCULATE (
COUNTROWS ( 'KasseJournal' ),
FILTER ( ALL ( 'KasseJournal' ),
'KasseJournal'[Hendelse] = "Bekreftet kasseekspedisjon"
)
)
RETURN DIVIDE ( [Totalt antall salg], _TotalSales, 0 )

DAX - Get list from a filtered SUMMARIZE formula

So, I have the following tables in my Power BI :
Sales : Date | ID_Client | ID_Product | Amount
Client : ID_Client | Name_Client
I would like to get the number of unique BIG clients in any given month. I therefore use the following formula (which I then put in a column in a table with months in rows):
# BIG Clients =
VAR threshold = 10000
RETURN
(
CALCULATE(
DISTINCTCOUNT( Sales[ID_Client] ),
FILTER(
SUMMARIZE(
Sales,
Sales[ID_Client],
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
)
)
QUESTION IS : how can I get the list of those BIG clients for any given month? Let's say I click on the November number of big clients in my table, could another table nearby display the list of those clients ?
Thanks in advance for your kind help, I've been trying for a while :)
I assume that you have a table of clients with the Name column with a one to many relationship with the Sales table and that you do not have duplicate client names. Then you may create a [BIG Sales] measure to be used in a table or matrix visual with client names on the rows.
since [BIG Sales] evaluates to BLANK() for clients with less that threshold sales, they are automatically filtered out from the visual
BIG Sales =
VAR threshold = 10000
VAR BigCustomers =
FILTER(
ADDCOLUMNS(
VALUES( Clients[Name] ),
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
RETURN
SUMX(
BigCustomers,
[Sales]
)
You could create a table or matrix visual with the client on the rows and use your measure in the values field. This will show 1 for all big clients and return blank for the rest (which should hide them). If you don't want to show the measure, you can set the value is 1 in the filter pane and remove the measure from the values field.
A more direct option is to use a simple SalesAmount = SUM ( Sales[Amount] ) measure in the values field and filter like this

Calculate percent of total considering applied filter

I would like to calculate Percentage value of total (same as inbuilt "show as -> percentage of grand total" but using DAX).
I have seen solutions
Percent of Total Windowed in Power BI DAX
and
Power BI DAX - Percent of Total Column with FILTERs
and
How to calculate Percentage out of Total value in DAX (Power BI Desktop)
but unfortunately all of them do not work for me (I get all rows filled with 100% for calculated column)
Idea is to have percetage of total but be able to apply date filter and see percent value of shown data, not entiry query
I tried as in above mentioned solutions:
Percentage =
DIVIDE(
SUM( All_Years[Price:] ),
CALCULATE(
SUM( All_Years[Price:] ),
ALLSELECTED( All_Years )
)
)
First of all I do not understand why do they take SUM in numerator. If I use just
Percentage =
DIVIDE(
All_Years[Price:],
CALCULATE(
SUM( All_Years[Price:] ),
ALLSELECTED( All_Years )
)
)
then situation looks better, I get percent value of total table in each row. But then when I apply date filter in Visual I see total 3.5% (which is correct if we consider full query and not slice that I got after applying filter)
Leaving ALLSELECTED blank also does not resolve the problem.
what am I missing?

How to Rank a Measure which is Average Field, Power BI

I am new in Power bi. I have a table where I have agents details. I have their scores as well. I have date wise data into table where the following columns are available -
I have created created measure for Average of Score where Metric is UES AGGREGATE -
I have to get the ranking of the advocate(s) for the Average Score (UES AGG). I have tried this measure for Ranking calculation -
Rank_UES = RANKX('RankSummary',[RKS_UESAGG])
I am getting wrong ranking. Please help me , how to solve the issue.
Thanking You.
Use ALL function with RANKX.
Rank_UES =
RANKX (
ALL ( 'RankSummary'[AgentfullName] ),
[RKS_UESAGG]
)
I do not know if your [RKS_UESAGG] get you what you want. Suppose you want average sales you make something like this:
Rank_UES =
RANKX (
ALL ( 'RankSummary'[AgentfullName] ),
AVERAGE ( 'RankSummary'[Amount] )
)
https://learn.microsoft.com/en-us/dax/rankx-function-dax

If a exists pick a else pick b power bi

I have forecast and budget values for the year, and a new forecast is created every quarter. I need PowerBI to pick up the Metric Value (can be Budget, Q1F, Q2F and Q3F) for a given date based on data availability.
Example - If for a given date, data for Q3F is available, pick Q3F, else pick Q2F else Q1F else budget.
This is what my data looks like:
Date Metric Value
1/1/11 Budget 1.1
1/1/11 Q3F 1.2
1/1/11 Q2F 1.3
In this case the function should pick up Q3F since it's available.
One way to solve this would be by using both a SUMX and a SWITCH Statements.
To start with assign a constant to your forecasts, e.g. budget = 1, Q1F = 2 and so on as a column on your data. The idea more recent forecast will have a higher number, it will be used in the switch statement late. I am going to refer to it as forecast_ID in this example.
I am also assuming you have a calendar table, also that your forecasts are entered in entirely for the business and not in waves. E.g. Category A is still on budget, Category B is an updated forecast.
The idea of below, is that the SUMX iterates though each quarter that you are looking at, e.g. 2018 would run Q1, Q2, Q3, Q4 separately.
Within the context of each quarter, it is getting the MAX of your forecast IDs, which is then used in the switch to select the most recent forecast.
Measure :=
SUMX (
VALUES ( Calendar[Quarter] ),
SWITCH (
MAX ( table1[forecast_ID] ),
1, CALCULATE ( SUM ( table1[value] ), table1[Metric] = "Budget" ),
2, CALCULATE ( SUM ( table1[value] ), table1[Metric] = "Q1F" )
)
)
You could also then do something like MAX ( table1[forecast_ID] - 1) for finding the previous forecast dynamically.
If you always want to pull the most recent value then you can use LASTNONBLANK
As Marcus mentioned, the first step is to create a constant for your forecasts. I set up a separate table for this example.
Then you can create a relationship between the two tables based on Metric. Add a calculated column to your original table
MetricConstant = RELATED(Table2[Constant])
Now create a measure to pull the most recent value within each date period
Measure =
SUMX (
VALUES ( Table1[Date] ),
CALCULATE ( SUM ( Table1[Value] ), LASTNONBLANK ( Table1[MetricConstant], 1 ) )
)
Now when you pull in the Date and the Measure it will only show you the most recent available
EDIT-Updated based on comments. If you want to view which Metric is being used you need another measure
MetricMeasure = CALCULATE(MAX(Table1[Metric]),LASTNONBLANK(Table1[MetricConstant],1))
You could create an area chart based on that, and add this to the tooltip.