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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
analyser
New Member

Exclude rows from measure

I have a large transactions table (600M+ records). The table has both revenues and expenses records.

 

I have a measure that calculate a profit % = (revenue - expense) / revenue

 

Record #ContractTransaction TypeArea IDProduct IDAmount $....
11Revenue15198$123 
21Expense15198$2525 
31Expense15198$232 
42Revenue54874$15 
52Revenue54874$23 
62Expense54874$84 
73Revenue1980$0 
83Expense1980$123 
93Expense1980$646 
 ....     

 

I want to exclude all records from my profit % measure if the sum of revenue for a contract is zero. For example, I want to exclude records 7-9 from my measure. How?? 

Thank you! 

6 REPLIES 6
FreemanZ
Super User
Super User

Hi @analyser ,

 

not sure if i really get you, try like:

measure = 
VAR _table = 
FILTER(
    ADDCOLUMNS(
        SUMMARIZE(
            data,
            data[contract]
        ),
        "Revenue",
        CALCULATE(SUM(data[Amount $]), data[transaction type] = "Revenue"),
        "Expense",
        CALCULATE(SUM(data[Amount $]), data[transaction type] = "Expense")
    ),
    [Revenue]<>0
)
VAR _result = SUMX(_table, [Revenue])/SUMX(_table, [Expense]) -1 
RETURN _result

 

it worked like:

FreemanZ_0-1733896299758.png

 

For profit, i use (revenue-expense)/expense. so it was ((123+15 + 23) - (2525 + 84)) / (2525 + 84)

Poojara_D12
Memorable Member
Memorable Member

Hi @analyser 

To exclude records where the sum of revenue for a given contract is zero, you can modify your Profit % measure to check for this condition. Specifically, you'll need to use a DAX formula that ensures that only contracts with a positive revenue are included in the calculation. Here’s how you can adjust your DAX measure:

 

Profit Percentage = 
VAR TotalRevenue = 
    CALCULATE(
        SUM(Transactions[Amount $]),
        Transactions[Transaction Type] = "Revenue"
    )

VAR TotalExpense = 
    CALCULATE(
        SUM(Transactions[Amount $]),
        Transactions[Transaction Type] = "Expense"
    )

RETURN 
    IF(TotalRevenue = 0, BLANK(), (TotalRevenue - TotalExpense) / TotalRevenue)

 

The BLANK() function causes Power BI to ignore these records, ensuring that they do not affect your visualizations.

This approach efficiently handles large datasets because the filter is applied at the contract level, reducing the impact of irrelevant data.

 

This solution should work for your case, as it ensures that contracts with zero revenue are excluded from your profit percentage calculation.

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Conceptshttps://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

Semaj06Fr
Regular Visitor

I wuld need an exemple of your data model with cleaned datas to help you

 

Semaj06Fr
Regular Visitor

Hi

 

Please try this code

Semaj06Fr_0-1733864579474.png

Profit% =
VAR _contract =
SELECTEDVALUE ( 'Table (2)'[Contract] )
VAR Rev =
CALCULATE (
SUM ( 'Table (2)'[Amount $] ),
'Table (2)'[Transaction Type] = "Revenue"
)
VAR exp =
CALCULATE (
SUM ( 'Table (2)'[Amount $] ),
'Table (2)'[Transaction Type] = "Expense"
)
VAR result =
IF ( Rev <> 0, DIVIDE ( Rev - Exp, Rev, 0 ) )
RETURN
result

I get a blank result when I try this. 

 

I think because all my of visuals are not at for contracts? I have a bunch of tables that are joined to the transactions table. For example I have a regions table that is joined to the transactions table above using the contract field. I want to aggregate the profit calc % by region. 

Hi @analyser ,

 

Could you tell me if your issue has been solved? If it is, kindly Accept the helpful reply as the solution.
Or you can share your workaround and mark it as the the solution. Then more people will benefit from it.

Or you are still confused about it, I think you issue should be caused by your data model.
Please share us with a sample file without sensitive data. You can also show us a screenshot with the result you want.

This will make us easier to find the solution.


Best Regards,

Rico Zhou

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.