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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
MEverts
Frequent Visitor

Running total scenarios - filter/exclude entries based on combination of 2 columns

Background: I have built a patient-recruitment forecast-tool for a clinical-study, where a running total (of number patients per clinical-site/country) is plotted per calendar day. Source material is a list of hospital-sites (and associated countries) with the start- & stop-dates (for the study) and total (expected) patients to be recruited.
My approach thus far has been to calculate a Daily Recruitment-Rate per Site (’Total expected patients’/days between start and stop date) and use Power-query to feed an Expanded List of individual rows for: [Active calendar days] per [Site], [ Country], [[X_daily recruit](Site-specific Recruitment Rate) and an [Index-coumn] into my data-model.

For the +/- 100 sites, the data model now holds a +75k-row table, where each line specifies an individual day, pertaining to a site and country, with its site-specific “daily Recruitment Rate”. [RR_Expanded]

With a Calendar-table in the data modelit shows the plotted line (Forecast X) beautifully with the typical forecast-measure for a running total:

 

Forecast X:=CALCULATE (

    SUMX (RR_Expanded, RR_Expanded[X_daily recruit]),

    FILTER (

        ALL ( 'Calendar'[Date] ),

        'Calendar'[Date] <= MAX ( 'Calendar'[Date] )

    )

)

 

(note that i'm (still) using excell, as our client is not yet onboard with Power-BI.)

 

However, I want to visualize and explore multiple scenarios where for instance a country experiences a 4-month delay in start-up. To do this, I can create a separate table with redefined start-dates for each scenario and create a new measure [say: Forcast Y] to show an additional forecast-line in my graph.

Unfortunately, this makes the excel file increasingly large and sluggish and... (on general principle) I’m hoping to learn a more dynamic approach using DAX.

 

As such, would it be possible to formulate logic based on the above forecast-formula (say Forecast Y) that uses the [RR_Expanded] listing but excludes all rows that have [Country] as e.g. “Russian” AND where the [Active calendar days] < “DateX” (effectively excluding the [X_daily recruit]’s from the cumulative forecast formula for Russia before a certain date).

So far, it seems impossible (for me) to apply a filter based on a combination of two column-criteria. All my efforts have resulted in the addition of two column-filters, filtering ‘RR_Expanded’ for ALL ‘Russian entries’ + ALL ‘date-entries <DateX’.

Any help is much appreciated! It has been learning by doing, but I really feel I hit a wall with this one.

 

Cheers!

 

 

1 ACCEPTED SOLUTION

HI @MEverts ,

In fact, && means conditions are use 'and' logic to link, It will filter records who less than specific date and country not equal to particular value.
If you want to get rolling records, then exclude specific condition records, you can try to append these conditions after original rolling formula:

Forecast Y :=
VAR currDate =
    MAX ( 'Calendar'[Date] )
VAR delayDate =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 4, DAY ( currDate ) )
RETURN
    CALCULATE (
        SUM ( RR_Expanded[X_daily recruit] ),
        FILTER (
            ALL ( 'RR_Expanded' ),
            'RR_Expanded'[Date] <= delayDate
                && NOT (
                    AND ( 'RR_Expanded'[Date] < Feb - 20, [Country] = "bb" )
                )
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

HI @MEverts ,

You can test with following measure formula,t I ignore all filters on 'RR_Expanded' table and calculate rolling total based on selected calendar date(four months delay) and exclude country "Russian":

Forecast Y :=
VAR currDate =
    MAX ( 'Calendar'[Date] )
VAR delayDate =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 4, DAY ( currDate ) )
RETURN
    CALCULATE (
        SUM ( RR_Expanded[X_daily recruit] ),
        FILTER (
            ALL ( 'RR_Expanded' ),
            'RR_Expanded'[Date] <= delayDate
                && [Country] <> "Russian"
        )
    )

Regards.

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you so much for your reply!
It seems however that, as with my initial efforts, the full source table for the rolling totals is filtered completely by each of the individual statements, and not limited to unique cases where both filter statements (Country=Russia AND start-date=<DateX) are TRUE.

 

Basically, I want to have the rolling SUM of [X_daily recruit], but exclude the sum of rows were [Country]=bb AND the [Date]=<Feb-20. (in purple).

[Site] [Country][Date][X_daily recruit]
1aa20-Jan0.5
2aa20-Feb0.5
3aa20-Mar0.5
4aa20-Apr0.5
5aa20-May0.5
6bb20-Jan0.6
7bb20-Feb0.6
8bb20-Mar0.6
9bb20-Apr0.6
10bb20-May0.6
11cc20-Jan0.3
12cc20-Feb0.3
13cc20-Mar0.3
14cc20-Apr0.3
15cc20-May0.3
16dd20-Feb0.8
17dd20-Mar0.8
18dd20-Apr0.8
19dd20-May0.8

Currently however, it seems:

            ALL ( 'RR_Expanded' ),
            'RR_Expanded'[Date] <= delayDate
                && [Country] <> "Russian"

is combining both filter statements.

 

Is there any way in DAX to exclude/filter for rows that distinctly meet criteria from two separate columns?

 

thanks!

HI @MEverts ,

In fact, && means conditions are use 'and' logic to link, It will filter records who less than specific date and country not equal to particular value.
If you want to get rolling records, then exclude specific condition records, you can try to append these conditions after original rolling formula:

Forecast Y :=
VAR currDate =
    MAX ( 'Calendar'[Date] )
VAR delayDate =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 4, DAY ( currDate ) )
RETURN
    CALCULATE (
        SUM ( RR_Expanded[X_daily recruit] ),
        FILTER (
            ALL ( 'RR_Expanded' ),
            'RR_Expanded'[Date] <= delayDate
                && NOT (
                    AND ( 'RR_Expanded'[Date] < Feb - 20, [Country] = "bb" )
                )
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you so much Xiaoxin, this means a lot! the rolling totals are filtered as required.

 

Best regards,

 

Martijn

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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