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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
laetitiaf
Frequent Visitor

Calculating invoice margin total

Hey, 

 

I'm stuck on how I can summarise the invoice margin for the whole invoice and was wondering how this can be achieved in a dax measure?

 

For example, in this table, we have each SKUs margin (in red), but next to it I want to be able to see the total margin for the same invoice number

laetitiaf_0-1730765965843.png

So the above "margin invoice total" should correlate with the below.

laetitiaf_1-1730766146094.png

 

 

1 ACCEPTED SOLUTION

Hi @laetitiaf ,

Please create a measure as below to get it and check if it can return the correct result...

Margin Invoice Total =
VAR _invnum =
    SELECTEDVALUE ( 'Table'[Invoice Number] )
RETURN
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Invoice Number] = _invnum ),
        [Margin]
    )

If the above one can't help you figure out, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

Community Support Team _ Rena
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

5 REPLIES 5
v-yiruan-msft
Community Support
Community Support

Hi @laetitiaf ,

Whether your problem has been resolved? If yes, could you please mark the helpful reply as Answered? It would be helpful for others in the community if they face the similar problem as yours. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@laetitiaf ,

you need a measure like

calculate([Margin], allexcept(Table, Table[Invoice Number]))

 

 

calculate([Margin], filter(allselected(Table), Table[Invoice Number]) = max(Table[Invoice Number]) ) ) 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

First syntax I get an error stating that the query has exceeded the available resources - I also have the data filtered down to todays date

Hi @laetitiaf ,

Please create a measure as below to get it and check if it can return the correct result...

Margin Invoice Total =
VAR _invnum =
    SELECTEDVALUE ( 'Table'[Invoice Number] )
RETURN
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Invoice Number] = _invnum ),
        [Margin]
    )

If the above one can't help you figure out, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

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

Hi Rena, 

 

Apologies I have only been able to look back at this now.
Your solution works, but still results in breaking the visual, resulting in a query exceededs the available resources error when I add in anything from the "SKU" table.

laetitiaf_1-1737598505105.png

 

Example of the data output that is sufficient 

SKUQuantityCost (per unit)Sell Price (per unit)MarginMargin invoice totalInvoice NumberCustomer ID
560354.145.4924.59%18.28%D2783556793
5916210.2311.511.04%18.28%D2783556793
38483116.6821.8523.66%18.28%D2783556793
443472148.66176.1715.62%18.28%D2783556793
443472315.9374.3615.62%18.28%D2783556793
451361129.73150.5113.81%18.28%D2783556793
47712211.4314.9723.65%18.28%D2783556793
489712112.73121.757.41%7.41%D2783868223
5010119.1122.3714.57%21.41%D2784154426
5034410.010 21.41%D2784154426
681933.74.8523.71%21.41%D2784154426
682923.534.6824.57%21.41%D2784154426
10888123.5130.823.67%21.41%D2784154426
38724133.54.1916.47%21.41%D2784154426
38728315.4820.2823.67%21.41%D2784154426
3872914.385.4820.07%21.41%D2784154426
42133205.196.823.68%21.41%D2784154426
42492127.0533.8119.99%21.41%D2784154426
48880436.2447.4923.69%21.41%D2784154426

 

Then once "Product Name" is added, query exceededs the available resources 
laetitiaf_2-1737602368075.png

SKU Product NameQuantityCost (per unit)Sell Price (per unit)MarginMargin invoice totalInvoice NumberCustomer ID
5603Premium Black Nylon Cable Ties, 300mm (Pack of 10)54.145.4924.59%18.28%D2783556793
5916Heavy-Duty Stainless Steel Hose Clamps210.2311.511.04%18.28%D2783556793
38483Weatherproof Junction Box, IP68 Rated116.6821.8523.66%18.28%D2783556793
44347Industrial-Grade Cable Glands (Pack of 5)2148.66176.1715.62%18.28%D2783556793
44347Industrial-Grade Cable Glands (Pack of 5)2315.9374.3615.62%18.28%D2783556793
45136Multi-Purpose Electrical Insulation Tape, 10m Roll1129.73150.5113.81%18.28%D2783556793
47712UV Resistant Cable Clips, 25mm (Pack of 50)211.4314.9723.65%18.28%D2783556793
48971High-Performance Surge Protector Power Board2112.73121.757.41%7.41%D2783868223
5010Compact LED Floodlight, 30W119.1122.3714.57%21.41%D2784154426
50344Durable PVC Conduit, 20mm (2m Length)10.010 21.41%D2784154426
6819Modular Circuit Breaker, 16A33.74.8523.71%21.41%D2784154426
6829Advanced Digital Timer Switch, 24-Hour Programmable23.534.6824.57%21.41%D2784154426
10888Flexible Heat Shrink Tubing Assortment123.5130.823.67%21.41%D2784154426
38724Waterproof LED Strip Light Kit, 5m133.54.1916.47%21.41%D2784154426
38728Smart Wi-Fi Plug with Energy Monitoring315.4820.2823.67%21.41%D2784154426
38729High-Torque Electric Screwdriver Kit14.385.4820.07%21.41%D2784154426
42133Compact Power Distribution Board, 4-Way205.196.823.68%21.41%D2784154426
42492Adjustable Cable Tray System, 600mm127.0533.8119.99%21.41%D2784154426
48880Low-Voltage Garden Lighting Transformer436.2447.4923.69%21.41%D2784154426

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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