Calculate rolling total for calculated measure in powerBi - powerbi

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:

Related

DAX - RT Measure calculation based on specific selected date in slicer

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])

Power BI Calculate distinct impacting when I use filter

I made a measure that is as follows:
wo = CALCULATE(
DISTINCTCOUNT('Table1'[won]),
ALLEXCEPT(Table1, 'Table1'[flag]),
ALLEXCEPT(Calendar,Calendar[End of Week]),
FILTER(Table1,[flag]="Y")
)
I want the total amount of items in 'won' column with the flag = 'Y'. But when I use one date range filter [End of Week] I had problem because my total amount keeps changing and shouldn't change, I want the total of my entire table regardless of date.
This measure works without 'Y' flag, but it's not what I need:
wo= CALCULATE(
DISTINCTCOUNT('Table1'[wo]),
ALL(Calendar)
)
Could you please help me how to adjust this measure?
Solved using this DAX CODE:
wo= CALCULATE(
DISTINCTCOUNT('Table1'[won]),
FILTER(ALL(Table1),[flag]="Y")
)

Measure Not Totaling Correctly

I have a measure that is comprised of other measures. I will post below pictures. I am calculating the forecast for the month per location. I created a measure for that and the total is correct for that. I created another measure that calculates the working days in a month and when I divide by this measure, I get the correct results per the location but the total is wrong.
This measure shows the measure I am using to calculate the total forecast for the month per location.
"MPP = (CALCULATE(SUM('TF'[ Forecast ]), DATESBETWEEN ('TF'[Date],[Month Start-pp], [Month end_pp] )))"
This measure shows the measure I am using to calculate the working days in a month.
"Days per location =
CALCULATE (
COUNTROWS ( 'TF' ),
FILTER (
'TF',
'TF'[Date].[MonthNo] = MONTH ( TODAY () )
)
)"
The pic is showing the totaling. The first column is the measure without the division and is correct totaling. The second column is where the issue is.

How to calculate average percentage in PowerBI?

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.

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?