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

Cumulative Total with date column

Hello

 

I need to calculate running total ,year wise. If user selects date as "Dec 2023" it should show running total from Jan 2023- Dec 2023.

Few examples are given below

 

User selection (in slicer dropdown)Running Total 
Jan '2023To show data for Jan '2023
June '2023Sum from Jan to June 2023
October '2023Sum from Jan to October 2023
Dec '2023Sum showing Jan to Dec 2023
Jan '2024Sum for Jan '2024
Mar '2024Sum of Jan + Feb + Mar 2024

 

It is not YTD calculation but it is calendar year calculation. What logic I need to write-in? Pleae note that Month filter is in form of  "December 2023" i.e. Month Year

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

Hi @romilv1 ,

@Dangar332 's answer is good , and there is my solution:

Below is my table:

vxiandatmsft_0-1711958255393.png

The following DAX might work for you:

Measure = 
   var A = SELECTEDVALUE('Table'[Month])
   var B = SELECTEDVALUE('Table'[Year])
   RETURN
   CALCULATE(SUM('Table'[data]),'Table'[Year] = B && 'Table'[Month]<=A)

The final output is shown in the following figure:

vxiandatmsft_1-1711958303868.pngvxiandatmsft_2-1711958316445.png

Best Regards,

Xianda Tang

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

5 REPLIES 5
v-xiandat-msft
Community Support
Community Support

Hi @romilv1 ,

@Dangar332 's answer is good , and there is my solution:

Below is my table:

vxiandatmsft_0-1711958255393.png

The following DAX might work for you:

Measure = 
   var A = SELECTEDVALUE('Table'[Month])
   var B = SELECTEDVALUE('Table'[Year])
   RETURN
   CALCULATE(SUM('Table'[data]),'Table'[Year] = B && 'Table'[Month]<=A)

The final output is shown in the following figure:

vxiandatmsft_1-1711958303868.pngvxiandatmsft_2-1711958316445.png

Best Regards,

Xianda Tang

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

romilv1
Helper I
Helper I

measure77 =
var a = selectedvalue('dim date'[monthYear])
var b = calculate(min('dim date'[year]),'dim date'[monthYear]=a)
return
calculate(sum(vw_AdaptivePlanningActualsNew[Amount]),'dim date'[year]= b ,'dim date'[monthYear]<=a)
 
@Dangar332  Code from my file.

hi, @romilv1 

 

try below code

var a = selectedvalue('dim date'[monthYear])
var b = calculate(min('dim date'[year]),'dim date'[monthYear]=a)
return
calculate(sum(vw_AdaptivePlanningActualsNew[Amount]),'dim date'[year]= b ,'dim date'[monthYear]<=a,removefilters())

 

if still not work provide some sample data 

 

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

romilv1
Helper I
Helper I

@Dangar332  Thanks but it doesn't work. When I select Dec 2023 it returns the sum of Dec '23 only.

Dangar332
Super User
Super User

hi, @romilv1 

 

try below measure code 

it maybe work

make sure you have month column(1,2,3,4,5....) for jan-2023 it 1, feb-2023 it 2 and year column

measure =
var a = selectedvalue(datetable[month year])
var b = calculate(min(datetable[year]),datetable[month year]=a)
return
calculate(sum[value],datetable[year]= b ,datetable[month year]<=a )

 

 

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

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.