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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Akolade
Regular Visitor

DAX with For and while loop

I have this table

Account RefAmountDateOrg code
12524 February 2000A
22524 February 2000A
32514 March 2000B
42520 March 2000B
5344  April  2000B
61210  April  2000A
73024 may  2000A

 

I have another table called pot Fund

OrganisationInitialFund
B£1000
A

£2000

 

Please I need to create a DAX that will filter each row. If the Org code = "A" then the amount will be deducted from pot fund "A".

 

For example for Account "1" the Amount is £25 and the org = "A"  which will  be £2000- £25 = £1975. The next column that will satisfied the  condition, the  calculation will be  £1975 - [Amount]

 

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Akolade ,

 

You can create a calcualted column. And you need to create a relationship first.

Column = var _initial=RELATED('pot Fund'[InitialFund])
var _culmative=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[Date]<=EARLIER('Table'[Date])&&[Org code]=EARLIER('Table'[Org code])&&[Account Ref]<=EARLIER('Table'[Account Ref])))
return _initial-_culmative

vstephenmsft_0-1695029684042.png

Here's the result.

vstephenmsft_1-1695029695670.png

 

Best Regards,

Stephen Tao

 

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
Anonymous
Not applicable

Hi @Akolade ,

 

You can create a calcualted column. And you need to create a relationship first.

Column = var _initial=RELATED('pot Fund'[InitialFund])
var _culmative=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[Date]<=EARLIER('Table'[Date])&&[Org code]=EARLIER('Table'[Org code])&&[Account Ref]<=EARLIER('Table'[Account Ref])))
return _initial-_culmative

vstephenmsft_0-1695029684042.png

Here's the result.

vstephenmsft_1-1695029695670.png

 

Best Regards,

Stephen Tao

 

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

 

Akolade
Regular Visitor

@amitchandak for your time. What I really need is DAX that will Perform a sort of row context and iteration  for the upper table with a condition
for example: If the Org code = "A" then the amount on that row which is 25 will be duducted from the £2000 in the pot fund table leaving the balance to £1975.
The next row which is Account 2 with the same organisation(A) the Amount (25) will be deduccted from the balance (£1975). The same goes with org code "B"
The idea is to know the balance of the pot fund  at any point in time. 
Thank you



amitchandak
Super User
Super User

@Akolade , Not very clear.

 

Create a common dimension or table org

and analyze with a measure

Sum(Table2[Initial Fund]) - Sum(Table1[Amount])

 

You can use a filter of date and company for Table 1

 

Power BI- DAX: When I asked you to create common tables: https://youtu.be/a2CrqCA9geM
https://medium.com/@amitchandak/power-bi-when-i-asked-you-to-create-common-tables-a-quick-dax-soluti...

 

You might need cumulative for table 1 amount

Continue to explore Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors