DIVIDE/AVERAGEX in PowerBI - powerbi

In my data model I have 12 months worth of employee data and month name is in the first column, I.e Jan, Feb Mar etc
I have been using the formula below but I have an issue,
Employee 101 has worked as a sole employee in one department
2 months out of the 12, my formula below will divide that 2/12 equaling =0.16. I want to return average headcount for the department as 1.
So only averaging for months greater 0 employees
DIVIDE(
AVERAGEX(
KEEPFILTERS(VALUES('Date Table'[Month])),
CALCULATE(COUNTROWS(Employee List),Employee List[Emp Status] = "Full Time")),,"")

So use roundup():
roundup(DIVIDE( AVERAGEX( KEEPFILTERS(VALUES('Date Table'[Month])), CALCULATE(COUNTROWS(Employee List),Employee List[Emp Status] = "Full Time")),,""),0)
But you might consider wrapping it in an if() so it only rounds up when the result is less than 1.

I was Averagex and Divide at the same time, removing divide fixed the issue.

Related

Why do i get the avrage of the subcategory and not the avrage of category per year?

When i drag in a tabel
and just have
-YEAR
-Kategory
-Summa
I will get the medium value of 895,50 (815 + 976 / 2) for february
I don't want it to separeate the Subcategory
I want it to show
1791
when i just mark february
and if i use February and March
It sould say
2022 Inköp 2435,5
Becouse that the Medium of February and Marsh on the category
It's difficult to understand what you are asking (likely the reason for your downvotes). I think you are after a monthly average measure. Since your sample data is extremely limited I assume that each month will have exactly one date. Ideally this type of calculation should be handled by using a calendar table as a basis for month values, but for your sample data, try this:
Monthly average =
AVERAGEX (
VALUES ( 'Table'[Datum] ) ,
CALCULATE ( SUM ( 'Table'[Summa] ) )
)

Calculate total variance in power bi with dax

I have 3 measures:
1) total_trx = SUM(mytable[trx])
2) trx_prev_month = CALCULATE([total_trx], DATEADD(calendar[date], -1,MONTH))
3) monthly_var = DIVIDE([total_trx],[trx_prev_month])-1
If I add a waterfall viz, x-axis with month, it gives me the % of monthly variation and a TOTAL bar at the end that sums all the variations.
I need to reproduce that total number in order to show a KPI as in "so far, we've increased ...%", changing when using a date slicer.
Seems like sum(monthly_var) is not allowed.
Any ideas?
Thank you very much.
Edit1: sample with date filter = Last 4 months
Jul 100 0%
Aug 110 10%
Sep 90 -20%
Oct 80 -10%
Total: -20% <- need a dax to calculate this number and show just -20%
Then if I change the filter to, for example LAST 6 MONTHS, I need to calculate it up to May
In order to get the desired result we will use an intermediate table in our query that will summarize the results by months:
use this code and replace calendar[Year Month] with your Year month column :
SUMX(
SUMMARIZECOLUMNS(calendar[Year Month],"Monthly_int_var",[monthly_var]),
[Monthly_int_var]
)

What AVERAGEX function does in this context?

I am trying to calculate monthly trend KPI over last 6 months. Whether it is positive or negative.
So I have columns: Current Month Premium, Previous Month Premium, Month Over Month
Then I am using AVERAGEX and DATESBETWEEN functions to find out whether trend is positive or negative.
WP 6M Trend =
VAR LastEffDate = LASTDATE(fact_Premium[EffectiveDate])
RETURN
AVERAGEX(
DATESBETWEEN(
dim_Date[Date],
DATEADD(STARTOFMONTH(LastEffDate), -5,MONTH), //creates rolling 6 months window [Ttl WP] and [PreviousMonthWP]
ENDOFMONTH(LastEffDate)
),
[MoM WP]
)
But I don't quiet understand how -72 exactly calculated here?
So I need to understand to know whether it is correct or not.
Your avergex is evaluating the last period in your dataset due the the fact that your LastEffDate calculates the last available date in a dataset or subset. As the total line refers to the entire context of all the data in your table, it computes the last date similarly to the last period you calculated, effectively the same calculation as the month august in this case.

Grand Total not working for sales per day last year function

I am trying to do a sales by day comparison where I compare the sales this year with the sales of the same day last year as a date of the week.
So I would be comparing Monday March 25 2019 with Monday march 24 2018 etc
Here is the formula I’m using for last year’s sale
Amount per Day LY = CALCULATE([Amount TY], FILTER(all(Dates), Dates[Date] = MAX(Dates[Date])-364))
However, my total isn’t working right for my sales last year. It will just be the total for 1 day (and that day seems to change as my date range increases)
Because you are having a one to one, you can do this with LookupValue:
SalesLY = LOOKUPVALUE(Sheet1[Sales];Sheet1[Date];DATEADD(Sheet1[Date];-364;DAY))
However if you have more rows for the same date, this will not hold, in this case you need to sum all the dates together,
SalesLY = CALCULATE(SUM(Sheet1[Sales]);FILTER(Sheet1; DATEADD(Sheet1[Date];364;DAY)= EARLIER(Sheet1[Date])))
Using DateAdd fixed my problem
Amt per Day LY = CALCULATE([Amount TY], DATEADD(Dates[Date], -364,DAY))

Rolling 3 months DAX

I have had a headache since yesterday with a measure.
My table is Data and in this table, I have a column Data[Date] which contains the first day of each month from January to June and a measure which calculates Total revenue.
I need a measure that calculates for June: Total REV = April + May + June.
I have tried this measure:
CALCULATE([TOTAL REV], DATESINPERIOD(Data[Date], LASTDATE(Data[Date]), -3, MONTH))
but in order to have the correct number I need to select all three months in the slicer, not just the month I am interested in.
When you've got just one date selected in the slicer the filter context for the CALCULATE is just that month.
So I suspect that something similar to the below would fix your issue as it would allow the CALCULATE to consider the whole date table:
CALCULATE([TOTAL REV], DATESINPERIOD( ALL(Data[Date]), LASTDATE(Data[Date]), -3, MONTH))
Try this:
sumx(DATESINPERIOD('Data'[Date], LASTDATE('Data'[Date]), -3, MONTH) , [TOTAL REV])