Forum Discussion

Akolade's avatar
Akolade
Regular Visitor
2 years ago
Solved

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

  • Anonymous's avatar
    Anonymous
    2 years ago

    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

    Here's the result.

     

    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.           

     

3 Replies

  • 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-solution-8e3eccb41bda

     

    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

     

     

  • Akolade's avatar
    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



  • Anonymous's avatar
    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

    Here's the result.

     

    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.