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
Anonymous
Not applicable

Need help with measures - Finding donors who gave gifts within the past 12 months

Hello,

 

I have a problem to solve where we have a list of customers that I need to identify who first gave a gift within the past 12 months and after 5 years since their previous gift.

 

Below are the following fields that I'm working with:

 

  • customer_id
  • date
  • gift_id

Any help would be much appreciated.

 

Thank you

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, i created data to reproduce your scenario.

w1.png

 

You can create a table as below.

Table 2 = SUMMARIZECOLUMNS('Table'[customer_id],"LastestDate",MAX('Table'[date]),"PreviousDate",

CALCULATE(MAX('Table'[date]),FILTER('Table',[date]<MAX('Table'[date]))))

 

 

You can create a measure as below.

 

TestMeasure = var LastestDate = MAX('Table'[date])

var PreviousDate=CALCULATE(MAX('Table'[date]),FILTER('Table',[date]<LastestDate))

return IF(LastestDate>NOW()-365&&PreviousDate>LastestDate-365*6,1,BLANK())

 

Result:

w2.png

 

If I misunderstand the your thoughts, please show us your sample data and expected output. I am glad to solve the problem for you.

 

 

Best Regards,

Allan

 

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

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, i created data to reproduce your scenario.

w1.png

 

You can create a table as below.

Table 2 = SUMMARIZECOLUMNS('Table'[customer_id],"LastestDate",MAX('Table'[date]),"PreviousDate",

CALCULATE(MAX('Table'[date]),FILTER('Table',[date]<MAX('Table'[date]))))

 

 

You can create a measure as below.

 

TestMeasure = var LastestDate = MAX('Table'[date])

var PreviousDate=CALCULATE(MAX('Table'[date]),FILTER('Table',[date]<LastestDate))

return IF(LastestDate>NOW()-365&&PreviousDate>LastestDate-365*6,1,BLANK())

 

Result:

w2.png

 

If I misunderstand the your thoughts, please show us your sample data and expected output. I am glad to solve the problem for you.

 

 

Best Regards,

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hello all,

 

Thank you for your replies, I believe I'm on the right track but have a question for @v-alq-msft ,

 

The sample measure that you put together:

 

TestMeasure = var LastestDate = MAX('Table'[date])

var PreviousDate=CALCULATE(MAX('Table'[date]),FILTER('Table',[date]<LastestDate))

return IF(LastestDate>NOW()-365&&PreviousDate>LastestDate-365*6,1,BLANK())

 

Should I be using the calulated table 'Table 2' to be referenced within the measure like this below:

 

TestMeasure = var LastestDate = MAX('Table 2'[date])

var PreviousDate=CALCULATE(MAX('Table 2'[date]),FILTER('Table 2',[date]<LastestDate))

return IF(LastestDate>NOW()-365&&PreviousDate>LastestDate-365*6,1,BLANK())

 

Or should I reference the original table?  I tried both but receiving a 1 for all the values, regardless if it fits the criteria or not.

 

Below is a sample of table 2:

 

Sample Data SetSample Data Set

 
amitchandak
Super User
Super User

You can use earlier to get the last date. 

for rolling 12 month you can get values like. No using date diff ealier date and date and rolling 12 month data you can create a flag

 

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date Filer],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))  

 

earlier

https://community.powerbi.com/t5/Desktop/Explanation-of-the-EARLIER-formula/td-p/529469

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

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