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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
martynaaagesen
Regular Visitor

Difference based on dynamic filter

Hi

I tried to search the forum for the answer, but I didnt quite find one that can help me. 

 

I have a table structured like below. BudgetID is my filter on the page, where I am selecting multiple different values. It is a column with multiple and not unique values. Selection I make is dynamic and I need to capture that. 

I also have a total in column CcTotalContractPaymentCBY. That Total I show as a sum. So per BudgetID - sum of CcTotal. 

 

martynaaagesen_0-1655206333141.png

 

Now, what I need is to show the difference between CcTotal, based on dynamic filter on the Page, also having a logic (CcTotal, filtered by BudgetID lower value - CcTotal, filtered by BudgetID higherValue)

 

 

You cannot imagine how greatful I will be, if you can help me out. 

 

4 REPLIES 4
martynaaagesen
Regular Visitor

Hi Again, Sorry it took me so much time.. I am not sure if the above works, MAYBE it does.. but the issue I have now, is that I am selecting those 2 budgetID's on the pages filter. This measure seems to disregard that fact and somehow when I throw it on the visual, it keeps it away.

 

any advice?

tamerj1
Community Champion
Community Champion

Hi @martynaaagesen 
If you are slicing by ID then it is simply the difference between the max and the min

=
VAR MaxCcTotal =
    MAX ( TableName[CcTotalContractPaymentCBY] )
VAR MinCcTotal =
    MIN ( TableName[CcTotalContractPaymentCBY] )
RETURN
    MinCcTotal - MaxCcTotal

thank you  for quick response! 

Unfortunately, I was not clear enough.

I am slicing by BudgetID. And I have 2 selected on the page. 

 

So I need to have a difference based on the BudgetID. BudgetID MAX and BudgetID MIN (as it is dynamic)

 

martynaaagesen_0-1655211123699.png

 

Hi @martynaaagesen 

A clean way to do that is by utilizing the column totals to disply the difference value. Activate the columns total from the visual format options and change the name from "Total" to "Difference". 

In the values of the matrix place this measure instead of the old one

=
VAR SelectedIDs =
    ALLSELECTED ( TableName[BudgetID] )
VAR MaxID =
    MAXX ( SelectedIDs, TableName[BudgetID] )
VAR MinID =
    MINX ( SelectedIDs, TableName[BudgetID] )
VAR MaxIDCcTotal =
    CALCULATE (
        SUM ( TableName[CcTotalContractPaymentCBY] ),
        TableName[BudgetID] = MaxID
    )
VAR MinIDCcTotal =
    CALCULATE (
        SUM ( TableName[CcTotalContractPaymentCBY] ),
        TableName[BudgetID] = MinID
    )
VAR CcTotal =
    SUM ( TableName[CcTotalContractPaymentCBY] )
RETURN
    IF ( HASONEVALUE ( TableName[BudgetID] ), CcTotal, MaxIDCcTotal - MinIDCcTotal )

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.