I haven't found anything on this, but maybe someone has an idea.
I want to calculate the running total of an amount, and then get a measure that allows to show it per month. This then should be multiplied by a value for that month.
The data I have is looking like this:
Now i want to get as result:
So, sum up the amounts and then calculate it with this months value. Is this possible as a measure?
Thanks in advance for any help!
Here is one way to do it:
//amount_total measure calculates total amount
amount_total = SUMX(data, data[amount])
//value_total measure calculates total value
value_total = SUMX(data, data[value])
//amount_rt measure calculates running total multiplied by value
amount_rt =
VAR cur_date = MAX(data[date])
VAR rt = CALCULATE(
[amount_total],
FILTER(
ALL(data),
data[date] <= cur_date
)
)
RETURN rt * [value_total]
Result:
Related
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
I have calculated measures for total Hrs and quantity with that I calculated (Hrs/Qty), and now I need to calculate running total of that.
Expected result: 6.18,7.52 and so on. But it's giving incorrect result. What's is the correct Dax formula? Can we calculate rolling total for calculated measure?
Power BI has a Quick Measure Running Total that is provided for exactly this purpose. And of course, you can also use Measures as Base Value for the calculation.
Please try this measures to achieve your goal:
% Of HR = SUMX(YourTable,DIVIDE([HR],[Qty]))
Rolling Total = CALCULATE(
[% Of HR],
FILTER(
ALL(YourTable[Week End Date]),
YourTable[Week End Date] <= MAX(YourTable[Week End Date])
)
)
If we test our measure on a visual:
I have a measure, an SMA (Simple Mobile Average), and I need to calculate the MAX of it.
It should be simple, but I can't find what am I doing wrong.
In my case I have a table (allDataCSV). Each row represents an event, and it has a DATE. I can calculate the num of events that occur in when filtering the table (just count rows):
Count = COUNTROWS()
And my SMA is calculated this way:
CountSMA5Days = AVERAGEX(
DATESINPERIOD(allDataCSV[Day],LASTDATE(allDataCSV[Day]),-5,DAY),
[Count])
I want to calulate the MAX value of [CountSMA5Days]. It is a measure, not a field, so I cant use MAX. I have tried MAXX, with no luck:
MaxSMA = MAXX(allDataCSV,[CountSMA5Days])
It returns me '1', and I suppose it is because it evals row by row, and, in ths case, [CountSMA5Days] returns an average of 5 'ones'
Could you help me, please?
Thanks!
EDIT:
Thans to #Mik, who guided me to solution. The right meassure is:
MaxSMA = MAXX(
all(allDataCSV[Day])
,[CountSMA5Days]
)
That's it!!!
The problem with your measure can come from CALCULATE() that you get by enclosed measure.
I mean your measure MaxSMA = MAXX(allDataCSV,[CountSMA5Days]) DAX converts to MaxSMA = MAXX(allDataCSV,CALCULATE([CountSMA5Days])). So, all data in rows filters your measure. Try the same trick as you did with AVERAGEX()
MAXX(
DATESINPERIOD(allDataCSV[Day],LASTDATE(allDataCSV[Day]),-5,DAY)
,[CountSMA5Days]
)
I believe that DAX will convert it to
MAXX(
DATESINPERIOD(allDataCSV[Day],LASTDATE(allDataCSV[Day]),-5,DAY)
,CALCULATE(
AVERAGEX( -- your measure
DATESINPERIOD(
allDataCSV[Day]
,LASTDATE(allDataCSV[Day]) --= date from current iteration of MAXX
,-5
,DAY
)
,CALCULATE([Count])
)
,allDataCSV[Day]= date from current iteration
)
)
I didn't check the measure. Hope you'll manage to fix the issue.
i have a problem regarding my calculation. I want to visualize the running total over time (for example 01.07 after hours rounded to the nearest half hour to reduce computing power). I have 90 days of data in my dataset. The Problem i have is that the calculation for the dates long time ago (for example 01.12.2021) are super fast and the calculation for recent dates (05.07.2022) are super slow. I think that the measure calculates the running total for the whole column and then the date filter will be applied, which caused the extreme long calculation time for recent dates. Every day has the same amount of rows. Any idea how i can tell the measure to calculate the running total only for the selected date/date which i picked in my filter?
I used the following measures:
Average Sales =
'Measure Table X'[RT Sales] / 'Measure Table X'[RT Rows]
RT Sales = CALCULATE(
Sum('X'[Sales]),
'X'[Time rounded] <= Max('X'[Time rounded]))
RT Rows = CALCULATE(
COUNTA('X'[Time rounded]),
'X'[Time rounded] <= Max('X'[Time rounded]))```
I'm not sure what you are going to achive, but you can try this, this can work faster.
Average Sales =
CALCULATE(
DIVIDE('Measure Table X'[RT Sales] , 'Measure Table X'[RT Rows])
'X'[Time rounded] <= Max('X'[Time rounded]
)
RT Sales = Sum('X'[Sales])
RT Rows =COUNTA('X'[Time rounded])
Hi everyone,
I'm still new to PowerBI, right now I have a set of data in PowerBI as shown in the screenshot above. I have a Measure to calculate the % of OK:
total_student = COUNT(StudentAns[Name])
ok_% =
VAR OK_COUNT = COUNTROWS(
FILTER(
StudentAns,
StudentAns[Answer] = "OK"
)
)
RETURN (OK_COUNT/StudentAns[total_student])
I created a Matrix to show the % of OK for each month as shown in the screenshot below:
What I want to find is the average percentage for all the months. So the final output answer should be 89.05%, which is the average of 85.95%, 91.4%, 89.27% and 89.58%.
The reason I want to get the average percentage of OK across all the months is because I want to use the output as a Target Goals for KPI visualization.
Any help or advise will be greatly appreciated!
You can add one more measure to the matrix as follows:
ok_2 % =
IF(
HASONEVALUE( 'StudentAns'[Month] ),
[ok_%],
AVERAGEX(
VALUES( StudentAns[Month] ),
[ok_%]
)
)
It calculates your original measure for each month, but for the Totals it returns the average of results of your measure.
HASONEVALUE returns True if there is only one distinct value in the filtered context; VALUES - creates a list of unique values; AVERAGEX - calculates the average of a set of expressions evaluated in each row.