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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
patri0t82
Post Patron
Post Patron

Simple (Hopefully) filter calculation

Hello, Here's my formula. It's telling me the Expression refers to multiple columns.

 

 

Count-Jobs (NEW) = 
VAR SelectedYear =
    SELECTEDVALUE ( CalendarTable[Year] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Jobs[JobUnique] ),
        FILTER (
            FILTER ( ButaneSchedule, ButaneSchedule[Year] = SelectedYear ),
            IF (
                SELECTEDVALUE ( CalendarTable[Date] ) >= ButaneSchedule[Begin]
                    && SELECTEDVALUE ( CalendarTable[Date] ) <= ButaneSchedule[End],
                FILTER (
                    Jobs,
                    Jobs[Area] = SELECTEDVALUE ( Areas[Area] )
                        && Jobs[JobAbbr] <> "V"
                        && Jobs[JobAbbr] <> "V1"
                        && Jobs[JobAbbr] <> "V2"
                        && Jobs[JobAbbr] <> "V3"
                        && Jobs[JobAbbr] <> "T"
                        && Jobs[JobAbbr] <> "S"
                        && Jobs[JobAbbr] <> "B"
                        && Jobs[JobAbbr] <> "O"
                        && Jobs[JobAbbr] <> "TA"
                        && Jobs[JobAbbr] <> "SE"
                        && Jobs[JobAbbr] <> "BT"
                ),
                FILTER (
                    Jobs,
                    Jobs[Area] = SELECTEDVALUE ( Areas[Area] )
                        && Jobs[JobAbbr] <> "V"
                        && Jobs[JobAbbr] <> "V1"
                        && Jobs[JobAbbr] <> "V2"
                        && Jobs[JobAbbr] <> "V3"
                        && Jobs[JobAbbr] <> "T"
                        && Jobs[JobAbbr] <> "S"
                        && Jobs[JobAbbr] <> "B"
                        && Jobs[JobAbbr] <> "O"
                        && Jobs[JobAbbr] <> "TA"
                        && Jobs[JobAbbr] <> "SE"
                )
            )
        )
    )

 

 

 

 

Basically all I'm looking to do is "if the selected calendar date falls within the date range then distinct count based on *these* filters, otherwise, disctinctcount based on *those* filters

5 REPLIES 5
SanderVeeken
Helper III
Helper III

Do you have some sample data to tinker with?
FILTER returns a table, not a single column. Also the arguments after the first of a CALCULATE statement are already filters, so I'm not sure you need all of the FILTER statements.

Thanks for responding. I'm not exactly sure I can get you sample data. I'd basically have to dummify my whole report with all its data. I'll try to come up with another solution before attempting that, if possible. I guess I'm just missing the point a little though, I mean, I'm trying to return a DISTINCTCOUNT based on some filter criteria - that seems like it would be a normal thing to do doesn't it?

Have you tried it without all the explicit FILTER statements?
Because basically CALCULATE already works that way;

CALCULATE(Expression, Filter1, Filter2, etc.)

I believe this is a little bit cleaner, but I need to somehow incorporate a filter to ensure the ButaneSchedule table is filtered on the correct row, otherwise the code won't work.

            FILTER ( ButaneSchedule, ButaneSchedule[Year] = SelectedYear ),



 

Count-Jobs (NEW) = 
VAR SelectedYear =
    SELECTEDVALUE ( CalendarTable[Year] )
RETURN
    IF (
        SELECTEDVALUE ( CalendarTable[Date] ) >= ButaneSchedule[Begin]
            && SELECTEDVALUE ( CalendarTable[Date] ) <= ButaneSchedule[End],
        CALCULATE (
            DISTINCTCOUNT ( Jobs[JobUnique] ),
            FILTER (
                Jobs,
                Jobs[Area] = SELECTEDVALUE ( Areas[Area] )
                    && Jobs[JobAbbr] <> "V"
                    && Jobs[JobAbbr] <> "V1"
                    && Jobs[JobAbbr] <> "V2"
                    && Jobs[JobAbbr] <> "V3"
                    && Jobs[JobAbbr] <> "T"
                    && Jobs[JobAbbr] <> "S"
                    && Jobs[JobAbbr] <> "B"
                    && Jobs[JobAbbr] <> "O"
                    && Jobs[JobAbbr] <> "TA"
                    && Jobs[JobAbbr] <> "SE"
                    && Jobs[JobAbbr] <> "BT"
            )
        ),
        CALCULATE (
            DISTINCTCOUNT ( Jobs[JobUnique] ),
            FILTER (
                Jobs,
                Jobs[Area] = SELECTEDVALUE ( Areas[Area] )
                    && Jobs[JobAbbr] <> "V"
                    && Jobs[JobAbbr] <> "V1"
                    && Jobs[JobAbbr] <> "V2"
                    && Jobs[JobAbbr] <> "V3"
                    && Jobs[JobAbbr] <> "T"
                    && Jobs[JobAbbr] <> "S"
                    && Jobs[JobAbbr] <> "B"
                    && Jobs[JobAbbr] <> "O"
                    && Jobs[JobAbbr] <> "TA"
                    && Jobs[JobAbbr] <> "SE"
            )
        )
    )

 

 

But I don't think you need the FILTER statements at all, since they are already part of the CALCULATE. So after your IF, it should be simply
CALCULATE(COUNTROWS(Jobs[JobUnique]), Jobs[Area] = SELECTEDVALUE(Areas[Area]), Jobs[JobAbbr] <> "V", Jobs[JobAbbr] <> "V1", Jobs{JobAbbr) <> "V2" etc. etc.

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.