I have a table (TABLE1) similar to this:
DATE
VALUE
01/01/2022
4
01/01/2022
3
01/01/2022
5
01/01/2022
8
02/01/2022
9
02/01/2022
8
02/01/2022
7
02/01/2022
3
I would like to calculate for each day the average value excluding the values that are less than the general average.
For example, for the 01/01/2022 the average is (4+3+5+8)/4 = 5 and the value that I want to calculate is the average excluding the values undder than this average (5+8)/2 = 6,5
Hope you can help me with a measure to calculate this.
Thanks!!
Test this measure:
AverageValue =
VAR AllAverage = CALCULATE(AVERAGE(TestTable[VALUE]),ALLEXCEPT(TestTable,TestTable[DATE]))
VAR TblSummary = ADDCOLUMNS(
VALUES(TestTable[DATE]),
"AvgValue",CALCULATE(AVERAGE(TestTable[VALUE]),TestTable[VALUE]>=AllAverage)
)
RETURN
AVERAGEX(TblSummary,[AvgValue])
Related
This data
Row_ID EmployeeID Date
1 1 2023-02-13
2 2 2023-02-13
3 3 2023-02-13
4 1 2023-01-13
5 8 2023-01-13
6 7 2023-01-13
7 4 2023-01-13
8 5 2023-01-13
9 6 2023-01-13
and a DATE table
I use a Measure
_DistinctEmployee = DISTINCTCOUNT(tblTestEmployee[EmployeeID])
And a Messure for the DATESTYD
_DATESTYD = CALCULATE([_DistinctEmployee],DATESYTD(vwDimDatum[Datum2]))
Image for date choise and table
The end result i want on the measure (NOT drag in MONTH in the table)
Is that the datestyd take the distinct numbers of employee (Becouse in the real scenarie there can be more then one employee that month)
and then + that month with the next month and then + it to the next month thats accumulated
and then take al this addition of values and devide it with the number if the month thats choisen.
Example of the data
I have choisen MONTH Febuary
In my measure i get the number 8 and thats the distinct accumulated employees in JAN and FEB and if i devide that with the number of the month i get 4 and that wrong that no the avrage.
there is 3 distinct employee in January
and there is 6 Distinct employee in Febuary
3+6 / 2(Febuary) = 4,5
Thats the average of employees in al this month.
Try the following measure:
=
VAR DateChosen =
MIN( vwDimDatum[Datum2] )
VAR T1 =
SUMMARIZE(
FILTER( ALL( vwDimDatum ), vwDimDatum[Datum2] <= DateChosen ),
vwDimDatum[Datum2],
"Distinct Employees", [_DistinctEmployee]
)
RETURN
AVERAGEX( T1, [Distinct Employees] )
I have these columns and I want to create a measure to calculate the number of types
types
ID Type
1 A
2 A
3 B
4 C
5 D
6 A
7
8
Results :
A 3
B 1
C 1
D 1
Blank 2
Try this Calculated Table:
Results =
SUMMARIZE(
'Table',
'Table'[Type],
"Count", COUNT('Table'[ID])
)
Need help in creating measures that will reflect the actual count of rows in the table when filtered.
Example:
ID
RankC
RankA
Avg Diff
RankC_count
RankA_count
Avg Diff_count
1000
AAA
XYZ
+01.00 to +01.25
5
6
4
1001
AAA
ZY1
+01.5.00 to +01.75
5
1
5
1002
AAB
XYZ
+01.5.00 to +01.75
3
6
5
1003
AAB
ZY2
+01.5.00 to +01.75
3
1
5
1004
AAB
XYZ
+01.00 to +01.25
3
6
4
1005
AAA
XYZ
+01.00 to +01.25
5
6
4
1006
AAA
ZY3
+01.00 to +01.25
5
1
4
1007
AAC
XYZ
+01.25.00 to +01.5
1
6
2
1008
AAA
ZY4
+01.25.00 to +01.5
5
2
2
1009
AAZ
ZY4
+01.5.00 to +01.75
1
2
5
1010
ABY
XYZ
+01.5.00 to +01.75
1
6
5
The last 3 columns represent the count of each entry. If I use the measure such as below, it provides the correct count. However, when I use in the visual, filtering by ID, say ID 1000, I want it to show line 1 with 5,6, and 4 on the counts, instead of all 1.
Questions:
Is there any measure to give me the correct result? say summarize the table first then do a lookup?
is creating a column the only choice? I cannot create columns since I need 1000 of these calculated columns. whereas using measure, I can create 1000 in one go.
Thanks for any help.
AverageDiff_Count =
CALCULATE (
COUNTROWS (
FILTER ( '28Jun_1973', [Average Diff] = '28Jun_1973'[Average Diff] )
)
)
The ALL function is useful here. It removes filter context so that it uses the whole table instead of just the part in the current filter context.
AvgDiff_Count =
VAR CurrAvgDiff = SELECTEDVALUE ( '28Jun_1973'[Avg Diff] )
RETURN
COUNTROWS (
FILTER ( ALL ( '28Jun_1973' ), '28Jun_1973'[Avg Diff] = CurrAvgDiff )
)
Given a table FACT in Power BI with three columns Date, Category and Sales I am looking for a DAX function that for each day returns the sum of the sales of its previous n days.
Lets assume n = 2, that means for day 01/04/2020 my measure should return the sum of the sales of the days 01/02/2020 and 01/03/2020.
Here is a small example:
Date Category Sales
01/01/2020 A 1
01/01/2020 B 3
01/02/2020 B 2
01/03/2020 B 1
01/04/2020 A 0
01/05/2020 B 10
01/06/2020 B 7
What I want is
Date MyMeasure
01/01/2020 0
01/02/2020 4
01/03/2020 6
01/04/2020 3
01/05/2020 1
01/06/2020 10
I later would then like to use the Category as a filter and in my case n is 365.
I tried the following
MyMeasure =
VAR FROM_DATE =
DATEADD ( FACT[DATE], 0, DAY )
VAR SALES_365 =
CALCULATE (
SUM ( FACT[SALES] ),
DATESINPERIOD ( FACT[DATE], FROM_DATE, 365, DAY )
)
RETURN
SALES_365
but got an error that a table of multiple values was supplied where a single value was expected.
The error was in the variable FROM_DATE, in which DATEADDD returned a column of dates and not a single value.
That said you don't really need a variable for that, you can just use a simple subtraction and DATESBETWEEN(DateCol, DateFrom,DateTo)
MyMeasure =
CALCULATE (
SUM ( FACT[SALES] ),
DATESBETWEEN('FACT'[DATE],MAX(FACT[DATE])-2,MAX(FACT[DATE])-1)
)
I am new to Power BI and the language DAX. Therefore, I find it hard to do simple yearly average across different products.
I have tried a different combination of the functions AVERAGEX and CALCULATE without any luck so far.
My table:
Date | Product | Value
2014-05-06 Cheese 10
2014-08-11 Cheese 12
2015-04-11 Cheese 9
2014-01-22 Milk 4
2014-12-24 Milk 8
The output I try to create:
Date | Product | Value | Yearly_AVG
2014-05-06 Cheese 10 11
2014-08-11 Cheese 12 11
2015-04-11 Cheese 9 9
2014-01-22 Milk 4 6
2014-12-24 Milk 8 6
Lastly, I do not have a calendar table in the dataset.
For a measure, you can write something like this:
YearAvg =
VAR CurrProduct = VALUES ( Sales[Product] )
VAR CurrYear = YEAR ( MAX ( Sales[Date] ) )
RETURN
CALCULATE (
AVERAGE ( Sales[Value] ),
ALLSELECTED ( Sales ),
Sales[Product] IN CurrProduct,
YEAR ( Sales[Date] ) = CurrYear
)