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
KA95
Helper III
Helper III

How do I only sum up certain values on a matrix (sum measure might be needed)

Hi there,

I have a matrix visual that's built off two datasets, Lineitems and Deals, on this test dataset there are 3 deal names (schools) and each School has several lineitems that are either lineitem type assembly or workshop, and a year group of 7, 8, 9 with a quantity value. As shown below:

 

KA95_0-1653522272832.png

I don't want this visual to sum up duplicates, so for London School I want the total to be 1400 for both Assembly and Workshop. If a Deal has the exact same figures on Assembly and the exact same figures on Workshop, I only want to add up either one or the other, if that makes sense. 

So London and Manchester Schools have duplicate values, I only want one LineItem Type summed up or the other. Whereas Newcastle School I want summing up entirely because all values on the LineItem types are different. 

The value that I'm using to sum this data up is [quantity], would this need to be a measure? Here are the sample datasets below so people can understand what the data is.

LineItem Table

LineItem IDDeal IDLineitem TypeYear GroupQuantity
1001101Assembly7500
1002101Assembly8500
1003101Assembly9400
1004101Workshop7500
1005101Workshop8500
1006101Workshop9400
1007102Assembly7320
1008102Assembly8320
1009102Assembly9320
1010102Workshop7320
1011102Workshop8320
1012102Workshop9320
1013103Assembly7160
1014103Assembly8340
1015103Assembly9350
1016103Workshop7200
1017103Workshop8245
1018103Workshop9400

 

Deal Table

Deal IDDeal Name
101London School
102Manchester School
103Newcastle School

 

1 ACCEPTED SOLUTION

Hi @KA95,

My bad. Lineitem ID shouldn't have been included in the calcuation. The updated formula is

Unique Sum = 
SUMX (
    SUMMARIZE ( LineItem, LineItem[Year Group], LineItem[Quantity] ),
    LineItem[Quantity]
)


Here's the sample output:

danextian_0-1653537322368.png

 


This should have worked with just the given data. Basically, it creates a temporary table of Year Group and LineItem Quantity thus ignoring Lineitem Type. The logic is very similar to selecting columns in Excel as criteria for removing duplicates.  Alternatively you can do this in Power Query or by creating a calculated column in DAX to include just one of those with duplicates. Here's a sample calculated column formula in DAX.

With Duplicate = 
VAR _OtherLineitemType =
    CALCULATE (
        MAX ( LineItem[Quantity] ),
        FILTER (
            LineItem,
            LineItem[Year Group] = EARLIER ( LineItem[Year Group] )
                && LineItem[Deal ID] = EARLIER ( LineItem[Deal ID] )
                && LineItem[Lineitem Type]
                    < EARLIER ( LineItem[Lineitem Type] ) //what is less than Workshop in alphabetical order is Assembly, works if there are only two line item types 
        )
    )
RETURN
    LineItem[Quantity] = _OtherLineitemType
   

 

Please refer to this PBIX for your reference: https://drive.google.com/file/d/1Rnlav71Z0idt6lVRmyI70kjI6JgBLrqe/view?usp=sharing 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @KA95 ,

If I get it right, you want to ignore Lineitem Type from your calculation and just based it on all the other columns.  This formula, hopefully, should do the trick. Otherwise please elaborate.

Unique Sum = 
SUMX (
    SUMMARIZE ( LineItem, LineItem[Year Group], LineItem[LineItem ID], LineItem[Quantity] ),
    LineItem[Quantity]
)

danextian_0-1653525779169.png

danextian_1-1653525789356.png

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

No I don't want to ignore it. 

Basically I want it to detect if there are duplicates. So for example, for London School, Assembly and Workshop have the exact same values for year 7, 8, and 9. I want it to only sum up one lineitem type, so the total sum for London School is 1400, instead of 2800. This is exactly the same for Manchester School.

However, for Newcastle School, I want it summed up the way it is as the values from Assembly and Workshop are different and not the same.

Hi @KA95,

My bad. Lineitem ID shouldn't have been included in the calcuation. The updated formula is

Unique Sum = 
SUMX (
    SUMMARIZE ( LineItem, LineItem[Year Group], LineItem[Quantity] ),
    LineItem[Quantity]
)


Here's the sample output:

danextian_0-1653537322368.png

 


This should have worked with just the given data. Basically, it creates a temporary table of Year Group and LineItem Quantity thus ignoring Lineitem Type. The logic is very similar to selecting columns in Excel as criteria for removing duplicates.  Alternatively you can do this in Power Query or by creating a calculated column in DAX to include just one of those with duplicates. Here's a sample calculated column formula in DAX.

With Duplicate = 
VAR _OtherLineitemType =
    CALCULATE (
        MAX ( LineItem[Quantity] ),
        FILTER (
            LineItem,
            LineItem[Year Group] = EARLIER ( LineItem[Year Group] )
                && LineItem[Deal ID] = EARLIER ( LineItem[Deal ID] )
                && LineItem[Lineitem Type]
                    < EARLIER ( LineItem[Lineitem Type] ) //what is less than Workshop in alphabetical order is Assembly, works if there are only two line item types 
        )
    )
RETURN
    LineItem[Quantity] = _OtherLineitemType
   

 

Please refer to this PBIX for your reference: https://drive.google.com/file/d/1Rnlav71Z0idt6lVRmyI70kjI6JgBLrqe/view?usp=sharing 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thank you very much @danextian that worked perfectly. 

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.