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
HeatherD
Regular Visitor

Calculate Last Date and Amount Where Full Write-Offs have been excluded

Greetings, all.

I'm a long-time Power Query user, but am very new to Power Pivot and DAX.  I am working in Excel and I have created a number of measures, used slicers to filter, and have even dabbled with some CUBE functions with success.  However, there is one DAX measure that I just cannot figure out and I am hoping someone here has some DAX magic they can share.  Thank you in advance for your help!  

 

A little background before the measures I'm stuck on

 

Full write-off - when CampaignID and Pledge (row) = CampaignID and Write-Offs (row)

 

So this IS a full write-off

CompanyDateCampaignIDPledgeWrite-Offs
Company A7/29/2019A19$5,000 
Company A10/30/2020A19 $5,000

 

This IS NOT a full write-off

CompanyDateCampaignPledgeWrite-Offs
Company A7/29/2019A19$5,000 
Company A10/30/2020A19 $2,500
Company A10/31/2020A19 $2,500

 

I need to create 2 measures, LastPledgeDate and LastPledgeAmount, for each Company where I filter out dates/amts that are a full write-off.  If all pledges have been fully written-off, then return no value (blank).

 

I have a dim Calendar table where Calendar[Date] is related to Transactions[Date]

Transactions (fact table)

CompanyDateCampaignIDPledgeWrite-Offs
Company A7/29/2019A1950000
Company A7/8/2020B2010000
Company A10/30/2020A1905000
Company A10/25/2021B200742
Company A12/15/2021C2150000
Company B7/29/2019A1950000
Company B7/8/2020B20350000
Company B10/30/2020A1905000
Company B10/27/2021B20035000
Company B12/15/2021C21150000
Company X7/30/2019A1950000
Company X7/8/2020B20400000
Company X10/26/2020A19109050
Company X12/11/2020A19010905
Company X10/25/2021B20020000
Company X10/31/2021B20020000
Company X12/15/2021C21300000
Company Z7/29/2019A19750000
Company Z7/8/2020B20350000
Company Z10/30/2020A19035000
Company Z10/25/2021B20020000
Company Z10/30/2021B20015000
Company Z12/15/2021C21600000

 

Here are the results I would see in the PivotTable.  If the today was:

10/1/2020, then…  
 LastPledgeDateLastPledgeAmt
Company A7/8/2020$1,000
Company B7/8/2020$35,000
Company X7/8/2020$40,000
Company Z7/8/2020$35,000
   
11/1/2020, then same as previous except….
 Company X10/26/2020$10,905
   
12/31/2020, then same as previous except….
Company X7/8/2020$40,000
   
12/1/2021, then same as previous except….
Company B(blank)(blank)
   
12/31/2021, then ….
Company A12/15/2021$5,000
Company B12/15/2021$15,000
Company X12/15/2021$30,000
Company Z12/15/2021$60,000
1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @HeatherD ,

 

Please try the following measures:

 

IS full write-off = 
COUNTROWS (
    FILTER (
        ALLSELECTED ( Transactions ),
        Transactions[Company] = MAX ( Transactions[Company] )
            && Transactions[CampaignID] = MAX ( Transactions[CampaignID] )
            && Transactions[Write-Offs] = MAX ( Transactions[Pledge] )
            && Transactions[Date] <> MAX ( Transactions[Date] )
    )
)
LastPledgeDate = 
IF (
    SUM ( Transactions[Pledge] ) > 0,
    CALCULATE (
        MAX ( Transactions[Date] ),
        FILTER ( ALLSELECTED ( Transactions[Date] ), [IS full write-off] = BLANK () )
    )
)
LastPledgeAmt = 
LASTNONBLANKVALUE (
    FILTER ( VALUES ( Transactions[Date] ), Transactions[Date] = [LastPledgeDate] ),
    SUM ( Transactions[Pledge] )
)

vkkfmsft_0-1646104311577.png    vkkfmsft_1-1646104332632.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Hi @HeatherD ,

 

Please try the following measures:

 

IS full write-off = 
COUNTROWS (
    FILTER (
        ALLSELECTED ( Transactions ),
        Transactions[Company] = MAX ( Transactions[Company] )
            && Transactions[CampaignID] = MAX ( Transactions[CampaignID] )
            && Transactions[Write-Offs] = MAX ( Transactions[Pledge] )
            && Transactions[Date] <> MAX ( Transactions[Date] )
    )
)
LastPledgeDate = 
IF (
    SUM ( Transactions[Pledge] ) > 0,
    CALCULATE (
        MAX ( Transactions[Date] ),
        FILTER ( ALLSELECTED ( Transactions[Date] ), [IS full write-off] = BLANK () )
    )
)
LastPledgeAmt = 
LASTNONBLANKVALUE (
    FILTER ( VALUES ( Transactions[Date] ), Transactions[Date] = [LastPledgeDate] ),
    SUM ( Transactions[Pledge] )
)

vkkfmsft_0-1646104311577.png    vkkfmsft_1-1646104332632.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Hi @v-kkf-msft.  Thank you for your reply! 

 

I can see the calculations working in the pbix file you provided and attempted to recreate it in Excel using Power Pivot.  The LastPledgeDate works great so far! 

 

I get an error on the LastPledgeAmt:  "Failed to resolve name 'LASTNONBLANKVALUE'. It is not a valid table, variable, or function name."

 

Since it works in PowerBI and not Power Pivot/Excel, it seems to be something specific to the latter so I'll do a little research (unless you happen to know off-hand).  The good news is that of the two measures, LastPledgeDate is the most important.

Whitewater100
Solution Sage
Solution Sage

Hi Heather:

 

Please see solution file. I hope this is what you are looking for!

https://drive.google.com/file/d/1Ux2apB_c3wRcixCGiooSz_fTaFbU6jpp/view?usp=sharing 

Hi Whitewater:

Thank you for your quick response!  I looked at what you provided over the weekend but wasn't seeing the values I was expecting.  It looks like the date shows the last transaction date, write-offs included, as opposed to the last pledge transaction date.  I was hoping to figure that out and then figure out the last pledge amount, but no luck so far.  I'm also looking at another suggestion that was posted.  

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.

Top Solution Authors