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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Tamerlane
Helper I
Helper I

Calculated column for balance per customer in timeline

Hi everyone,

 

I have a table with customer balances in a timeline. Now I want to show how the balance has developed over time, per customer, in a calculated column.

 

So for example, I have this table called CustomerTransactions:

Customer   Transdate    Balance    Desired column

112             1-1-2020     500           500

112             1-5-2020     900           1400

112             4-5-2020     -200          1200

113             1-1-2020     400            400

113             2-5-2020     -900           -500

113             8-5-2020     300            -200

 

Anyone know how to get this 'Desire column'? Thanks!

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

Hi, @Tamerlane 

 

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

 

Table:

d1.png

 

You may create a calculated column or a measure as below.

Calculated column:

Result Column = 
var _customer = [Customer]
var _transdate = [Transdate]
return
CALCULATE(
    SUM('Table'[Balance]),
    FILTER(
        ALL('Table'),
        'Table'[Customer]=_customer&&
        'Table'[Transdate]<=_transdate
    )
)

 

Measure:

Result Measure = 
var tab = 
ADDCOLUMNS(
    'Table',
    "Result",
    var _customer = [Customer]
    var _transdate = [Transdate]
    return
    CALCULATE(
        SUM('Table'[Balance]),
        FILTER(
            ALL('Table'),
            'Table'[Customer]=_customer&&
            'Table'[Transdate]<=_transdate
        )
    )
)
return
SUMX(
    tab,
    [Result]
) 

 

Result:

d2.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @Tamerlane 

 

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

 

Table:

d1.png

 

You may create a calculated column or a measure as below.

Calculated column:

Result Column = 
var _customer = [Customer]
var _transdate = [Transdate]
return
CALCULATE(
    SUM('Table'[Balance]),
    FILTER(
        ALL('Table'),
        'Table'[Customer]=_customer&&
        'Table'[Transdate]<=_transdate
    )
)

 

Measure:

Result Measure = 
var tab = 
ADDCOLUMNS(
    'Table',
    "Result",
    var _customer = [Customer]
    var _transdate = [Transdate]
    return
    CALCULATE(
        SUM('Table'[Balance]),
        FILTER(
            ALL('Table'),
            'Table'[Customer]=_customer&&
            'Table'[Transdate]<=_transdate
        )
    )
)
return
SUMX(
    tab,
    [Result]
) 

 

Result:

d2.png

 

Best Regards

Allan

 

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

@Tamerlane 

as new column

Desired column= SUMX(filter(all(Table),Table[Transdate] <=earlier(Table[Transdate]) && Table[Customer] =earlier(Table[Customer])),Sales[Balance])

 

As new measure

Desired Measure = CALCULATE(SUM(Sales[Balance]),filter(all(Table),Table[Transdate] <=max(Table[Transdate]) && Table[Customer] =max(Table[Customer])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
parry2k
Super User
Super User

@Tamerlane check this post.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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