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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JamesGordon
Helper II
Helper II

Summarised Data

Hi,


I have been trying to find a way to either create calculated columns with my data or a summarised table.


We have unique stock numbers that have multiple transactions of invoices and credits. I am looking to create a table to summarise the following information, Stock Number, Lowest Invoice number that relates to that stock number, the Invoice date that relates to that invoice number, and then add up all sales and cost values for that stock number.


Below is a screenshot of what i am trying to achieve which hopefully makes sense? The top table is the orignal data for two items and the lower table is what i am trying to achieve?


I have tried numerous DAX combinations but no luck! Does anyone have any suggestions ideas?

Power Bi Ques 23.jpg

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@JamesGordon 

This can also be done in Power Query (perhaps best) but here is a DAX solution. Create a new calculated table:

New table = 
ADDCOLUMNS (
    FILTER (
        ALLEXCEPT ( Table1, Table1[Sales Val], Table1[Cost Val] ),
        VAR minInvNo_ =
            CALCULATE ( MIN ( Table1[Inv No] ), ALLEXCEPT ( Table1, Table1[Stock No] ) )
        RETURN
            Table1[Inv No] = minInvNo_
    ),
    "Sales Val", CALCULATE ( SUM ( Table1[Sales Val] ), ALLEXCEPT ( Table1, Table1[Stock No] ) ),
    "Cost val", CALCULATE ( SUM ( Table1[Cost Val] ), ALLEXCEPT ( Table1, Table1[Stock No] ) )
)

See it all at work in the attached file. 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

5 REPLIES 5
AntrikshSharma
Super User
Super User

@JamesGordon - Try this.. the file is attached below my signature. Let me know if it works for you.

1.png

 

New table =
VAR MinInvoicePerStock =
    SUMMARIZECOLUMNS ( James[Stock No], "MinInv", MIN ( James[Inv No] ) )
VAR MaintainLineage =
    TREATAS ( MinInvoicePerStock, James[Stock No], James[Inv No] ) 
    -- By using TREATAS we inforce a data lineage that treats newly 
    -- added virtual column MinInv as a part of the model
VAR Result =
    CALCULATETABLE ( James, MaintainLineage )
RETURN
    Result

 

It produces efficient internal queries with no bottleneck.2.png

AlB
Community Champion
Community Champion

@JamesGordon 

This can also be done in Power Query (perhaps best) but here is a DAX solution. Create a new calculated table:

New table = 
ADDCOLUMNS (
    FILTER (
        ALLEXCEPT ( Table1, Table1[Sales Val], Table1[Cost Val] ),
        VAR minInvNo_ =
            CALCULATE ( MIN ( Table1[Inv No] ), ALLEXCEPT ( Table1, Table1[Stock No] ) )
        RETURN
            Table1[Inv No] = minInvNo_
    ),
    "Sales Val", CALCULATE ( SUM ( Table1[Sales Val] ), ALLEXCEPT ( Table1, Table1[Stock No] ) ),
    "Cost val", CALCULATE ( SUM ( Table1[Cost Val] ), ALLEXCEPT ( Table1, Table1[Stock No] ) )
)

See it all at work in the attached file. 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

@AlBthat worked perfectly!!! Thank you!

JamesGordon
Helper II
Helper II

@AntrikshSharmahere is a link to the sample data (it wont let me attached a file to this thread)

https://jamesgordon-my.sharepoint.com/:x:/g/personal/james_moss_jgordon_co_uk/EVYKstDyVzNOtMfBxaRZLw...

AntrikshSharma
Super User
Super User

@JamesGordon  Should be easy if you could attach a sample file as well.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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