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
WarrenBarrell
Frequent Visitor

Dax Running Total In by Non Date and showing each year Running Total In

Hello all, I am trying to calculate the running total in calculated on DAX, by Month on Book column and year (as in my example).

 

I've presented the inputs and what I am aiming for in an output table below. 

 

Any help would be highly appreciated. 

 

Input

DateMonth on Book Loss Amount
1/01/20191500
1/02/201921000
1/03/201931500
1/04/201942000
1/05/201952500
1/06/201963000
1/07/201973500
1/08/201984000
1/09/201994500
1/10/2019105000
1/11/2019115500
1/12/2019126000
1/01/2020136500
1/02/2020147000
1/03/2020157500
1/04/2020168000
1/05/2020178500
1/06/2020189000
1/07/2020199500
1/08/20202010000
1/09/2020110500
1/10/2020211000
1/11/2020311500
1/12/2020412000
1/01/2021512500
1/02/2021613000
1/03/2021713500
1/04/2021814000
1/05/2021914500
1/06/20211015000
1/07/20211115500
1/08/20211216000
1/09/20211316500
1/10/20211417000
1/11/20211517500

 

Output

 

Month on Book201920202021
1500105000
21500215000
33000330000
45000450000
575004500012500
6105004500025500
7140004500039000
8180004500053000
9225004500067500
10275004500082500
11330004500098000
123900045000114000
13 51500130500
14 58500147500
15 66000165000
16 74000 
17 82500 
18 91500 
19 101000 
20 111000 
1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @WarrenBarrell 

 

Try to create a Measure with this code:

 

**bleep** Loss Amount = 
VAR _A =
    CALCULATE (
        MAX ( 'Table'[Month on Book ] ),
        REMOVEFILTERS ( 'Table'[Date].[Year] )
    )
VAR _B =
    CALCULATE (
        MAX ( 'Table'[Month on Book ] ),
        ALLEXCEPT ( 'Table', 'Table'[Date].[Year] )
    )
VAR _C =
    CALCULATE (
        SUM ( 'Table'[Loss Amount] ),
        FILTER ( ALL ( 'Table'[Month on Book ] ), 'Table'[Month on Book ] <= _A )
    ) + 0
RETURN
    IF ( _A <= _B, _C, 0 )

 

then create a matrix with this arangment:

VahidDM_0-1653014250216.png

 

 

output:

VahidDM_1-1653014266183.png

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 



View solution in original post

3 REPLIES 3
VahidDM
Super User
Super User

Hi @WarrenBarrell 

 

Try to create a Measure with this code:

 

**bleep** Loss Amount = 
VAR _A =
    CALCULATE (
        MAX ( 'Table'[Month on Book ] ),
        REMOVEFILTERS ( 'Table'[Date].[Year] )
    )
VAR _B =
    CALCULATE (
        MAX ( 'Table'[Month on Book ] ),
        ALLEXCEPT ( 'Table', 'Table'[Date].[Year] )
    )
VAR _C =
    CALCULATE (
        SUM ( 'Table'[Loss Amount] ),
        FILTER ( ALL ( 'Table'[Month on Book ] ), 'Table'[Month on Book ] <= _A )
    ) + 0
RETURN
    IF ( _A <= _B, _C, 0 )

 

then create a matrix with this arangment:

VahidDM_0-1653014250216.png

 

 

output:

VahidDM_1-1653014266183.png

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 



thank you very much Vahid! You have clearly explained and demonstrated this.

amitchandak
Super User
Super User

@WarrenBarrell , I think you need YTD. Use date table, Day, Month , year in visual should come from date table

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

 

or a new column

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

measure


YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

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.