Forum Discussion
Dax Average with Distinct Filter
- Anonymous6 years ago
Hi Erik_Debono -
Try the following:
Cycle Time Average = var _table = DISTINCT( SELECTCOLUMNS( FILTER('Cycle Time', [Result]<>"N/A"), "ID", [ID], "CycleTime", [CycleTime] ) ) return AVERAGEX(_table, [CycleTime])
Hi Erik_Debono -
Try the following:
Cycle Time Average =
var _table = DISTINCT(
SELECTCOLUMNS(
FILTER('Cycle Time', [Result]<>"N/A"),
"ID", [ID],
"CycleTime", [CycleTime]
)
)
return AVERAGEX(_table, [CycleTime])
- Erik_Debono6 years ago
Advocate II
Hi Anonymous
Thank you for that. I tried your formula and i'm getting underline errors for the following:
- Name 2 [ID] on line 5
- Name 3 [CycleTime] on line 6 and
- Expression [CycleTime] on the last line.
The overall error is "Function SELECTCOLUMNS expects a column name as argument number 4"
- Nathaniel_C6 years ago
Community Champion
Hi Erik_Debono , Anonymous ,
I built a table using copy and paste from your numbers, and it works for me.
Nathaniel
- Erik_Debono6 years ago
Advocate II
Hi Anonymous Nathaniel_C
Error was self inflicted, your solution worked great, thank you for that. Have marked as Solved. Are you able to explain what's happening here? i'm not following how it works.
amitchandak Thanks for your solution. I didn't get around to checking if it would work in this case.
- Anonymous6 years agoNot applicable
Sure, it is basically 2 steps:
- Create a table of the distinct values:
- FILTER limits table to eliminate N/A
- SELECTCOLUMNS chooses the 2 columns we need to run the distinct on.
- DISTINCT returns the distinct values
var _table = DISTINCT( SELECTCOLUMNS( FILTER('Cycle Time', [Result]<>"N/A"), "ID", [ID], "CycleTime", [CycleTime] ) )
- Get the average of the CycleTimes from the distinct table.
- Use AVERAGEX to work with Table Variables.
return AVERAGEX(_table, [CycleTime])- Erik_Debono6 years ago
Advocate II
Anonymous perfect. I understand now. Thank you.
- Create a table of the distinct values: