Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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!

1 ACCEPTED SOLUTION
v-xiaoyan-msft
Community Support
Community Support

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.

 

 

v-caitlyn-mstf_0-1609388514866.png

 

 

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.

 

View solution in original post

3 REPLIES 3
v-xiaoyan-msft
Community Support
Community Support

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.

 

 

v-caitlyn-mstf_0-1609388514866.png

 

 

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.

 

amitchandak
Super User
Super User

@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
Not applicable

Thanks for your response.

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.