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
ChuckChuck
Helper I
Helper I

Use a variable in a measure as a filter within same measure

I have a measure that I need to take one step further, but can't figure out the solution to make it work. Using the below measure I can determine the variance for each customer. However, I only want to return the results if the variance shows underperformance (i.e. variable Underperforming >0). Is it possible to add this last filter to the measure so that only underperforming values are picked up? Each time I try a filter, it's looking for a table, but I want the filter to be on the variable itself.  Currently it's retruning True or False, but I want the actual dollars and only where it's underperfoming. 

 

Total Month Expected vs Actual =

    VAR

    Underperforming = 

        CALCULATE(

        [Month Expected]-[Month Actuals],

        FILTER(Table1,[Frequency]="Only Once") ,

        FILTER(Table2,[Date]=Table3[Max Expected Date]))

    Return

Underperforming>0

13 REPLIES 13
Zubair_Muhammad
Community Champion
Community Champion

@ChuckChuck

 

Do you need this???

 

Total Month Expected vs Actual =
VAR Underperforming =
    CALCULATE (
        [Month Expected] - [Month Actuals],
        FILTER ( Table1, [Frequency] = "Only Once" ),
        FILTER ( Table2, [Date] = Table3[Max Expected Date] )
    )
RETURN
    IF ( Underperforming > 0, underperforming )

 

Thanks, @Zubair_Muhammad! Almost, but not exactly. I got this far too, but gave up on this version of the measure because won't actually display the grand total of just the underperforming values. If in a table I can get the expected results to appear, but the grand total for the table is still showing the total without that last filter applied (so ignoring if it's underperforming or not). I also have a card visual and since the net of all accounts is not underperforming, the value displayed in the card is not correct. 

HI @ChuckChuck

 

Normally you can use this pattern to get correct totals for the MEASURE

Try creating another MEASURE on these lines

 

New Measure =
IF (
    HASONEFILTER ( TableName[ColumnName] ),
    [Total Month Expected vs Actual ],
    SUMX (
        ALLSELECTED ( TableName[ColumnName] ),
        [Total Month Expected vs Actual ]
    )
)

Hi @Zubair_Muhammad. I've added the second measure to reference the first. However, the results are simply adding up the total of all values and not just the total where the customer is underperforming to expectations. 

Hello,
If I correct undrestud, you are tracking performance by Customer. Try this approach (in example I use dimension table Customer with attribute Customer Name):

 

Total Month Expected vs Actual =
SUMX (
    ADDCOLUMNS (
        VALUES ( Customer[Customer Name] ),
        "UnderPerforming", CALCULATE (
            [Month Expected] - [Month Actuals],
            FILTER ( Table1, [Frequency] = "Only Once" ),
            FILTER ( Table2, [Date] = Table3[Max Expected Date] )
        )
    ),
    IF ( [UnderPerforming] > 0, [UnderPerforming] )
)

Thanks, @popov. I've given this a try, but the resutls where only returned for one of the 15 customers and those results weren't correct. If I remove the SUMX part and just do the ADDCOLUMNS part, I get an error "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value." Do you know what this indicates?

Hello, @ChuckChuck
Sorry for my delay. Can you share your formula (based my formula) and screenshots for current and expected result?

Hi @popov, I made some test data and applied the measure to it and then created some screen grabs. This is close to what I need, but it is picking up the values for dates I'm not interested in and it's not giving me a total, just blank. 2018-03-19_9-06-32.jpg

 

 

 

Hi, @ChuckChuck

Try this formula

Total Month Expected vs Actual =
SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( Sheet1, Sheet1[Customer Name], Sheet1[Expected Date] ),
        "UnderPerforming", CALCULATE (
            [Month Expected] - [Month Actuals],
            FILTER ( Sheet1, [Frequency] = "Only Once" )
        )
    ),
    IF ( [UnderPerforming] > 0, [UnderPerforming] )
)

Hi @popov, Unfortunately this version still isn't producing the desired results. In fact, when I add a table to just show the measure for each customer name the table is excluding records and the measure doesn't add up correctly. Here's a screenshot:

2018-03-21_7-07-06.jpg

Hello, can you share your pbix file to test?

Hi @popov

I don't see an option to attach a PBIX file. Were you able to get the formula to work on a similar set of data on your end?

Hello, @ChuckChuck

You can upload it to OneDrive or Dropbox and post the link here.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.