Forum Discussion

AMR80's avatar
AMR80
Frequent Visitor
6 years ago
Solved

SUMX with Filter or If Statement

I have custom columns to calculate the balance of an Employee's time off by subtracting their Time Used so far in the year from their Time Allotted.  All the types of time are straight forward excep...
  • v-janeyg-msft's avatar
    v-janeyg-msft
    6 years ago

    Hi, @AMR80

    Sorry for my late response.

    It's not recommended that you calculate the aggregate value in Power Query. Power Query uses M language to write formulas,and using custom column will change the original data model.

    v-janeyg-msft_0-1600917878535.png

    You can create a measure in the model. The measure is mainly used for aggregation calculation, and the calculations are executed during query.

    Like this:

    Measure = SUMX (
        FILTER (
            'Table_query__5',
            AND (
                [Date]
                    > TODAY () - 365
                    && [Date] <= TODAY (),
                     [Type of Time] = "Family Leave"
            )
        ),
        [Hours Requested] 
    )

    Snipaste_2020-09-24_11-32-20.png

    v-janeyg-msft_2-1600917878540.png

    If you still have questions, please feel free to contact me.

    Best Regards

    Janey Guo

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