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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Substract Values from Same column dynamically based on another field.

I have a table (See below) with prices for different years

 

Capturenew.PNG

 

I have 250 Trade Days in each contract period from 11/01 to 10/31 each year.

 

I need to dynamically select (what if) table or similar a buy and sell Trade day and calculate the profit for each contract year if i were to buy and sell on those days. See below

 

In date: Day of trade

Out Date Day of trade

 

I need a measure that will substract the price from my in trade day to my out trade day. How can I do that?

Capture6.PNG

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Anonymous ,

Please try to update the formula of your measure "Profit" just like below(the red font part is newly add):

Profit =
CALCULATE (
    SUM ( Winter_Contracts_Zema[Price] ),
    FILTER (
        ALL ( Winter_Contracts_Zema[Trade Day - Buy] ),
        Winter_Contracts_Zema[Trade Day - Buy] = [Buy_Trade Value]
    )
)
    CALCULATE (
        SUM ( Winter_Contracts_Zema[Price] ),
        FILTER (
            ALL ( Winter_Contracts_Zema[Trade Day - Buy] ),
            Winter_Contracts_Zema[Trade Day - Buy] = [Sell_Trade Value]
        )
    )

Best Regards

Rena

View solution in original post

Anonymous
Not applicable

I solved it by using the value function in my measure! thanks to everyone who took the time to read this!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

I created this measure

Profit = CALCULATE(SUM(Winter_Contracts_Zema[Price]), Winter_Contracts_Zema[Trade Day - Buy] = [Buy_Trade Value]) - CALCULATE(SUM(Winter_Contracts_Zema[Price]), Winter_Contracts_Zema[Trade Day - Buy] = [Sell_Trade Value])
 
But I get this error
 
A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
 
By trade Value is a parameter table i Created to emulate this dax calculation
 
Profit = CALCULATE(SUM(Winter_Contracts_Zema[Price]), Winter_Contracts_Zema[Trade Day - Buy] = 148  - CALCULATE(SUM(Winter_Contracts_Zema[Price]), Winter_Contracts_Zema[Trade Day - Buy] = 244)
 
I need the trade day filter values to change dynamically by end user, like a parameter. Any ideas?
 
All the help is highly appreciated
Capture8.PNG
Anonymous
Not applicable

Hi @Anonymous ,

Please try to update the formula of your measure "Profit" just like below(the red font part is newly add):

Profit =
CALCULATE (
    SUM ( Winter_Contracts_Zema[Price] ),
    FILTER (
        ALL ( Winter_Contracts_Zema[Trade Day - Buy] ),
        Winter_Contracts_Zema[Trade Day - Buy] = [Buy_Trade Value]
    )
)
    CALCULATE (
        SUM ( Winter_Contracts_Zema[Price] ),
        FILTER (
            ALL ( Winter_Contracts_Zema[Trade Day - Buy] ),
            Winter_Contracts_Zema[Trade Day - Buy] = [Sell_Trade Value]
        )
    )

Best Regards

Rena

Anonymous
Not applicable

Thank you!! my profit measure is now working!

 

This is probably very simple, as it is in excel but I cant figure it out in Power Bi

I need to count the number of times my profit measure gave > 0 results.

 

=COUNTIF(Profit>0")

 

But i get an error in power Bi as it doesnt accept a measure as a filter. Any ideas? Im stuck in something so simple.

 

I also tried Calculate(Count(Winter_Contracts_Year)), [profit] > 0)

 

Capture9.PNG

 

I  highly appreciate the best practice here.

 

 

 

From my 

Anonymous
Not applicable

I solved it by using the value function in my measure! thanks to everyone who took the time to read this!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.