Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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 Number | Date | Balance |
1 | 04/12/2022 | 0 |
1 | 05/12/2022 | -1000 |
1 | 06/12/2022 | -1000 |
1 | 07/12/2022 | -1000 |
2 | 04/12/2022 | -1000 |
2 | 05/12/2022 | 0 |
2 | 06/12/2022 | -1000 |
2 | 07/12/2022 | -1000 |
3 | 04/12/2022 | -1000 |
3 | 05/12/2022 | 0 |
3 | 06/12/2022 | 1000 |
3 | 07/12/2022 | 1000 |
Solved! Go to Solution.
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:
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 @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:
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
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:
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 Number | Date | Balance | Last overdrawn start date |
1 | 04/12/2022 | 0 | 05/12/2022 |
1 | 05/12/2022 | -1000 | 05/12/2022 |
1 | 06/12/2022 | -1000 | 05/12/2022 |
1 | 07/12/2022 | -1000 | 05/12/2022 |
2 | 04/12/2022 | -1000 | 06/12/2022 |
2 | 05/12/2022 | 0 | 06/12/2022 |
2 | 06/12/2022 | -1000 | 06/12/2022 |
2 | 07/12/2022 | -1000 | 06/12/2022 |
3 | 04/12/2022 | -1000 | Not Overdrawn |
3 | 05/12/2022 | 0 | Not Overdrawn |
3 | 06/12/2022 | 1000 | Not Overdrawn |
3 | 07/12/2022 | 1000 | Not Overdrawn |
4 | 04/12/2022 | 0 | 06/12/2022 |
4 | 05/12/2022 | 0 | 06/12/2022 |
4 | 06/12/2022 | -1000 | 06/12/2022 |
4 | 07/12/2022 | 0 | 06/12/2022 |
5 | 04/12/2022 | 0 | 08/12/2022 |
5 | 05/12/2022 | -1000 | 08/12/2022 |
5 | 06/12/2022 | 0 | 08/12/2022 |
5 | 07/12/2022 | 1000 | 08/12/2022 |
5 | 08/12/2022 | -1000 | 08/12/2022 |
5 | 09/12/2022 | -1000 | 08/12/2022 |
User | Count |
---|---|
139 | |
113 | |
103 | |
73 | |
63 |
User | Count |
---|---|
136 | |
125 | |
107 | |
70 | |
61 |