Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

DAX: SUM an IF statement comparing 2 Measures

Hi,   I want to sum the results of an expression that uses and IF statement to get the difference between 2 measures. Here is the DAX I'm currently using:   Total Single Giving Donors New (FYTD)...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Jihwan_Kim ,

     

    I used ChatGPT. It took me a while to figure out the right way to ask the question. But eventually we got there:

     

    Total Single Giving Donors - New (FYTD) = 
    COUNTROWS(
        EXCEPT(
            CALCULATETABLE(
                DISTINCT('DONOR OPPORTUNITIES (RAW)'[Supporter ID]),
                'DONOR OPPORTUNITIES (RAW)'[Opportunity Won] = TRUE(),
                'DONOR OPPORTUNITIES (RAW)'[Opportunity Bequest] = FALSE(),
                'DONOR OPPORTUNITIES (RAW)'[Business Unit, Regular Giving] = FALSE(),
                'DONOR OPPORTUNITIES (RAW)'[Supporter ID] <> BLANK(),
                FILTER(
                    ALL('02: Calendar'),
                    '02: Calendar'[Year ID] = MAX('02: Calendar'[Year ID]) &&
                    '02: Calendar'[Month ID] <= MAX('02: Calendar'[Month ID])
                )
            ),
            CALCULATETABLE(
                DISTINCT('DONOR OPPORTUNITIES (RAW)'[Supporter ID]),
                'DONOR OPPORTUNITIES (RAW)'[Opportunity Won] = TRUE(),
                'DONOR OPPORTUNITIES (RAW)'[Opportunity Bequest] = FALSE(),
                'DONOR OPPORTUNITIES (RAW)'[Business Unit, Regular Giving] = FALSE(),
                'DONOR OPPORTUNITIES (RAW)'[Supporter ID] <> BLANK(),
                FILTER(
                    ALL('02: Calendar'),
                    '02: Calendar'[Year ID] = MAX('02: Calendar'[Year ID]) - 1 &&
                    '02: Calendar'[Month ID] <= MAX('02: Calendar'[Month ID])
                )
            )
        )
    )

     

    This measure creates 2 tables, for one Current FYTD, another for FYTD, with the filtering taking place within this measure. It then takes the difference to get the total New Customers.

     

    I've done the same for Returning, using INSERSECT rather than EXPECT. To get Lost Customers I use the same measure as above, but swap around the FILTER sections.

     

    That was a lot of work!

     

    Mark