Forum Discussion
If with selectedvalue
Hi Experts
I need a if condition with a selected value in DAX.
So if the user does not selects a Region then
Contribution Margin =
VAR Mth1 =
SELECTEDVALUE ( SelMth_Current[Month] )
VAR yr =
SELECTEDVALUE ( SelYr[Year] )
VAR Reg =
SELECTEDVALUE (Region_Grp[Region])
VAR Fcst1 =
SELECTEDVALUE ( SelMth4[Actual] )
VAR Prod =
SELECTEDVALUE(Product_Grp[Product])
VAR MthVal =
CALCULATE (
SUM ( Profitability_Consolidation[Profit] ),
Profitability_Consolidation[Period] = Fcst1,
Profitability_Consolidation[Month] = Mth1,
Profitability_Consolidation[Year] = yr,
Profitability_Consolidation[Product] = Prod,
Profitability_Consolidation[Region] = Reg,
Profitability_Consolidation[AccountGroup] ="Contribution Margin"
)
RETURN
MthVal/1000
Hi, Anonymous
According to your description, I think you can use 'isfiltered' function in measure.
Like this:
Contribution Margin = VAR Mth1 = SELECTEDVALUE ( SelMth_Current[Month] ) VAR yr = SELECTEDVALUE ( SelYr[Year] ) VAR Fcst1 = SELECTEDVALUE ( SelMth4[Actual] ) VAR Prod = SELECTEDVALUE ( Product_Grp[Product] ) VAR Reg = SELECTEDVALUE ( Region_Grp[Region] ) VAR MthVal1 = CALCULATE ( SUM ( Profitability_Consolidation[Profit] ), Profitability_Consolidation[Period] = Fcst1, Profitability_Consolidation[Month] = Mth1, Profitability_Consolidation[Year] = yr, Profitability_Consolidation[Product] = Prod, Profitability_Consolidation[AccountGroup] = "Contribution Margin" ) VAR MthVal2 = CALCULATE ( SUM ( Profitability_Consolidation[Profit] ), Profitability_Consolidation[Period] = Fcst1, Profitability_Consolidation[Month] = Mth1, Profitability_Consolidation[Year] = yr, Profitability_Consolidation[Product] = Prod, Profitability_Consolidation[Region] = Reg, Profitability_Consolidation[AccountGroup] = "Contribution Margin" ) RETURN IF ( ISFILTERED ( 'table'[Region] ), MthVal2 / 1000, MthVal1 / 1000 )If it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 Replies
- amitchandakSuper User
Anonymous , I think the best way is to create connected (joined) tables in a star schema format. You only need to use selected value for disconnected tables
https://www.sqlbi.com/articles/the-importance-of-star-schemas-in-power-bi/
- v-janeyg-msftCommunity Support
Hi, Anonymous
According to your description, I think you can use 'isfiltered' function in measure.
Like this:
Contribution Margin = VAR Mth1 = SELECTEDVALUE ( SelMth_Current[Month] ) VAR yr = SELECTEDVALUE ( SelYr[Year] ) VAR Fcst1 = SELECTEDVALUE ( SelMth4[Actual] ) VAR Prod = SELECTEDVALUE ( Product_Grp[Product] ) VAR Reg = SELECTEDVALUE ( Region_Grp[Region] ) VAR MthVal1 = CALCULATE ( SUM ( Profitability_Consolidation[Profit] ), Profitability_Consolidation[Period] = Fcst1, Profitability_Consolidation[Month] = Mth1, Profitability_Consolidation[Year] = yr, Profitability_Consolidation[Product] = Prod, Profitability_Consolidation[AccountGroup] = "Contribution Margin" ) VAR MthVal2 = CALCULATE ( SUM ( Profitability_Consolidation[Profit] ), Profitability_Consolidation[Period] = Fcst1, Profitability_Consolidation[Month] = Mth1, Profitability_Consolidation[Year] = yr, Profitability_Consolidation[Product] = Prod, Profitability_Consolidation[Region] = Reg, Profitability_Consolidation[AccountGroup] = "Contribution Margin" ) RETURN IF ( ISFILTERED ( 'table'[Region] ), MthVal2 / 1000, MthVal1 / 1000 )If it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Many thanks much appreciated for the excellent response 👍
- AnonymousNot applicable
Hi can you kindly assist with https://community.powerbi.com/t5/Desktop/Unable-to-Use-New-Reporting-Header-Column-in-Table-Visual/m-p/1678473#M669086
- v-janeyg-msftCommunity Support
Hi, Anonymous
Due to the nature of the work, other colleagues are responsible for this case. I believe he will reply to you soon.
Best Regards
Janey Guo