cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors