Forum Discussion
if condition dont work using CALCULATE
hi ,
I have a column in table : T_YD - that counts the number of selected values from field : MainYD_Desc
CntSelectMainYD = CALCULATE(
Hi yanivl ,
If Msg_MainYehida is a calculated column, it won’t respond to slicers or visual filters. Calculated columns are evaluated at data load time. To get dynamic text based on how many values are selected, you must use measures.
What to change (use measures, not a calculated column)
Create a measure that counts the number of distinct MainYD_Desc currently selected
CntSelectMainYD := CALCULATE( DISTINCTCOUNT( T_YD[MainYD_Desc] ), ALLSELECTED( T_YD[MainYD_Desc] ) )
Create a measure that shows the description only when there’s exactly one selected value Msg_MainYehida := VAR cnt = [CntSelectMainYD] RETURN IF( cnt = 1, SELECTEDVALUE( T_YD[MainYD_Desc] ), "NOT ONE!" )
Please mark this post as solution if it helps you. Appreciate Kudos.
7 Replies
- bhanu_gautamSuper User
yanivl The issue with your Msg_MainYehida column likely stems from the fact that CntSelectMainYD is a measure, not a column. Measures are calculated dynamically based on the context of the report, and they cannot be directly referenced in calculated columns
To resolve this, you should use a measure for Msg_MainYehida instead of a calculated column
DAX
Msg_MainYehida =
IF(
[CntSelectMainYD] = 1,
SELECTEDVALUE(T_YD[MainYD_Desc]),
"NOT ONE!"
) - FarhanJeelaniSuper User
Hi yanivl ,
If Msg_MainYehida is a calculated column, it won’t respond to slicers or visual filters. Calculated columns are evaluated at data load time. To get dynamic text based on how many values are selected, you must use measures.
What to change (use measures, not a calculated column)
Create a measure that counts the number of distinct MainYD_Desc currently selected
CntSelectMainYD := CALCULATE( DISTINCTCOUNT( T_YD[MainYD_Desc] ), ALLSELECTED( T_YD[MainYD_Desc] ) )
Create a measure that shows the description only when there’s exactly one selected value Msg_MainYehida := VAR cnt = [CntSelectMainYD] RETURN IF( cnt = 1, SELECTEDVALUE( T_YD[MainYD_Desc] ), "NOT ONE!" )
Please mark this post as solution if it helps you. Appreciate Kudos.
- Shahid12523Community Champion
Your issue is because you used a calculated column — slicer filters don’t affect it. ✅ Use measures instead:
CntSelectMainYD =
COUNTROWS ( ALLSELECTED ( T_YD[MainYD_Desc] ) )Msg_MainYehida =
IF ( [CntSelectMainYD] = 1,
SELECTEDVALUE ( T_YD[MainYD_Desc] ),
"NOT ONE!" ) - v-sshirivoluCommunity Support
Hi yanivl ,
The issue is due to mixing a measure and a column. CntSelectMainYD is a measure, so referencing it as T_YD[CntSelectMainYD] is incorrect. Additionally, using a calculated column won’t work since the logic relies on filter context.
To resolve this, create a new measure as follows :
Msg_MainYehida =
IF (
[CntSelectMainYD] = 1,
SELECTEDVALUE ( T_YD[MainYD_Desc], "NOT ONE!" ),
"NOT ONE!"
)[CntSelectMainYD] is correctly used as a measure. SELECTEDVALUE returns the single value of MainYD_Desc if selected, or "NOT ONE!" otherwise. This approach ensures the message updates dynamically based on slicer or filter selections.
- v-sshirivoluCommunity Support
Hi yanivl ,
I hope the information provided above assists you in resolving the issue. If you have any additional questions or concerns, please do not hesitate to contact us. We are here to support you and will be happy to help with any further assistance you may need.- v-sshirivoluCommunity Support
Hi yanivl ,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you