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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
npatten
Helper II
Helper II

A trickey DAX formula for fundraising

Hi-- I'm a prospect manager/data analyst with the children's hospital in Vancouver, BC. I'm the only one I know in my organization working with DAX.  I'm trying to simplify a SQL formula to work in DAX that returns a specific monetary value from one of three columns based on the proposal status of another column. Basically donor proposals can have different values based on the fundraising cultivation stage. The IT colleauge developed the formula in SQL to run a Crystal Report, but I'm trying to adapt the formula into the Power Pivot/Power BI space. I believe the formula is set up as a series of IF statements, and it works in PBI, but not in 2010 Power Pivot. Here's the formula:

if([Prospect Proposal Stage]="11. MG Qualification") or ([Prospect Proposal Stage]="12. MG Early Cultivation") or ([Prospect Proposal Stage]="13. MG Advanced Cultivation") or ([Prospect Proposal Stage]="14. MG Solicitation in Progress") or ([Prospect Proposal Stage]="17. Payment Pending") then [Prospect Proposal Initial Target Amount] else if([Prospect Proposal Stage]="15. MG Decision Pending") or ([Prospect Proposal Stage]="16. MG Verbal Commitment") then [Prospect Proposal Amount Asked] else if ([Prospect Proposal Stage]="6. Confirmed") then [Prospect Proposal Amount Funded] else 0

 

 

For some reason, this won't work in PowerPivot. forAnyone have any idea of what's going on? I can post some sample data if needed. Thanks in advance for any help.

2 ACCEPTED SOLUTIONS
Sean
Community Champion
Community Champion

@npatten 

 

