Forum Discussion

Excellove15's avatar
Excellove15
Iron Contributor
Jul 29, 2024
Solved

Dax measure doesn't return correct total value in all rows

Hi,   Created a measure as below:   Its giving me the correct values at filter context and total as well as shown below:   My expected outcome of this measure should be: total 0.17...
  • SergeiBaklan's avatar
    SergeiBaklan
    Aug 06, 2024

    Excellove15 

    If I understood correctly now:

    We calculate Rate separately for the rows and for the Total. For each row we have one related utility, for the total we calculate average of averages for all selected utilities:

    VAR IsOneUtility =
        HASONEVALUE ( 'Points'[Utility] )
    VAR UtilityAverage =
        IF (
            IsOneUtility,
            CALCULATE (
                [Invoice Unit Rate test 2],
                ALL ( 'Points'[DBName-Point_Id] ),
                'Points'[Utility] = VALUES ( 'Points'[Utility] )
            )
        )
    VAR TotalAverage =
        CALCULATE (
            AVERAGEX ( VALUES ( 'Points'[Utility] ), [Invoice Unit Rate test 2] ),
            ALLSELECTED ( 'Points'[DBName-Point_Id] )
        )
    VAR Result =
        IF ( IsOneUtility, UtilityAverage, TotalAverage )
    RETURN
        Result

    which gives

    Just in case,

    Invoice Unit Rate test 2 =
    VAR Cost =
        SUM ( 'Invoice Data'[Cost] )
    VAR Units =
        SUM ( 'Invoice Data'[Units] )
    VAR div =
        DIVIDE ( ABS ( Cost ), ABS ( Units ), BLANK () )
    RETURN
        CALCULATE ( IF ( ISBLANK ( Cost ) || ISBLANK ( Units ), BLANK (), div ) )
    

Resources