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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Custom Column sumif

I am trying to create a Gross Margin Mix- for this I would use the following calculations

GrossMargin(per Row) / The Sum of all comparable Gross margins

I have a column with Gross Margin and a Column stating whether the item is comparable (Yes/No) 

The formula can either be based on CY or PY.

 

Powerbi help.PNG

 

Thank you

 

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

You should do this in Power BI with DAX, not Power Query. It will not perform well in Power Query as it isn't designed to dynamically filter tables. See below.

edhans_0-1634230713986.png

Some Measure = 
VAR varComparable = SELECTEDVALUE('Table'[Comparable])
VAR varNumerator = SUM('Table'[Gross Margin CY])
VAR varDenominator = 
    CALCULATE(
        SUM('Table'[Gross Margin PY]),
        'Table'[Comparable] = varComparable
    )
RETURN
    DIVIDE(varNumerator, varDenominator, BLANK())

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

You should do this in Power BI with DAX, not Power Query. It will not perform well in Power Query as it isn't designed to dynamically filter tables. See below.

edhans_0-1634230713986.png

Some Measure = 
VAR varComparable = SELECTEDVALUE('Table'[Comparable])
VAR varNumerator = SUM('Table'[Gross Margin CY])
VAR varDenominator = 
    CALCULATE(
        SUM('Table'[Gross Margin PY]),
        'Table'[Comparable] = varComparable
    )
RETURN
    DIVIDE(varNumerator, varDenominator, BLANK())

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.