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

Counting the number of people in last 2 years and grouping

Hi All,

 

2 questions, from the example data below, is there a way in DAX to be able to

 

1. find the number of people who gave some money in the last two years

2. Create 3 groups from the dataset, so all the people who gave within between "0-24 months", "25-48 months", then "Older"

 

PeopleDateAmount
person 101/01/201910
person 225/02/200220
person 313/05/200030
person 416/07/201840
person 517/08/201850
person 615/12/200960
person 723/01/201915
person 813/05/201916
person 906/05/200513
person 1017/08/200624
person 1126/09/200725
person 1214/03/201729
person 1316/07/201850
person 1418/01/200131
person 1512/12/2019110
person 1616/07/201940

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@UK_User123456 Please try below calculated columns and let me know if you have any question

WithinLastTwoyear = 
VAR _diff = DATEDIFF('Table'[Date],TODAY(),YEAR)
RETURN IF(_diff<=2,TRUE(),FALSE())
Group = 
VAR _month = DATEDIFF('Table'[Date],TODAY(),MONTH)
RETURN SWITCH(TRUE()
                ,AND(_month>=0,_month<25),"0-24 months"
                ,AND(_month>=25,_month<49),"25-48 months"
                ,"Other")

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

@UK_User123456 Please try below calculated columns and let me know if you have any question

WithinLastTwoyear = 
VAR _diff = DATEDIFF('Table'[Date],TODAY(),YEAR)
RETURN IF(_diff<=2,TRUE(),FALSE())
Group = 
VAR _month = DATEDIFF('Table'[Date],TODAY(),MONTH)
RETURN SWITCH(TRUE()
                ,AND(_month>=0,_month<25),"0-24 months"
                ,AND(_month>=25,_month<49),"25-48 months"
                ,"Other")

 

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.