Measure to calculate average - powerbi

Okay, so I have this dataset.
What I want to do is checking the average number of attempts a student has to take to get to a 6 or higher. So far I came up with:
Students = CALCULATE(DISTINCTCOUNT(StudentResults[studnr]);StudentResults[result]>=6)
Which is how many students passed each class. In SQL, I'd use a Group By and a Having Max. How can I implement this in a measure in Power BI?

To calculate the average number of attempts a student needs to achieve a successful result (>=6) for a course, we need to divide the total number of attempts by the number of succesful attempts.
When counting the total number of attempts, we need to discard the attempts that have not yet led to a successful result, because you cannot count the number of attempts it took to achieve a successfull result if this succesfull result has not been achieved yet.
So the pseudo formula is AVG #Attempts = (all attempts - #No Success Yet) / #Successful Attempts
These are the three base measures:
All Attempts = COUNTROWS ( 'StudenResults' )
#Succesfull Attempts = COUNTROWS ( FILTER ('StudenResults', 'StudenResults'[result] >= 6))
#no succes yet =
SUMX (
'StudenResults',
CALCULATE (
IF ( MAX ( 'StudenResults'[result] ) < 6, 1, 0 ),
ALLEXCEPT ( 'StudenResults', StudenResults[studnr], StudenResults[course] )
)
)
This measure calculates the requested average:
AVG #Attempts = DIVIDE([All Attempts] - [#no succes yet], [#Succesfull Attempts], BLANK ())
A matrix visual, with [course] on Rows and the measures on Values, would look like this:
If you want the average for each student, just put [studnr] on Rows in stead of [course]

Related

How to calculate the cumulative total of an average (calculated column)

I'm having a hard time to calculate the running / cumulative total of average values...
My idea is to emulate a sales campaign for a product that never had one, using the average by day of all the products from an specific brand; problem is the code I made is only repeating the numbers from the average, it's not summing them up:
This is how it's now:
This is how it should be:
I managed to filter the values I want to calculate the average for, and that's for an specific brand (this is not going to be replicated to all products, and in the end I want to merge this in another calculated column which will calculate the goal for all the products (including the exception, which are the ones that never had a sales campaign before).
here's the code for the average:
AllPlutoProductsAverage = MAXX(FILTER('f_Leads(teste2)', [percentage] = EARLIER(d_CT_Leads_RT[percentage]) && 'f_Leads(teste2)'[group_name]="Pluto"), 'f_Leads(teste2)'[registers_per_day] )
And here's the code for the cumulative/running total column:
VAR _NoCampaign_RT =
CALCULATE(
MAX( 'd_CT_Leads_RT'[AllPlutoProductsAverage ] ) ,
FILTER( 'f_Leads(teste2)' ,
AND( 'f_Leads(teste2)'[group_name] = d_CT_Leads_RT[group_name] ,
'f_Leads(teste2)'[course] = d_CT_Leads_RT[course]
) &&'f_Leads(teste2)'[course_closed_percentage] = d_CT_Leads_RT[percentage]
)
)
Any ideas on how I fix that...?
Thanks in advance!! :))
I tried:
quick measure for running totals, didn't work
custom code for running totals, still repeated the values
creating a separate measure for average and then mentioned it on the column's running total code, same result
tried building up a running total code by adding the average calculation into it as a variable, didn't work either
tried exporting the calculation to a measure, didn't work either
And by 'didn't work' I mean the column No_PreviousCampaign still shows the repeated values from AllPlutoProductsAverage

Cumulative running total based on count PowerBI measure