You are in the Query Editor => M (that's you original formula)

 

M to DAX - Multiple IFs - 2.png

 

To use the DAX formula => close the Query Editor => go to the Appropriate Table => click New Column in the Modeling Tab

 

M to DAX - Multiple IFs.png

View solution in original post

Sean
Community Champion
Community Champion

@npatten The formula seems fine and working.

 

Discounted Amount Column =
IF (
    vwMG_ActiveProposals[Prospect Proposal Probability] = "Possible",
    vwMG_ActiveProposals[Stage Amount 2] * .3,
    IF (
        vwMG_ActiveProposals[Prospect Proposal Probability] = "Probable",
        vwMG_ActiveProposals[Stage Amount 2],
        0
    )
)

 

 

Seems to works as intended...

 

M to DAX - Multiple IFs - 4.png

View solution in original post

16 REPLIES 16
Sean
Community Champion
Community Champion

@npatten for starters this is M not DAX syntax

 

I have not reviewed the formula itself but if you say its working in PBI (should be fine)

 

M - Power Query (Query Editor)

and

DAX - Power Pivot (PBI)

Thank you Sean, any idea how I would turn it into a DAX formula? I only know of M from what I've read on the msdn pages, not how to write with it.

Sean
Community Champion
Community Champion

2010 Power Pivot??? You are using the original PowerPivot? when it was actually 1 word? I'm lost - why?

Excel 2010, and the associated Power Pivot add on for that version, is the only version we're allowed to have installed on our workstations. I'm going to have to figure out a way to start using my personal computer for work needs becuase our systems our so outdated. We're still using Windows 7, for example. My understanding though is that there a some limitations with the 2010 software in it's ability to use the full extent of Power Pivot. However, I have the most current version of Excel on my personal computer. I'll mostly likely have to upload PBI data sets to the service, then download them on my personal computer and use excel 2016. Workarounds....

Sean
Community Champion
Community Champion

This should be your DAX equivalent... Let me know if it does the job?

 

Formula =
IF (
    [Prospect Proposal Stage] = "11. MG Qualification"
        || [Prospect Proposal Stage] = "12. MG Early Cultivation"
        || [Prospect Proposal Stage] = "13. MG Advanced Cultivation"
        || [Prospect Proposal Stage] = "14. MG Solicitation in Progress"
        || [Prospect Proposal Stage] = "17. Payment Pending",
    [Prospect Proposal Initial Target Amount],
    IF (
        [Prospect Proposal Stage] = "15. MG Decision Pending"
            || [Prospect Proposal Stage] = "16. MG Verbal Commitment",
        [Prospect Proposal Amount Asked],
        IF (
            [Prospect Proposal Stage] = "6. Confirmed",
            [Prospect Proposal Amount Funded],
            0
        )
    )
)

Thank you! When I plug it into PBI it comes back with an error 'Token Comma expected' at the first |. If I understand it, the | | is the OR operator? I've included some sample date for you if you would like to play around with it. Again, thank you for you time.

 

Prospect Proposal Initial Target AmountProspect Proposal Amount AskedProspect Proposal Amount FundedProspect Proposal Stage
60000060000060000017. Payment Pending
30000025000025000016. MG Verbal Commitment
25000024026624026817. Payment Pending
5000005000017. Payment Pending
2000020000650017. Payment Pending
1000000011. MG Qualification
250000012. MG Early Cultivation
500000013. MG Advanced Cultivation
20000000014. MG Solicitation in Progress
100000100000015. MG Decision Pending
100000100000016. MG Verbal Commitment
kcantor
Community Champion
Community Champion

I would also suggest checking the directions of your relationships. PowerBI seems to work better with relationships for me. You may need to change the direction in your powerPivot.

Of course you could take your PowerBI build and export the data into Excel as a last ditch effort.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi--- Thanks for responding. i don't have the table related to any other tables. It functions as a standalone data source. Is cardinality still an issue? Also, when I go to the export function in PBI it only gives me the 'publish option'. Is there another way to get the PBI doc into excel? I'm bound to excel 2010 tho.

Sean
Community Champion
Community Champion

@npatten Can you post a picture of where you are getting the error?

 

It works with the sample you provided...

 

M to DAX - Multiple IFs.png

PBI formula sample.png

Sean
Community Champion
Community Champion

@npatten 

 

You are in the Query Editor => M (that's you original formula)

 

M to DAX - Multiple IFs - 2.png

 

To use the DAX formula => close the Query Editor => go to the Appropriate Table => click New Column in the Modeling Tab

 

M to DAX - Multiple IFs.png

Sean
Community Champion
Community Champion

@npatten in the Query Editor you enter the original M formula

 

and as you said it does work...

 

M to DAX - Multiple IFs - 3.png

 

I was able to get your DAX formula to work! I edited it to include the table references in addition to the column references, eg ( vwMG_ActiveProposals[Prospect Proposal Stage] = "11. MG Qualification"). If I understand the issues correctly: 1) DAX formulas are entered into via the Data Modeling tab using the formula editing bar, whereas M formulas are entered via the query editor; 2) i had to add the table references in addition to the column headings in DAX to reference the correct data locations. There are other tables in the PBI doc with the same column headings, generating some calculation confusion. Do these sound right?

 

Also, i tried it in 2010 power pivot and it works too! Many, many, thanks 🙂

 

 

Sean
Community Champion
Community Champion

Yes for Columns you reference the table => TableName[Column] and for Measures you do not just => [Measure]

 

And yes in the Query Editor we use M!

Sean
Community Champion
Community Champion

@npatten The formula seems fine and working.

 

Discounted Amount Column =
IF (
    vwMG_ActiveProposals[Prospect Proposal Probability] = "Possible",
    vwMG_ActiveProposals[Stage Amount 2] * .3,
    IF (
        vwMG_ActiveProposals[Prospect Proposal Probability] = "Probable",
        vwMG_ActiveProposals[Stage Amount 2],
        0
    )
)

 

 

Seems to works as intended...

 

M to DAX - Multiple IFs - 4.png

Hello-- Thank you so much! My original attempt had an unneeded ) the .3. This is awesome. I think I'm startint to understand the DAX logic a bit better. Thank you again 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.