Forum Discussion
Erik_Debono
6 years agoAdvocate II
Dax Average with Distinct Filter
Hi All, I'm trying to filter a table (have provided a mock one below) where I filter by Distinct and a result. As you can see, the Cycle time will be the same for every ID but I only want to Aver...
- 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])
Erik_Debono
6 years agoAdvocate 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.
Anonymous
6 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 agoAdvocate II
Anonymous perfect. I understand now. Thank you.