Forum Discussion

mastone's avatar
mastone
Frequent Visitor
3 years ago
Solved

Convert Table Expression (i.e. virtual table) to a set of Measures

New to DAX and power BI.  I am struggling and want to go hide under the covers.   Anywhoooo, after many iterations I have been able to generate a virtual table that produces the results I want.  But ...
  • tamerj1's avatar
    3 years ago

    Hi mastone 
    Please try

    ImpactMeasure =
    VAR countfailureTable =
        GROUPBY (
            FILTER ( ALLSELECTED ( Surveys ), Surveys[SVRESULT] >= 0 ),
            Surveys[QuestionId],
            "QuestionCount", COUNTX ( CURRENTGROUP (), Surveys[QuestionId] ),
            "FailurePercent", AVERAGEX ( CURRENTGROUP (), Surveys[SVRESULT] )
        )
    VAR allItems =
        ADDCOLUMNS (
            countfailureTable,
            "NegativeImpact",
                (
                    [QuestionCount] / SUMX ( countfailureTable, [QuestionCount] ) * [FailurePercent]
                )
        )
    VAR finalItems =
        ADDCOLUMNS (
            allItems,
            "RelativeImpact", [NegativeImpact] / MAXX ( allItems, [NegativeImpact] )
        )
    RETURN
        AVERAGEX (
            VALUES ( Surveys[QuestionId] ),
            MAXX (
                FILTER ( finalItems, [QuestionId] = EARLIER ( [QuestionId] ) ),
                [RelativeImpact]
            )
        )