I'm trying to create a chart with 3 informations:
Total cases
% of total per day
cumulative % running total
The first two informations are working, but I can't make the third one work, my chart look like this
And I need it to look like this
Basically, the upper line is a cumulative sum of the lower line, the problem is that the values of the bars are just a count on my table and the lower line I made using the PowerBI function "Show as % of total"
I've tried googling but no luck with this one, tried this measure but didn't work:
Running Total MEASURE =
CALCULATE (
COUNT ( 'Primes Encerrados'[Nome Cliente] ),
FILTER (
ALL ( 'Primes Encerrados' ),
'Primes Encerrados'[Data] <= MAX ( 'Primes Encerrados'[Data] )
)
)
Use a the Quick Measure feature to get your running total formula:
Power BI will generate this formula for you:
Primes encerrados running total in Dias =
CALCULATE(
SUM('Geral'[Primes encerrados]),
FILTER(
ALLSELECTED('Geral'[Dias]),
ISONORAFTER('Geral'[Dias], MAX('Geral'[Dias]), DESC)
)
)
Add the measure to your chart and show it as % of Grand Total like you did with the first line

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 )

How to Calculate measurement %sale Proportion in PowerBI

I'm newbie in PowerBI user.I create simple sale report and measurement. Like This :
My problem.In PowerBI show % calculate only Net sale and total rows but I need all % sale result like this :
Please suggest me how to solve this problem.This's my Code.
% to Sales = round(DIVIDE(
sum(DAILY_PNL_FF_TH_V2[VALUE]),
CALCULATE(sum(DAILY_PNL_FF_TH_V2[VALUE]),FILTER(ALLSELECTED(ERP_ACCOUNT[group_1]),ERP_ACCOUNT[group_1]="Net Sales")
))*100,2) &"%"
If you are trying to get the Percent of each group relative to Net Sales, then you can try something like below:
% to Sales =
VAR netSalesAmount =
CALCULATE (
SUM ( DAILY_PNL_FF_TH_V2[VALUE] ),
ERP_ACCOUNT[group_1] = "Net Sales"
)
RETURN
DIVIDE ( SUM ( DAILY_PNL_FF_TH_V2[VALUE] ), netSalesAmount )
Also, it is better to address formatting in the screen below so that the number is treated as a number rather than text. This is both for sorting and exporting the data. Also, it keeps the calculation simpler:

How to calculate cumulative Total and % in DAX?

This might be very simple...
I have the below summary table in Power BI and need to build a Pareto Chart, what I'm looking for is a way to create columns "D" and "E"... Thanks in advance!
The Count from column "B" is a measure I've created in PBI based on multiple filters. I've already tried some Calculate/Sum/Filter type of expressions with no luck.
My raw data looks like Image #2... I have the measures to build the summary table with the exception of column "I" - Running % - (for which I will also need the cumulative total of events per bucket).
Unfortunately, I haven't been able to successfully apply the calculations from DAXPATTERNS.
There is a well-known pattern for cumulative calculations in the DAXPATTERNS blog.
Try this expression for Running % measure:
Running % =
CALCULATE (
SUM ( [Percentage] ),
FILTER ( ALL ( YourTable), YourTable[Bucket] <= MAX ( YourTable[Bucket] ) )
)
And try this for Cumulative count measure:
Cumulative Count =
CALCULATE (
SUM ( [Count] ),
FILTER ( ALL ( YourTable ), YourTable[Bucket] <= MAX ( YourTable[Bucket] ) )
)
Basically in each row you are summing those count or percent values that are less or equal than the bucket value in the evaluated row, which produces the cumulative total.
UPDATE: A posible solution matching your model.
Assuming your Event Count measure is defined as follows:
Event Count = COUNT(EventTable[Duration_Bucket])
You can create a cumulative count using CALCULATE function, which lets us calculate the Running % measure:
Cumulative Count =
CALCULATE (
[Event Count],
FILTER (
ALL ( EventTable ),
[Duration_Bucket] <= MAX ( EventTable[Duration_Bucket] )
)
)
Now calculate the Running % measure using:
Running % =
DIVIDE (
[Cumulative Count],
CALCULATE ( [Event Count], ALL ( EventTable ) ),
BLANK ()
)
You should get something like this in Power BI:
Table visualization
Bar chart visualization
Note my expressions use an EventTable which you should replace by the name of your table. Also note the running % line starts from 0 to 1 and there is only one Y-axis to the left.
Let me know if this helps.