Cash flow in Power Pivot and using DAX

didijaba

Well-known Member
Joined
Nov 26, 2006
Messages
511
Hello, I would like to show cash flow for lending and borrowing (landing as + and borrowing as -) using Power Pivot and DAX. First table is what I have, and second is what I want. Do you have any ideas how to do this?

<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style><table class="tableizer-table">
<tr class="tableizer-firstrow"><th>Date</th><th>Lender</th><th>Borrower</th><th>Amount</th></tr>
<tr><td>15.1.2014</td><td>AAA</td><td>BBB</td><td>100</td></tr>
<tr><td>30.1.2014</td><td>AAA</td><td>CCC</td><td>200</td></tr>
<tr><td>14.2.2014</td><td>BBB</td><td>AAA</td><td>300</td></tr>
<tr><td>1.3.2014</td><td>BBB</td><td>CCC</td><td>400</td></tr>
<tr><td>16.3.2014</td><td>CCC</td><td>AAA</td><td>500</td></tr>
<tr><td>31.3.2014</td><td>CCC</td><td>BBB</td><td>600</td></tr>
<tr><td>15.4.2014</td><td>DDD</td><td>AAA</td><td>700</td></tr>
<tr><td>30.4.2014</td><td>DDD</td><td>BBB</td><td>800</td></tr>
</table>

<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style><table class="tableizer-table">
<tr class="tableizer-firstrow"><th>Cash flow report</th><th> </th></tr>
<tr><td> </td><td> </td></tr>
<tr><td>Row Labels</td><td>Cash flow</td></tr>
<tr><td>AAA</td><td>-1200</td></tr>
<tr><td>15.1.2014</td><td>100</td></tr>
<tr><td>30.1.2014</td><td>200</td></tr>
<tr><td>14.2.2014</td><td>-300</td></tr>
<tr><td>16.3.2014</td><td>-500</td></tr>
<tr><td>15.4.2014</td><td>-700</td></tr>
<tr><td>BBB</td><td>-800</td></tr>
<tr><td>15.1.2014</td><td>-100</td></tr>
<tr><td>14.2.2014</td><td>300</td></tr>
<tr><td>1.3.2014</td><td>400</td></tr>
<tr><td>31.3.2014</td><td>-600</td></tr>
<tr><td>30.4.2014</td><td>-800</td></tr>
<tr><td>CCC</td><td>500</td></tr>
<tr><td>30.1.2014</td><td>-200</td></tr>
<tr><td>1.3.2014</td><td>-400</td></tr>
<tr><td>16.3.2014</td><td>500</td></tr>
<tr><td>31.3.2014</td><td>600</td></tr>
<tr><td>DDD</td><td>1500</td></tr>
<tr><td>15.4.2014</td><td>700</td></tr>
<tr><td>30.4.2014</td><td>800</td></tr>
<tr><td>EEE</td><td>0</td></tr>
<tr><td>Grand Total</td><td>0</td></tr>
</table>
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Awesome problem! Love it.

So, I am fairly sure there is a more "direct" way to solve this, but ... here is what I did.

I created a separate accounts table with AAA-EEE, and called the table of values... Ledger.

I created TWO relationships (one will necessarily be inactive)... one for Lender, one for Borrower.

KccwgdG.png


Then I created two based measures:
Lent:=CALCULATE(SUM(Ledger[Amount]), USERELATIONSHIP(Ledger[Lender],Accounts[Account]))
Borrowed:=CALCULATE(-1*SUM(Ledger[Amount]), USERELATIONSHIP(Ledger[Borrower],Accounts[Account]))

Then a simple total:
Total :=[Lent] + [Borrowed]

By place Accounts (from the lookup table!) and Dates on rows, and [Total] in values... I think you get just what you want?
 
Upvote 0
Thanks, your solution looks just right, but I'm having some problem with relationship dependency. I am trying to build model from start to eliminate some error of mine.
 
Upvote 0
Ok, I solved one, but got other problem. Now it gives me circular dependancy when I try to place formula for Borrowed.
 
Upvote 0
Do you by any chance have workbook made? I don't see no error but circular error is getting me every time. Maybe is some problem with excel settings on my end.
 
Upvote 0
Sorry for the slow response. I just went and looked and alas, I did not save it. If it keeps giving you fits, I'll take a look -- just share it via dropbox/googledrive/onedrive.
 
Upvote 0
Wonder if you can just add a union all to your SQL where one query has only the borrower name and the other has only the Lender name. You would then have 16 rows and making your example would be very simple.

 
Upvote 0
I can do this in sql and vba very fast, but thing is I would like to learn DAX and Power Pivot logic of solving such things. Thanks for sugesstion, Kazlik :)
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top