cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RhodesBrown
Frequent Visitor

How to get date account became overdrawn

Hi All

 

I'm looking to add a date column into my dataset where each account became overdrawn (don't have a data point in our system for this).  An account could go in and out of an overdrawn position so I would like the last time the overdraft position was reached.

 

The data would look something similar to the below. For account 1 I would like the column to say 05/12/22, for account 2 06/12/22 and account 3 to return 'Not overdrawn'

 

Account NumberDateBalance
104/12/20220
105/12/2022-1000
106/12/2022-1000
107/12/2022-1000
204/12/2022-1000
205/12/20220
206/12/2022-1000
207/12/2022-1000
304/12/2022-1000
305/12/20220
306/12/20221000
307/12/20221000

 

 

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

Hi  @RhodesBrown ,

 

Here are the steps you can follow:

1. Create calculated column.

Rank =
RANKX(
    FILTER(ALL('Table'),
    'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date],,ASC)
Flag =
var _maxxgroupdate=MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date])
var _maxbalance=SUMX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Date]=_maxxgroupdate),[Balance])
var _maxx0=
MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Balance]>=0),[Rank])
var _next=
MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Rank]=_maxx0+1),[Date])
var _next2=MAXX(FILTER(ALL('Table'),'Table'[Date]<>_maxxgroupdate&&'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date])
return
SWITCH(
    TRUE(),
    _maxbalance =0,FORMAT(_next2,"dd/mm/yyyy"),
    _maxbalance >0,"Not overdrawn",
    _maxbalance<0,FORMAT(_next,"dd/mm/yyyy"))

2. Result:

vyangliumsft_0-1670574768867.png

 

Best Regards,

Liu Yang

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

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @RhodesBrown ,

 

Here are the steps you can follow:

1. Create calculated column.

Rank =
RANKX(
    FILTER(ALL('Table'),
    'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date],,ASC)
Flag =
var _maxxgroupdate=MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date])
var _maxbalance=SUMX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Date]=_maxxgroupdate),[Balance])
var _maxx0=
MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Balance]>=0),[Rank])
var _next=
MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Rank]=_maxx0+1),[Date])
var _next2=MAXX(FILTER(ALL('Table'),'Table'[Date]<>_maxxgroupdate&&'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date])
return
SWITCH(
    TRUE(),
    _maxbalance =0,FORMAT(_next2,"dd/mm/yyyy"),
    _maxbalance >0,"Not overdrawn",
    _maxbalance<0,FORMAT(_next,"dd/mm/yyyy"))

2. Result:

vyangliumsft_0-1670574768867.png

 

Best Regards,

Liu Yang

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

The flag works positively, I'm just filtering out any positive balances and this always give me the correct overdrawn date. Thank you

v-yangliu-msft
Community Support
Community Support

Hi  @RhodesBrown ,

 

Here are the steps you can follow:

1. Create calculated column.

Rank =
RANKX(
    FILTER(ALL('Table'),
    'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date],,ASC)
Value =
var _Balance0=MINX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Balance]=0),[Rank])
var _lastdate=MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])),[Date])
var _lastvalue=MAXX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Date]=_lastdate),[Balance])
var _next=
MINX(FILTER(ALL('Table'),'Table'[Account Number]=EARLIER('Table'[Account Number])&&'Table'[Rank]=_Balance0+1),[Date])
return
IF(
    _lastvalue>0,"Not overdrawn",FORMAT(_next,"yyyy/mm/dd"))

2. Result:

vyangliumsft_0-1670391997465.png

 

Best Regards,

Liu Yang

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

Hi Liu, thanks for your reply. I think its close but I guess I didnt give you enough scenarios.  An account could be zero for a few days before anything happens, the solution seems currently give me the date after the first zero if there are multiple days on zero balance. Would it be possible to through these two scenarios in as well

Account NumberDateBalanceLast overdrawn start date
104/12/2022005/12/2022
105/12/2022-100005/12/2022
106/12/2022-100005/12/2022
107/12/2022-100005/12/2022
204/12/2022-100006/12/2022
205/12/2022006/12/2022
206/12/2022-100006/12/2022
207/12/2022-100006/12/2022
304/12/2022-1000Not Overdrawn
305/12/20220Not Overdrawn
306/12/20221000Not Overdrawn
307/12/20221000Not Overdrawn
404/12/2022006/12/2022
405/12/2022006/12/2022
406/12/2022-100006/12/2022
407/12/2022006/12/2022
504/12/2022008/12/2022
505/12/2022-100008/12/2022
506/12/2022008/12/2022
507/12/2022100008/12/2022
508/12/2022-100008/12/2022
509/12/2022-100008/12/2022

RhodesBrown
Frequent Visitor

@amitchandak any way you help with this? Thanks

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.