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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
av9
Helper III
Helper III

Identify customers who withdraw all money from a bank account

Looking to flag customers who withdraw all their money from their bank account. The data looks like this with a balance of each account at the end of the month.

 

CustomerAccount TypeDateBalance
Customer ASavings Account31/03/2020$1000
Customer BSavings Account 31/03/2020$2500
Customer BCheque Account31/03/2020$800
Customer CSavings Account 31/03/2020$500
Customer ASavings Account30/04/2020$100
Customer BSavings Account 30/04/2020$25
Customer BCheque Account30/04/2020$0
Customer CSavings Account 30/04/2020$500

 

So in this situation, I would like to flag Customer B had a zero balance on their cheque account based on previous month having a positive value.

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@av9  Do you have a DimDate table? https://allisonkennedycv.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

Once you have that, you can use a function like DATEADD(DimDate[Date], -1, Month) inside a MEASURE to get

Balance = SUM(Table[Balance])

Previous Month Balance= CALCULATE([Balance], DATEADD(DimDate[Date], -1, Month) )

 

Then create another MEASURE: 

Conditional Format = IF( [Previous Month Balance] > 0 && [Balance] =0 , 1, 0)

 

You can add this measure to the conditional formatting within the matrix to change color or add an icon or whatever your requirements are. https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-conditional-table-formatting

 

Let me know if you need more details on any of those steps


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

3 REPLIES 3
Mariusz
Community Champion
Community Champion

Hi @av9 

 

Try a column like below.

Column = 
VAR __previousMonthBalance =
    CALCULATE(
        SUM( 'Table'[Balance] ),
        ALLEXCEPT( 'Table', 'Table'[Customer], 'Table'[Account Type] ),
        PREVIOUSMONTH( 'Table'[Date].[Date] )
    ) > 0
RETURN 
     __previousMonthBalance && 'Table'[Balance] = 0

 the result will be

image.png

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

AllisonKennedy
Super User
Super User

@av9  Do you have a DimDate table? https://allisonkennedycv.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

Once you have that, you can use a function like DATEADD(DimDate[Date], -1, Month) inside a MEASURE to get

Balance = SUM(Table[Balance])

Previous Month Balance= CALCULATE([Balance], DATEADD(DimDate[Date], -1, Month) )

 

Then create another MEASURE: 

Conditional Format = IF( [Previous Month Balance] > 0 && [Balance] =0 , 1, 0)

 

You can add this measure to the conditional formatting within the matrix to change color or add an icon or whatever your requirements are. https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-conditional-table-formatting

 

Let me know if you need more details on any of those steps


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@av9 , both as new columns

last Month value = maxX(filter(table,[Customer] =earlier([Customer]) && [Account Type] =earlier([Account Type] )
&& [Date] < earlier([Date]) ),[Date] )

If([Balance] =0 && maxX(filter(table,[Customer] =earlier([Customer] ) && [Account Type] =earlier([ Account Type])
&& [Date] = earlier([last Month value]) ),[Balance] ) >0 , "Yes", "No")

 

 

In case there are more than one date in a month for a account type  then try

last Month value = maxX(filter(table,[Customer] =earlier([Customer]) && [Account Type] =earlier([ Account Type])
&& [Date] < earlier([Date]) && eomonth([Date],0) < eomonth(earlier([Date]) ,0 )),[Date] )

 

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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