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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
v-stephen-msft
Community Support
Community Support

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
v-stephen-msft
Community Support
Community Support

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

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.