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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
HAM
Frequent Visitor

Sum amount based on account range

Lets say I have two tables. Entry Table: 

AccAmount
150
2100
370
435
560
320

 

and Account table:

NoFromTo
113
235
324
413
54

5

 

There's a relationship based on 'Acc' column and 'No' column. I want to calculate the sum of Amounts for each Account No based on the coresponding Account range (From, To). For example, for Account No 1, i want to be able to add 50+100+70+20 (and get 240 as the result) and for Account No 2 70+20+35+60. How can this be done.

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi @HAM 

 

Would a measure like this help?

 

Total in Range = 
    SUMX(
        ADDCOLUMNS(
            'Account',
            "__amt",
                VAR _From = [From]
                VAR _To = [To]
                VAR _Res =
                    CALCULATE(
                        SUM( 'Entries'[Amount] ),
                        FILTER( 
                            ALL( 'Entries' ),
                            'Entries'[Acc] >= _From
                                && 'Entries'[Acc] <= _To
                        )
                    )
                RETURN
                    _Res
        ),
        [__amt]
    )

 

 

or a calculated column

Total in Range CC = 
CALCULATE(
    SUMX(
        ADDCOLUMNS(
            'Account',
            "__amt",
                VAR _From = [From]
                VAR _To = [To]
                VAR _Res =
                    CALCULATE(
                        SUM( 'Entries'[Amount] ),
                        FILTER( 
                            ALL( 'Entries' ),
                            'Entries'[Acc] >= _From
                                && 'Entries'[Acc] <= _To
                        )
                    )
                RETURN
                    _Res
        ),
        [__amt]
    )
)

 

Let me know if you have any questions.

 

Sum of amount based on account range.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

View solution in original post

4 REPLIES 4
bhanu_gautam
Super User
Super User

@HAM , You can first add one calculated column in Entry table using below method

 

Account Number =
VAR CurrentAcc = EntryTable[Acc]
RETURN
CALCULATE(
MAX('Account Table'[No]),
'Account Table'[From] <= CurrentAcc && (ISBLANK('Account Table'[To]) || CurrentAcc <= 'Account Table'[To])
)

 

Then you can create one measure for sum using

 

Total Amount =
CALCULATE(
SUM(EntryTable[Amount]),
ALLEXCEPT(EntryTable, EntryTable[Account Number])
)

 

Please accept as solution and give kudos if it helps




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thank you for your response but this doesn't work

Hi @HAM 

 

Would a measure like this help?

 

Total in Range = 
    SUMX(
        ADDCOLUMNS(
            'Account',
            "__amt",
                VAR _From = [From]
                VAR _To = [To]
                VAR _Res =
                    CALCULATE(
                        SUM( 'Entries'[Amount] ),
                        FILTER( 
                            ALL( 'Entries' ),
                            'Entries'[Acc] >= _From
                                && 'Entries'[Acc] <= _To
                        )
                    )
                RETURN
                    _Res
        ),
        [__amt]
    )

 

 

or a calculated column

Total in Range CC = 
CALCULATE(
    SUMX(
        ADDCOLUMNS(
            'Account',
            "__amt",
                VAR _From = [From]
                VAR _To = [To]
                VAR _Res =
                    CALCULATE(
                        SUM( 'Entries'[Amount] ),
                        FILTER( 
                            ALL( 'Entries' ),
                            'Entries'[Acc] >= _From
                                && 'Entries'[Acc] <= _To
                        )
                    )
                RETURN
                    _Res
        ),
        [__amt]
    )
)

 

Let me know if you have any questions.

 

Sum of amount based on account range.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!
HAM
Frequent Visitor

@gmsamborn Thank you so much. The measure and the calculated column both work!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.