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
UK_User123456
Resolver I
Resolver I

Second Gift Date

Hi All,

 

I work for a non profit and starting to use power bi and wanted to show the number of donors that have given in FY 2018/19 for the first time and then given again for the second time?

 

as in the example below 

 

Donor 1234 first gave on 12/04/2018 and then in the gift table gave again on 15/05/2018, this would also apply to donor ID 1243. Donor ID 2345 and 3456 would be disregarded as they dont have any second gift.

 

Donor Table   Gift Table   
         
Donor IDFirst Gift Date  Donor IDGift DateGift Date 2Gift Date 3
123412/04/2018   123415/05/201813/01/2019 
234518/06/2018   2345   
345601/02/2018   3456   
124321/08/2018   124313/12/2018 16/01/03/2019

 

Im not too worried about gift 2 and 3, I just dont know how to insert a measure that will check the first gift and then check if the donor who gave the first has then given again. 

After reading through the community I can see that others have used variables and declared them and used the min/max, but im not sure if I am on the right lines?

 

Please let me know if this makes sense?

3 ACCEPTED SOLUTIONS

thanks @MitchM , however, it only return the very last gift date, I need it to be able to show the first gift as well, so as in the example below:

 

Gift Table

Donor ID         First donor date                Second donor date             Third donor date

1234                12/04/2018                       15/05/2018            

2345                 06/04/2018

1111                07/06/2018                        12/06/2018                         21/08/2018

 

The end result would be:

   

Donor ID         First donor date                Second donor date             

1234                12/04/2018                       15/05/2018            

2345                 06/04/2018

1111                07/06/2018                        12/06/2018                         

 

So not matter if the donor had donated 5 times, I would only want to see the first and second donor date if that makes sense?

 

Apologies if im confusing you, its almost there and what you have provided does kind of work, but I wouldnt know where to start to fix it.

               

View solution in original post

It is no suprise that the filtering does not work. The ranking needs another value (In this case FY) to rank against. To do this you can create a new calc. column called FY:

FY = 
VAR FirstMonthofFY = 9
VAR DateYear = YEAR( GiftData2[Reformatted Date] )
VAR DateMonth = MONTH( GiftData2[Reformatted Date] )
RETURN
    IF(
        DateMonth < FirstMonthofFY,
        (DateYear - 1) & "/" & DateYear,
        DateYear & "/" & (DateYear + 1)
    )

I am not sure when your FY starts, so just change the first variable (FirstMonthofFY) in the formula above to adjust the FY range. Once this is done a slight tweak to the Rank formula (below) should finish it off. The two dontation measures do not need to be adjusted.

Gift_Date_Rank = 
    RANKX(
        FILTER(
            GiftData2,
            GiftData2[Donor ID] = EARLIER( GiftData2[Donor ID] ) &&
            GiftData2[FY] = EARLIER( GiftData2[FY] )
        ),
        GiftData2[Reformatted Date],
        ,
        ASC,
        Dense
    )

View solution in original post

Another question and hopefully the last - once I have the campaign id's and how when the donors gave their 1st and 2nd gift, how would I go about doing a count of how many times the campaign id has appeared, so for example

 

In 2019 for Jan - there were 200 donors that donated a gift on campaign id "2", out of the 200 donors that gave on campaign id "2", 100 donors gave their second gift on campaign id "3", and 50 donors gave on campaign "4" and 50 donors never gave a second gift..

 

So its trying to identify out of all the donors that gave their first gift and to which campaign gave again and if it was to a different campaign code or not.

 

Hope that makes sense

 

TIA

View solution in original post

24 REPLIES 24
vanessafvg
Super User
Super User

@UK_User123456  do you want to just work out how many times they have given or do you want the exact dates.

 

I pivoted your data and then did a count on where the date was not null, this might work for you.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




MitchM
Resolver II
Resolver II

I took a stab at this. I operated under the assumption that you may want to define what your FY date range is, so you can do that in the measure. Hopefully this works for you.

 

Example.jpg

Given In FY = 
VAR FiscalYearStart = DATE(2018,03,01) //Date Function is Year,Month,Day
VAR FiscalYearEnd = DATE(2019,02,28)
RETURN 
    IF(
        CALCULATE(
        MAX( 'Donor Table'[First Gift Date] ),
        ALLEXCEPT( 'Donor Table', 'Donor Table'[Donor ID] ),
        'Donor Table'[First Gift Date] >= FiscalYearStart,
        'Donor Table'[First Gift Date] <= FiscalYearEnd
        ) = BLANK(),
    "Has Not Given In FY",
    "Has Given in FY"
    )
Additional Giving In FY = 
VAR FiscalYearStart = DATE(2018,03,01) //Date Function is Year,Month,Day
VAR FiscalYearEnd = DATE(2019,02,28)
VAR DonorId = SELECTEDVALUE( 'Donor Table'[Donor ID] )
RETURN 
           
        IF(
            CALCULATE(
            MAX( 'Gift Table'[Gift Date] ),            
            'Gift Table'[Gift Date] >= FiscalYearStart,
            'Gift Table'[Gift Date] <= FiscalYearEnd,
            FILTER( 'Gift Table', 'Gift Table'[Donor ID] = DonorId )
            ) = BLANK(),
            "No Additional Giving",
            "Additional Giving"
        )
    

@Mitchem, many thanks for your response, this is something that looks like I want, but what happens if there was no donor table and I wanted to just use the gift table only?

Also, I dont want to specify the date as I will have a FY already as a filter.

Also, if I wanted to return the date rather than the text of Has or Hasnt given, is this possible as well?

 

TIA

So if you only have the single gift table, and you do not need to worry about defining your date range, the measure become much simpler. Here is one to check for giving:

First Donor Gift Date = 
    CALCULATE(
        MAX( 'Gift Table'[Gift Date] )  
    )

From your initial question I am guessing you just need to know if they ever make a second donation, so here is the modified additional gift measure:

  IF(
        CALCULATE(
        MAX( 'Gift Table'[Gift Date 2] )                      
        ) = BLANK(),
        "No Additional Giving",
        "Additional Giving"
    )

Does this work?

What happens if I wanted to return the actual date of the first gift and the second gift, so that I can then do a datediff to find out the difference between the two dates?

That is doble, you could use:

 

 

Additional Giving In FY = 
    CALCULATE(
        MAX( 'Gift Table'[Gift Date 2] )
    )

 

 

thanks @MitchM , however, it only return the very last gift date, I need it to be able to show the first gift as well, so as in the example below:

 

Gift Table

Donor ID         First donor date                Second donor date             Third donor date

1234                12/04/2018                       15/05/2018            

2345                 06/04/2018

1111                07/06/2018                        12/06/2018                         21/08/2018

 

The end result would be:

   

Donor ID         First donor date                Second donor date             

1234                12/04/2018                       15/05/2018            

2345                 06/04/2018

1111                07/06/2018                        12/06/2018                         

 

So not matter if the donor had donated 5 times, I would only want to see the first and second donor date if that makes sense?

 

Apologies if im confusing you, its almost there and what you have provided does kind of work, but I wouldnt know where to start to fix it.

               

Quick question, because I think I must be missing something. Will your gift table be 2 columns with ID's and Dates or will it be as you showed, with a seperate column for each gift (1,2,3,etc.)? If it is laid out as you show it is there a reason you can not just place the first and second gift columns in a table? If you have a sample pbix file you can share or an excel file with a sample data set that you can share that would be much easier than me guessing 🙂

I have put below the sample of exactly how the data will be laid out and highlighted the outcome of what would be displayed in terms of gift 1 and gift 2.

 

Donor IDGift IDGift DateGift AmountGift CodeGift Type
123411111112/05/20182VoucherCash
123411111213/05/201815VoucherCash
123411111314/05/201845VoucherCash
123411111415/05/201812VoucherCash
234411111516/05/2018100Gift In KindCash
234511111617/05/201890OnlineCash
434311111718/05/20183.5Gift In KindCash
111111111819/05/201850OnlineCash
111111111920/05/20189OnlineCash
222211112021/05/201810Gift In KindCash
333311112122/05/201832Gift In KindCash
333311112223/05/201812Gift In KindCash
333311112324/05/201834OnlineCash
666611112425/05/201854OnlineCash
777711112526/05/201876Gift In KindCash
888811112627/05/201878Gift In KindCash
888811112728/05/201811Gift In KindCash

 

 

Thank you.


any help would be greatly appreciated.

Ok, I think I got it now. First off, I did go into the query editor and reformat the date to MM/DD/YYYY. This requires creating a calculated column that will rank each date for each donor (Gift_Date_Rank in pic). The measure the calculates the 1st rank (for First Gift) and 2nd rank (for Second Gift).

