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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Nicpet0
Regular Visitor

Calculating unique combination from different tables

Hi Community

I am facing an issue in Power Bi with a DAX measure i am trying to create. (See below the pasted code, as it looks currently)

I am trying to count each occurence of the unique combination of [Variant Item No], [Variant Code] and [Sales Person Name] whenever there as a sale where the Gross Margin % is negative. The first to mentioned fields comes from the same table 'Variant' while Sales Person comes from its own table. They are indirect linked through a 'Sales' table. 

What i am looking for is the most memory efficient DAX code that can achieve what i described above. Whenever i just have the combination of Variant Item No and Variant Code it runs fine, but it is when i also want to combine a field from another table where it becomes increasingly more taxing for it to run. 

Any advide is helpful, thank you.


Count of Negative Margin =
VAR Groups =
    SUMMARIZECOLUMNS(
        'Variant'[Variant Item No],
        'Variant'[Variant Code],
        'Sales Person'[Sales Person Name]
    )
RETURN
    COUNTROWS(
        FILTER(
            Groups,
            CALCULATE( [Gross Margin 2 %] ) < 0
        )
    )
2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

I think your code just needs a little tweak

Count of Negative Margin =
VAR Groups =
    SUMMARIZECOLUMNS (
        'Variant'[Variant Item No],
        'Variant'[Variant Code],
        'Sales Person'[Sales Person Name],
        "@gross margin", [Gross Margin 2 %]
    )
RETURN
    COUNTROWS ( FILTER ( Groups, [@gross margin] < 0 ) )

By including the measure in the SUMMARIZECOLUMNS you will only return combinations of item no, code and sales person which have made sales, rather than all possible combinations which your original code would do. You can then filter that for values below 0.

View solution in original post

Thanks, that did the trick!

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

I think your code just needs a little tweak

Count of Negative Margin =
VAR Groups =
    SUMMARIZECOLUMNS (
        'Variant'[Variant Item No],
        'Variant'[Variant Code],
        'Sales Person'[Sales Person Name],
        "@gross margin", [Gross Margin 2 %]
    )
RETURN
    COUNTROWS ( FILTER ( Groups, [@gross margin] < 0 ) )

By including the measure in the SUMMARIZECOLUMNS you will only return combinations of item no, code and sales person which have made sales, rather than all possible combinations which your original code would do. You can then filter that for values below 0.

Thanks, that did the trick!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.