Forum Discussion
Create IF/THEN statement in DAX using parameter
- Anonymous6 years ago
HI Anonymous ,
I'd like to clarify some features you misunderstand:
Power bi contains multiple data levels: query table(query, custom function, query parameters) -> data model(table, calculate table, calculate column) -> data view(visual, filter, measure)
These different levels are generated from left to right, you can use parent to effect its child but the child not able to affect the parent level.
For this scenario, it is impossible to use data view filter/slicers to interact with query parameters or create dynamic calculate column/table based on data view filter/slicers. (query parameters can interact with query table records, it will also affect generated data model tables and data view tables)
In summary, you can set query parameters and custom column on the query table side with if statement to dynamic change custom column value based on query parameter values or create a measure on the data view side to integrate with slicer to display dynamic result.
Dynamic measure(DAX) :
My Favorite DAX Feature: SELECTEDVALUE with SWITCH
M query(power query) :
#"Added Custom" = Table.AddColumn(#"previous step", "Dynamic", each if Parameter= "A" then [ColumnA] else if Parameter= "B" then [ColumnB] else null)Regards,
Xiaoxin Sheng
Anonymous try this, yes this new table doesn't need any relationship
Column =
VAR __selectedValue = SELECTEDVALUE ( 'QRY2'[Field4] )
RETURN
IF ( __selectedValue = "Include",'QRY1'[Field1], 'Qry2'[Field2])
Unfortunately it is not working as expected.
The statement says if the slicer is set to "Include", then return Field1. Else return Field2.
Thus the default value here is Field2. That is the result I am getting, no matter what value I select in the slicer.