Forum Discussion

kgoth's avatar
kgoth
Frequent Visitor
1 year ago
Solved

How to Dynamically Evaluate any Measure Over a Defined Summary Table

Hi All,   I'm reaching out for help as I feel I've exhausted my search online and other options 😅   Goal: I want to create a calculation item in Power BI that dynamically evaluates a selected ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi kgoth 

     

    Thank you very much lbendlin and DataInsights for your prompt reply. Allow me to share something.

     

    For your question, here is the method I provided:

     

    Here's some dummy data

     

    “Table”

     

    Total Measure = SUM('Table'[Value])
    Avg Measure = AVERAGE('Table'[Value]) 
    Count Measure = COUNTROWS('Table')
    Per Measure = DIVIDE(SUM('Table'[Value]), CALCULATE(SUM('Table'[Value]), ALL('Table')))

     

    Create a calculation table, using CALCULATETABLE to create a table that holds the filtering context. To add columns with measures, use ADDCOLUMNS to add the measures you want to evaluate to this table.

     

    EvaluatedMeasuresTable = 
    ADDCOLUMNS(
        CALCULATETABLE(
            'Table',
            ALLSELECTED('Table')
        ),
        "Total", 'Table'[Total Measure],
        "Average", 'Table'[Avg Measure],
        "Count", 'Table'[Count Measure],
        "Percentage", 'Table'[Per Measure]
    )

     

    Create a new table for selecting measures.

     

    MeasureSelector = 
    DATATABLE(
        "MeasureName", STRING,
        {
            {"Total"},
            {"Average"},
            {"Count"},
            {"Percentage"}
        }
    )

     

    Use SELECTEDVALUE to dynamically select the measures to be evaluated.

     

    DynamicMeasure = 
    VAR SelectedMeasure = SELECTEDVALUE('MeasureSelector'[MeasureName])
    RETURN
        SWITCH(
            SelectedMeasure,
            "Total", 'Table'[Total Measure],
            "Average", 'Table'[Avg Measure],
            "Count", 'Table'[Count Measure],
            "Percentage", 'Table'[Per Measure],
            BLANK()
        )
    

     

    Here is the result.

     

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.