Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calculate operations after certain value

Hi everyone, I have some trouble trying to do an specific topic, here is my data:

IDRegisterTypeAmount
101/01/2018Balance5
201/01/2018Cash10
301/01/2018Cash15
102/01/2018Balance20
202/01/2018Balance5
302/01/2018Balance10
104/01/2018Balance8
204/01/2018Cash10
304/01/2018Balance15
105/01/2018Cash10
205/01/2018Balance10
305/01/2018Balance20

ID: id user

Register: when a user buy an item

Type: type of payment

Amount

When someone wants to buy in the store, we give them an amount of 20 (Balance),the the user can buy some money in cash and add to balance.

I want to calculate the operations after a user spend that money (no matter type of payment). For example, user ID 1, spend the money on 2nd transaction, then he has 2 more transactions.

The result I expect is:

IDTotal PaymentTotal Balance paymentTotal OperationsOperationsAfter20
1433342
2351540
3604541

Thank you so much guys!

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi,Anonymous

    You can use the following method to meet your needs:

     

    Create a measure for Cumulative Balance to get OperationsAfter20 like this:

     

    Cumulative Balance =

    CALCULATE (

        SUM ( 'Table'[Amount] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[ID] = MAX ( 'Table'[ID] )

                && 'Table'[Type] = "Balance"

                && 'Table'[Register] <= MAX ( 'Table'[Register] )

        )

    )

     

     

     

     

     

     

    OperationsAfter20 =

    VAR _date =

        CALCULATE (

            MIN ( 'Table'[Register] ),

            FILTER (

                ALL ( 'Table' ),

                'Table'[ID] = MAX ( 'Table'[ID] )

                    && [Cumulative Balance] > 20

            )

        )

    RETURN

        COUNTROWS (

            FILTER (

                ALL ( 'Table' ),

                'Table'[ID] = MAX ( 'Table'[ID] )

                    && [Cumulative Balance] > 20

                    && 'Table'[Register] > _date

            )

    ) + 0

     

     

    Try to create new measure for total balance payment, Total operations,  Total payment.
    Total Balance payment =

    CALCULATE(

        SUM('Table'[Amount]),

    FILTER('Table','Table'[Type]="Balance"))

     

    Total Operations = COUNT('Table'[Amount])

     

    Total Payment = SUM('Table'[Amount])

     

    Then you will get what you want.

     

     

     

     

    Here is the demo , please try it:

    https://qiuyunus-my.sharepoint.com/:u:/g/personal/admin_qiuyunus_onmicrosoft_com/Ea6D_qeipgJKiXzYPre8TAMByCNtr-XqyvSb3hxxGCl__Q?e=wlt9G6

     

    Hope it helps.

     

    Best Regards,

    Caitlyn Yan

     

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

     

3 Replies

  • Anonymous , 4th one is not clear. Try measures like

     


    Total Payment = sum(Table[Amount])

     

    Total Balance payment = calculate(sum(Table[Amount]), filter(Table, Table[Type] ="Balance"))

     

    Total Operations = count(Table[Amount])

     

    OperationsAfter20 = calculate(count(Table[Amount]), filter(Table,Table[Register] > calculate(maxX(filter(Table, Table[Type] ="Balance" && Table[Amount] =20), Table[Register]), allexpcept(Table,Table[place_digital_adress]))))

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for your response.

      OperationsAfter20: I want the operations after the user spent his first 20 in balance

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,Anonymous

    You can use the following method to meet your needs:

     

    Create a measure for Cumulative Balance to get OperationsAfter20 like this:

     

    Cumulative Balance =

    CALCULATE (

        SUM ( 'Table'[Amount] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[ID] = MAX ( 'Table'[ID] )

                && 'Table'[Type] = "Balance"

                && 'Table'[Register] <= MAX ( 'Table'[Register] )

        )

    )

     

     

     

     

     

     

    OperationsAfter20 =

    VAR _date =

        CALCULATE (

            MIN ( 'Table'[Register] ),

            FILTER (

                ALL ( 'Table' ),

                'Table'[ID] = MAX ( 'Table'[ID] )

                    && [Cumulative Balance] > 20

            )

        )

    RETURN

        COUNTROWS (

            FILTER (

                ALL ( 'Table' ),

                'Table'[ID] = MAX ( 'Table'[ID] )

                    && [Cumulative Balance] > 20

                    && 'Table'[Register] > _date

            )

    ) + 0

     

     

    Try to create new measure for total balance payment, Total operations,  Total payment.
    Total Balance payment =

    CALCULATE(

        SUM('Table'[Amount]),

    FILTER('Table','Table'[Type]="Balance"))

     

    Total Operations = COUNT('Table'[Amount])

     

    Total Payment = SUM('Table'[Amount])

     

    Then you will get what you want.

     

     

     

     

    Here is the demo , please try it:

    https://qiuyunus-my.sharepoint.com/:u:/g/personal/admin_qiuyunus_onmicrosoft_com/Ea6D_qeipgJKiXzYPre8TAMByCNtr-XqyvSb3hxxGCl__Q?e=wlt9G6

     

    Hope it helps.

     

    Best Regards,

    Caitlyn Yan

     

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