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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Vinothsusai
Helper III
Helper III

Calculate formula column based on Id referred column - power bi desktop

Hi ,

I am new into power bi. 

I have Formula column that each value is referred to the Id column. I need to caculate total amount based on the formula column.

 

Could you please advise how we can acheive this below,

 

1.png

 

Thanks

Vinoth SUSAINATHAN

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Vinothsusai ,

 

To create a measure as below.

Measure = 
VAR maxf =
    MAX ( Table1[formula -extract] )
VAR no =
    LEN ( maxf ) - LEN ( SUBSTITUTE ( maxf, "+", "" ) )
VAR a =
    CALCULATE (
        SUM ( Table1[Amount] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Line ID] <= MAX ( Table1[Line ID] )
                && Table1[Line ID]
                    >= MAX ( Table1[Line ID] ) - no
        )
    )
RETURN
    IF ( maxf = BLANK (), BLANK (), a )

Or a calculated column as below.

Column = 
VAR aa =
    Table1[Line ID]
        - (
            LEN ( Table1[formula -extract] )
                - LEN ( SUBSTITUTE ( Table1[formula -extract], "+", "" ) )
        )
VAR co =
    CALCULATE (
        SUM ( Table1[Amount] ),
        FILTER (
            Table1,
            Table1[Line ID] >= aa
                && Table1[Line ID] <= EARLIER ( Table1[Line ID] )
        )
    )
RETURN
    IF ( Table1[formula -extract] = BLANK (), BLANK (), co )

Capture.PNG

 

Pbix as attached.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
v-frfei-msft
Community Support
Community Support

Hi @Vinothsusai ,

 

To create a measure as below.

Measure = 
VAR maxf =
    MAX ( Table1[formula -extract] )
VAR no =
    LEN ( maxf ) - LEN ( SUBSTITUTE ( maxf, "+", "" ) )
VAR a =
    CALCULATE (
        SUM ( Table1[Amount] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Line ID] <= MAX ( Table1[Line ID] )
                && Table1[Line ID]
                    >= MAX ( Table1[Line ID] ) - no
        )
    )
RETURN
    IF ( maxf = BLANK (), BLANK (), a )

Or a calculated column as below.

Column = 
VAR aa =
    Table1[Line ID]
        - (
            LEN ( Table1[formula -extract] )
                - LEN ( SUBSTITUTE ( Table1[formula -extract], "+", "" ) )
        )
VAR co =
    CALCULATE (
        SUM ( Table1[Amount] ),
        FILTER (
            Table1,
            Table1[Line ID] >= aa
                && Table1[Line ID] <= EARLIER ( Table1[Line ID] )
        )
    )
RETURN
    IF ( Table1[formula -extract] = BLANK (), BLANK (), co )

Capture.PNG

 

Pbix as attached.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thnak you very much

Hi,

Thank you very much for your answer. 

Your mentioned formula works fine for the sequence numbers (For ex 4+4+6...).

If it has non sequence number (For ex. 215+248+250+251+273). it not works. I tried to modify the formula that not works. Could you please advise.

 

21.png

Formula:

Measure =
VAR maxf =
    MAX ( HANGeneralJournals_Remodify[ReportLayout.Formula] )
VAR sub = SUBSTITUTE ( maxf, "D", "" )
VAR no =
    LEN (maxf) - LEN ( SUBSTITUTE ( sub, "+", "" ) )
VAR a =
    CALCULATE (
        SUM ( HANGeneralJournals_Remodify[AccountingCurrencyAmount]  ),
        FILTER (
            ALL ( HANGeneralJournals_Remodify ),
            HANGeneralJournals_Remodify[ReportLayout.Line ID] <= MAX ( HANGeneralJournals_Remodify[ReportLayout.Line ID]  )
                && HANGeneralJournals_Remodify[ReportLayout.Line ID]
                    >= MAX ( HANGeneralJournals_Remodify[ReportLayout.Line ID]  ) - no
        )
    )
RETURN
    IF ( maxf = BLANK (),0 , a )

 

 

Could you please advise.

 

Thanks

Vinoth SUSAINATHAN

parry2k
Super User
Super User

@Vinothsusai does formula always going to be sum of  two rows or it can be more than 2 as well?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi,

Thank you for your reply.

It can be more than 2 as well.

 

Thanks

Vinoth SUSAINATHAN

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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