Forum Discussion
AVERAGEX returns blank
- Anonymous1 year ago
Hi cheryl0316
Certainly!
The SELECTEDVALUE() returns blank when the Slicer Number of Notice is all, because there are multipal values being selected. Please refere to this link:
SELECTEDVALUE function - DAX | Microsoft Learn
So change the measure this way:
Average_Notice = VAR a = SUMMARIZECOLUMNS ( dimLocation[Country], dimLocation[City], dimEmployee[Employee Name], dimProduct[Product Category] ) VAR b = ADDCOLUMNS ( a, "n", CALCULATE ( [Number_Notice] ), "sa", CALCULATE ( [Sum_Sales Amount] ) ) RETURN IF ( SELECTEDVALUE ( Notice[Number] ) <> BLANK (), AVERAGEX ( FILTER ( b, [sa] > 0 && [n] = SELECTEDVALUE ( Notice[Number] ) ), [n] ), AVERAGEX ( FILTER ( b, [sa] > 0 ), [n] ) )The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Zhengdong,
Thank you for your help. I added [n] = SELECTEDVALUE(Notice[Number]) because I want the bar chart to be filtered by the slicer "Number of Notice." Is it possible to make the bar chart interact with the slicer?
Hi cheryl0316
Certainly!
The SELECTEDVALUE() returns blank when the Slicer Number of Notice is all, because there are multipal values being selected. Please refere to this link:
SELECTEDVALUE function - DAX | Microsoft Learn
So change the measure this way:
Average_Notice =
VAR a =
SUMMARIZECOLUMNS (
dimLocation[Country],
dimLocation[City],
dimEmployee[Employee Name],
dimProduct[Product Category]
)
VAR b =
ADDCOLUMNS (
a,
"n", CALCULATE ( [Number_Notice] ),
"sa", CALCULATE ( [Sum_Sales Amount] )
)
RETURN
IF (
SELECTEDVALUE ( Notice[Number] ) <> BLANK (),
AVERAGEX (
FILTER ( b, [sa] > 0 && [n] = SELECTEDVALUE ( Notice[Number] ) ),
[n]
),
AVERAGEX ( FILTER ( b, [sa] > 0 ), [n] )
)
The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.