How to calculate average of a measure using Dax in power BI - powerbi

In power bi, I created a measure to calculate the daily average of each department head. I got an error. First I used this formula. I got an error message like
'column is not found in query1'
.
AvgBydepartmentHead =
DIVIDE(
SUM(TableName[Total]),
SUM(TableName[Days worked])
Then I used the other formula
AvgBydepartmentHead =
DIVIDE(
SUM([Total]),
SUM([Days worked])
Got error like
The sum function only accepts column reference as the argument 1
Both Total and days worked are measures.
[1]: https://i.stack.imgur.com/1kv5b.png
How to resolve this issue. Thanks

Not sure what you mean with "calculated fields", but if they are Measures you don't need an additional aggregation, the following should work:
AvgBydepartmentHead = DIVIDE( [Total], [Days worked] )
It's also unclear what the message 'table is not found in query1' has to do with your problem.

Related

Power BI Dax Measure moving Sum by categories

im struggling with the following problem. I have categorical variables and and Amount column. What I want to do is, to write a dax measure which calculates the moving/rolling Sum, like you see in the third column "Dax Measure". Did not find any inhouse Dax function for that.
moving sum
EDIT:
Result Table with Dax Measure
Source Table
This will work if the category is always sorted ASC.
Dax measure =
VAR _currentRank = RANKX(ALL('Table'[Category]),CALCULATE(MIN('Table'[Category])),,ASC)
RETURN
CALCULATE(
CALCULATE(SUM('Table'[Amount]),TOPN(_currentRank,VALUES('Table'[Category]),MIN([Category]))),
ALL('Table'[Category])
)
Using RANKX to define the other and aggregating for all the item before it.

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

DAX - Grand Total not adding up to Row Total

I have a powerbi report which is running a dax formula to calculate a custom measure. In the picture below, the total at the bottom doesn't seem to add up to the individual rows. I've been trying my luck for some time and can't seem to figure out why this is.
The DAX formula used is as follows
SumRest<24hrs7Day = CALCULATE(
DISTINCTCOUNT(WorkTimeDirective[EmployeeKey]),
FILTER(
ADDCOLUMNS(
SUMMARIZE(WorkTimeDirective,Employee[EmployeeKey],'Date'[DateKey]),
"totRestHrs", CALCULATE(MAX(WorkTimeDirective[RestHours])
,DATESINPERIOD('Date'[DateKey], LASTDATE('Date'[DateKey]), -7, DAY))
),
[totRestHrs]<24
),
WorkTimeDirective[IsEmployeeAbove18]=1
)
Any idea why this is and what I am doing wrong.
For using SUMX the main step is listing the values which you are iterating over, which it typically a table or column. In this case it sounds like you would do a column.
For the example I just had it call the measure you already defined, since breaking DAX calculations into smaller pieces makes writing/testing complex formulas easier.
The idea being that it would iterate over the unique values which are in your TableName[Site Name], then run the [SumRest<24hrs7Day] under that context. I used TableName for the table due to not knowing the name for the table.
SUMX_Example = SUMX( VALUES( TableName[Site Name], [SumRest<24hrs7Day])

DAX SUM previous period integer value

This issue seemed to be easy at the first glance but I have been trying to solve it for a while.
enter image description here
I would like to dynamically sum the previous period sales in a power pivot measure. The thing is that my period column is a integer value not a date.
I manage to calculate the previous period but I did not manage to set it up as a filter value:
Max(Table1[Period])-1 --> this gives me the previous value of the period field
However when I want to add this as a filter of a calculated measure it doesn't work: --> Calculate(
Sum(table1[Sales]), Filter(table1,Max(table1[Period])=Max(table1[Period])
)
I tried simply this one as well: Calculate(Sum(table1[Sales]), table1[Period] = table1[Period] -1 )
but neither of them are working. I though that I do it with calculated column however I would rather do it with measure.
Can you please help me?
Expected result:
Create measure:
Previous Sales:=
CALCULATE( SUM(Table1[Sales]),
FILTER( ALL(Table1), Table1[Period] = MAX(Table1[Period]) - 1))
It will give you dynamic previous sales. Please note: it relies on the fact that periods increment by 1.
If you need to summarize Previous Sales, create a second measure:
Total Previous Sales:=
SUMX( VALUES(Table1[Period]), [Previous Sales])

DAX formula for calculating yesterday's Turnover?

I'm working with POWER BI to develop a commercial dashboard.
The formula I came up with to calculate the previous day's Turnover is giving me blank results :
TRNV_D-1 = CALCULATE(SUM(FACT_SALES[TRNV]) ; PREVIOUSDAY(DIM_TIME[DATE]))
there is nothing wrong with the syntax .
PS: DATE is the PK of the dimension TIME .
I would replace the 2nd parameter of CALCULATE with something like this:
FILTER(FACT_SALES , NEXTDAY(DIM_TIME[DATE]) = TODAY())
I reversed the logic because PREVIOUSDAY and NEXTDAY require a column of dates as their parameter.
Maybe it's just me, but I often find DAX totally counterintuitive ...