Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Create Calculated Fields based on Field Parameter selected

Hi Everyone   I would like to create a calculated field that is based on what I select from Field Parameters. I created a field parameter that contains Column A (all numbers) and Column B (all n...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

    Please try below steps:

    1. below is my test table

    Table:

    2. create a field parameter

    3. create a measure with below dax formula

    Measure =
    VAR tmp =
        SELECTCOLUMNS ( Parameter, "SelectColumn", [Parameter] )
    VAR _str =
        CONCATENATEX ( tmp, [SelectColumn] )
    VAR _val =
        SWITCH (
            _str,
            "Column1", SUMX ( SELECTCOLUMNS ( 'Table', "Column1", [Column1] ), [Column1] ),
            "Column2", SUMX ( SELECTCOLUMNS ( 'Table', "Column2", [Column2] ), [Column2] )
        )
    VAR _val1 = 100
    RETURN
        DIVIDE ( _val, _val1 )
    

    4. add a table visual and a card visual

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.