March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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) = IF([Total Single Giving Donation Amount (FYTD)] > 0 && [Total Single Giving Donation Amount (PFYTD)] <= 0, 1, 0)
When added to a table, it marks, as in the following example:
Highlighted in Yellow are all the times when the statement is true - when a Customer has a value the second column "Total Single Giving Donation Amount (FYTD)" and no value for the fourth column "Total Single Giving Donation Amount (PFYTD)". This indicates that this person has donated for the first time.
For context, here's one of the Measures from within the expressions:
Total Single Giving Donation Amount (FYTD) =
CALCULATE([Total Single Giving Donation Amount],
FILTER(ALL('02: Calendar'), '02: Calendar'[Year ID] = MAX('02: Calendar'[Year ID]) && '02: Calendar'[Month ID] <= MAX('02: Calendar'[Month ID])))
I want to be able to sum each of these to get an overall total that I can use in a card visual.
Can anyone help with this?
Thanks,
Mark
Solved! Go to Solution.
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
Hi @Jihwan_Kim ,
This doesn't quite work. It does give me a sum but the number is not what I'm expecting. It's showing 1,005 when I'm expecting 2,261.
Perhaps it will help if I show how my measures are all stacked up.
I'm starting with the following measure to work out the Total Opportunity Amount. I'm using USERELATIONSHIP as there are a few Date fields on the Donor Opportunities table:
Total Opportunity Amount =
CALCULATE(SUM('DONOR OPPORTUNITIES (RAW)'[Opportunity Amount]),
USERELATIONSHIP('DONOR OPPORTUNITIES (RAW)'[Opportunity Closed Date], '02: Calendar'[Dates]))
I then filter this measure to get only the Amount that relates to Single Giving:
Total Single Giving Donation Amount =
CALCULATE([Total Opportunity Amount],
'DONOR OPPORTUNITIES (RAW)'[Opportunity Won] = TRUE(),
'DONOR OPPORTUNITIES (RAW)'[Opportunity Bequest] = FALSE(),
'DONOR OPPORTUNITIES (RAW)'[Business Unit, Regular Giving] = FALSE())
Once I have this, I then work out the FYTD value:
Total Single Giving Donation Amount (FYTD) =
CALCULATE([Total Single Giving Donation Amount],
FILTER(ALL('02: Calendar'), '02: Calendar'[Year ID] = MAX('02: Calendar'[Year ID]) && '02: Calendar'[Month ID] <= MAX('02: Calendar'[Month ID])))
I do the same for PFYTD:
Total Single Giving Donation Amount (PFYTD) =
CALCULATE([Total Single Giving Donation Amount],
FILTER(ALL('02: Calendar'), '02: Calendar'[Year ID] = MAX('02: Calendar'[Year ID]) -1 && '02: Calendar'[Month ID] <= MAX('02: Calendar'[Month ID])))
Then I do my IF statement from the top of this thread. When I drop this final measure into a table looking at November FYTD, the SUM is not quite what I'm expecting.
Is there something else I could try?
Mark
Hi,
If it is OK, please share your sample pbix file's link (onedrive, dropbox, or googledrive), and then I can try to look into it with understanding more about your data model.
Thank you.
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi @Jihwan_Kim ,
I'm afraid I can't share any of the Data Model. But it's relatively simple.
Total Single Giving Donors New (FYTD) = IF([Total Single Giving Donation Amount (FYTD)] > 0 && [Total Single Giving Donation Amount (PFYTD)] <= 0, 1, 0)
Does that help?
Mark
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
Hi,
Please try something like below if it suits your requirement.
Total Single Giving Donors New (FYTD) =
SUMX (
VALUES ( 'TableName'[Supporter ID] ),
IF (
[Total Single Giving Donation Amount (FYTD)] > 0
&& [Total Single Giving Donation Amount (PFYTD)] <= 0,
1,
0
)
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
87 | |
87 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |