Forum Discussion
Add filter to show specific values in calculated columns
- 3 years ago
Hi vbvbvb,
Modify the formula to:
AvgValue Blue = VAR _table = FILTER ( TableName, TableName[Year] = EARLIER ( TableName[Year] ) && TableName[Month] = EARLIER ( TableName[Month] ) && TableName[Certain Value] <> BLANK () && 'TableName'[Name of colour] IN { "Blue" } ) RETURN IF ( [Name of colour] IN { "Blue" }, SUMX ( _table, TableName[Certain Value] / COUNTROWS ( _table ) ) )I add an if condition in the code, tweak the color in different color columns.
I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
When I add this part, column still returns all values for all rows regardless of what actual value 'TableName'[Name of colour] has:
&& 'TableName'[Name of colour] IN { "Green", "Blue" }
It doesn't exclude , for example "Red" from "AvgValue Green+Blue" like in your example, despite DAX and inputs being identical.
It doen't work even in your PBIX example, if change value to only "Blue", it shows "Blue" and "Green":
And if change to "Red" and "Blue", it shows all values:
It seems that filter becames invalid when "month" and "year" are matching :
If there any way to make more explicit filter which filters colour value first and then from it's results looks at month and year for average calculation?
Hi vbvbvb,
Modify the formula to:
AvgValue Blue =
VAR _table =
FILTER (
TableName,
TableName[Year] = EARLIER ( TableName[Year] )
&& TableName[Month] = EARLIER ( TableName[Month] )
&& TableName[Certain Value] <> BLANK ()
&& 'TableName'[Name of colour] IN { "Blue" }
)
RETURN
IF (
[Name of colour] IN { "Blue" },
SUMX ( _table, TableName[Certain Value] / COUNTROWS ( _table ) )
)
I add an if condition in the code, tweak the color in different color columns.
I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.