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
msuser48
Helper I
Helper I

Count the SUM of a column GROUPED BY id, and sorted by year

I have this table:

RowId
IdStartDate
MailDateTrips
1
12019-11-20
2020-11-204
2
12019-11-20
2020-12-101
3
1
2019-11-20
2022-12-103
4
22018-11-20
2021-01-016
5
22018-11-202021-02-027
6
32019-01-012020-01-012
7
32019-01-01
2022-05-052
8
32019-01-01
2022-06-09

3

9
4
2015-01-01
2019-01-01

2

 

What I need to do:

I need the SUM of Trips made after each year since each Ids StartDate.

 

The output needs to be this table, which would look like this for the above table:

YearsPassedSinceStartDate (0-5 years is fixed interval)Amount (this will be our calculated column)
00
17
213
38
42
50

For example, for YearsPassedSinceStartDate with the value "1", we know that the amount is = 7.

- Why? Because RowId 1, 2 and 6's DateDiff between MailDate and StartDate is 1 year. And SUM of their trips is 4+1+2 = 7.

 

How do I produce the above table's calculated "Amount" column like this?

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@msuser48 

you can create a column

Column = int( DATEDIFF('Table'[StartDate],'Table'[MailDate],month)/12)

create a year table

and create a measure

Measure = sumx(FILTER('Table',max('Table (2)'[year])='Table'[Column]),'Table'[Trips])+0

1.PNG

pls see the attachment below





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

Proud to be a Super User!




View solution in original post

1 REPLY 1
ryan_mayu
Super User
Super User

@msuser48 

you can create a column

Column = int( DATEDIFF('Table'[StartDate],'Table'[MailDate],month)/12)

create a year table

and create a measure

Measure = sumx(FILTER('Table',max('Table (2)'[year])='Table'[Column]),'Table'[Trips])+0

1.PNG

pls see the attachment below





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

Proud to be a Super User!




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.