Hope this makes sense.Example.jpg

CALCULATED COLUMN
Gift_Date_Rank = RANKX( FILTER( GiftData, GiftData[Donor ID] = EARLIER( GiftData[Donor ID] ) ), GiftData[Reformatted Date], , ASC, Dense )
First_Donation = 
    CALCULATE(
        MIN( GiftData[Reformatted Date] ),
        GiftData[Gift_Date_Rank] = 1
    )


Second_Donation = 
    CALCULATE(
        MIN( GiftData[Reformatted Date] ),
        GiftData[Gift_Date_Rank] = 2
    )

 

I will let you know if it has worked next week, but from your screenshot that you have provided, this looks absolutely spot on. Looks very complicated. Are you able to walk me through how the rank works as this is not something I have come across? and so that I can make notes within the calc to be able to remember what it is doing.

 

On a side note to this, would it be the same calculation or working if I wanted to get the ranking for the last two gift dates?

Ranking explained below. If you wanted to get the last 2 dates you would need to create a second calculated column and change from ASC to DESC. 

CALCULATED COLUMN
Gift_Date_Rank = RANKX(
// You need to filter down the dataset to the subset you want ranked. In this case it is all the dates where the Donor ID's match
// This is done by saying "Hey Power BI, filter GiftData to this row and any row after it that matches (EARLIER) FILTER( GiftData, GiftData[Donor ID] = EARLIER( GiftData[Donor ID] ) ),
// Next we need to define the value to be ranked, in this case it is the date column GiftData[Reformatted Date], ,
// You want the first gift, so we rank ASC so that the first is 1, second is 2, etc. ASC,
// We now dense rank to account for potential duplicate donations on the same day. The will both be 1, but the second day would be 2 Dense )

 

That is an awesome way of doing things and I would never have thought of it. You are awesome so many thanks!

No problem! If this works please mark the solution as accepted to close it off. Have a great weekend!

@MitchM- Your calculation works, however one slight problem( table below:) is that, as some donors may have given gifts in 1998 so it is taking this as the first gift, so when I apply a filter for FY 18/19, it is not showing the first gift and second gift correctly also to make things more complicated, the donor could have given 2 gifts on the same day but at different times.

 

Is there anyway around this?

 

Gift IDGift DateGift AmountGift CodeGift TypePost DateDonor ID
106/04/1998£10.00Standing orderCash12/04/19981010
208/05/1999£10.00Standing orderCash09/05/19991010
306/06/2000£10.00Standing orderCash12/06/20001010
406/07/2004£10.00Standing orderCash14/07/20041010
506/08/2005£10.00Standing orderCash08/08/20051010
606/09/2018£10.00Standing orderCash09/09/20181010
708/10/2018£10.00Standing orderCash21/10/20181010
806/05/2019£10.00Standing orderCash12/05/20181010
922/08/2009£100.00Direct donationCash01/09/2009202
1012/06/2018£235.30InMemCash13/06/2018202
1106/05/2019£10.00Standing orderCash22/05/2019300
1206/05/2019£100.00Direct donationCash22/05/2019300

 

TIA

It is no suprise that the filtering does not work. The ranking needs another value (In this case FY) to rank against. To do this you can create a new calc. column called FY:

FY = 
VAR FirstMonthofFY = 9
VAR DateYear = YEAR( GiftData2[Reformatted Date] )
VAR DateMonth = MONTH( GiftData2[Reformatted Date] )
RETURN
    IF(
        DateMonth < FirstMonthofFY,
        (DateYear - 1) & "/" & DateYear,
        DateYear & "/" & (DateYear + 1)
    )

I am not sure when your FY starts, so just change the first variable (FirstMonthofFY) in the formula above to adjust the FY range. Once this is done a slight tweak to the Rank formula (below) should finish it off. The two dontation measures do not need to be adjusted.

Gift_Date_Rank = 
    RANKX(
        FILTER(
            GiftData2,
            GiftData2[Donor ID] = EARLIER( GiftData2[Donor ID] ) &&
            GiftData2[FY] = EARLIER( GiftData2[FY] )
        ),
        GiftData2[Reformatted Date],
        ,
        ASC,
        Dense
    )

@MitchM- many thanks for helping with this, it has worked wonders, however, if I wanted to show the campaign(s) against these donations, would I need to follow the same path? I would like to show the campaign(s) for both the first donation and second donation?

 

Thanks

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.