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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
PBIuser73
Helper I
Helper I

Summarize values on multiple rows based on value in one of the rows

Hi. 

I have a table like this: 

OrdernoArticlecodeAmount
10001246211100
10001MDAHELG400
10002299093400
10002MDAHELG400
10002365256600
10003299095300
10004366494500
10004MDAHELG400

 

I want to summarize the amounts on only a few of this rows.

I want to summarize the rows that have this Articlecodes (hardcode is ok):

* 246211, 299093 and 299095

BUT i also want to add the sum for the rows that have the code MDAHELG and have the same orderno as the rows with the same Articlecodes as above) 246211, 299093 and 299095)

 

Like this:

OrdernoArticlecodeAmount
10001246211100
10001MDAHELG400
10002299093400
10002MDAHELG400
10002365256600
10003299095300
10004366494500
10004MDAHELG400

 

The Articlecode  365256 and 366494 are not going to be summarized and either MDAHELG that are related to Orderno 10004 with Articlecode 366494.

The sum should be 1600.


1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PBIuser73 ,

 

I think you can try this code to create a measure.

Measure = 
VAR _LIST = { "246211", "299093", "299095" }
VAR _ArticlecodeList = { "246211", "299093", "299095", "MDAHELG" }
VAR _OrdernoList =
    CALCULATETABLE (
        VALUES ( 'Table'[Orderno] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Articlecode] IN _LIST )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            'Table',
            'Table'[Orderno]
                IN _OrdernoList
                    && 'Table'[Articlecode] IN _ArticlecodeList
        )
    )

Result is as below.

vrzhoumsft_0-1724660221027.png

Best Regards,
Rico Zhou

 

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
Sahir_Maharaj
Super User
Super User

Hello @PBIuser73,

 

Can you please try the following:

TotalAmount =
CALCULATE(
    SUM('Table'[Amount]),
    'Table'[Articlecode] IN {"246211", "299093", "299095", "MDAHELG"},
    'Table'[Orderno] IN
        CALCULATETABLE(
            VALUES('Table'[Orderno]),
            'Table'[Articlecode] IN {"246211", "299093", "299095"}
        )
)

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi.

It did not work. The amount got a lot bigger than expected.

Frank

Anonymous
Not applicable

Hi @PBIuser73 ,

 

I think you can try this code to create a measure.

Measure = 
VAR _LIST = { "246211", "299093", "299095" }
VAR _ArticlecodeList = { "246211", "299093", "299095", "MDAHELG" }
VAR _OrdernoList =
    CALCULATETABLE (
        VALUES ( 'Table'[Orderno] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Articlecode] IN _LIST )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            'Table',
            'Table'[Orderno]
                IN _OrdernoList
                    && 'Table'[Articlecode] IN _ArticlecodeList
        )
    )

Result is as below.

vrzhoumsft_0-1724660221027.png

Best Regards,
Rico Zhou

 

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

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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