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 cheryl0316
Maybe you can try this:
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
AVERAGEX ( FILTER ( b, [sa] > 0 ), [n] )
It seems that the [n]=SELECTEDVALUE(Notice[Number]) is the reason of the error. There aren't relationship between Notice table and dimLocation table so the SELECTEDVALUE(Notice[Number]) returns blank in the Clustered column chart so that the result is blank.
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.
- cheryl03161 year ago
Helper II
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?
- Anonymous1 year agoNot applicable
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.