Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Create a calculation based on a field in another column?

Hello,  Would anyone know the DAx formula I may need to use for the below:   I'm trying to create a calculation (I think) based off a field in a different column   Currently my setup is: ...
  • v-alq-msft's avatar
    6 years ago

    Hi, Anonymous 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    You may go to 'Query Editor' and create an index column as below.

     

    You can try the following measures.

    Total measure = 
    var tab = 
    ADDCOLUMNS(
        'Table',
        "Result",
        IF(
            'Table'[MILESTONE]="AUTHORISED",
            CALCULATE(
                SUM('Table'[TOTAL]),
                'Table'[Index]=EARLIER('Table'[Index])
            )
        )
    )
    return
    SUMX(
        tab,
        [Result]
    )

     

    Percentage = 
    var tab = 
    ADDCOLUMNS(
        'Table',
        "Result",
        var _index = 
        CALCULATE(
            MAX('Table'[Index]),
            FILTER(
                ALL('Table'),
                'Table'[Index]<EARLIER('Table'[Index])&&
                'Table'[GROUP]=EARLIER('Table'[GROUP])&&
                'Table'[TEAM]<>""&&
                'Table'[CATEGORY]<>""
            )
        )
        var _time = 
        LOOKUPVALUE('Table'[TIME],'Table'[Index],_index)
        return 
        IF(
            [MILESTONE]="AUTHORISED",
            DIVIDE(_time,[TOTAL])
        )
    )
    return
    SUMX(
        tab,
        [Result]
    )

     

    Result:

     

    Best Regards

    Allan

     

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