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
Anonymous
Not applicable

Need to calculate cumulative on measure year/month wise

Hi All,

 

I need to to create on power bi something like below which is to create on Exel but not sure how to do it on power BI

Output:

 

YearPERIODACTIVECREATED (Cumulative)DELETED (Cumulative)NET IMPACT (Cumulative)CREATEDDELETED
2020Jan1228772,1776642,8412177664
2020Feb2827630,754-1,22,514-91,76028577-1,23,178
2020Mar2709957,936-1,50,873-92,93727182-28,359
2020Apr12870559,992-51,3238,669205699,550

 

Here 'ACTIVE' and 'CREATED' values  are already there, based on that I need to create other columns.

 

Deleted formula should be : H3(-1,23,178) =-C2 (12,287)-G3(28,577)+C3(28,276)

Created (Cumulative) : D3(30,754) = D2(2,177)+G3(28,577)

Deleted (Cumulative) : E3(-1,22,514) = E2(664)+H3(-1,23,178)

 

Input Data:

DateACTIVECREATED
12-12-2019130021974
18-12-2019210022300
12-01-202020001100
13-01-202020877177
14-01-202050000400
15-01-202050000500
16-02-2020102768000
17-02-202010000577
18-02-2020500010000
19-02-202020005000
20-02-202010005000
26-03-2020500010000
22-03-202060996182
23-03-20201600011000
13-04-202020001000
14-04-202070556
15-04-2020100001000

 

Only in the month of January the CREATED (Cumulative) and DELETED (Cumulative) will be same as Created and Deleted.

 

I am able to create Created (Cumulative) but it is not getting reset in every jan of each year.

 

Please find the link of the dashboard for better understanding help me with the solution of this issue.

 

https://app.powerbi.com/view?r=eyJrIjoiNmFjNzM3ODItOTEwOS00NjE1LWIyMWMtNmMyMTRkM2ZkNTRjIiwidCI6IjVhM...

 

Thanks in advance.

7 REPLIES 7
Anonymous
Not applicable

Hi All,

 

Please find the dashboard attached where you can see how the data looks like. According to that I need to calculate above measures which I have mentioned above. 

 

Here I am facing difficulty with calculate deleted cumulative which is taking last date deleted value where I want last deleted value for the previous month. And Every year January it has to be recalculate from created value, then cumulative and created should be same.

https://app.powerbi.com/view?r=eyJrIjoiNmFjNzM3ODItOTEwOS00NjE1LWIyMWMtNmMyMTRkM2ZkNTRjIiwidCI6IjVhM...

Please let me know if you have any solution of this issue.

 

Data looks like this:

 

DateACTIVECREATED
12-12-2019130021974
18-12-2019210022300
12-01-202020001100
13-01-202020877177
14-01-202050000400
15-01-202050000500
16-02-2020102768000
17-02-202010000577
18-02-2020500010000
19-02-202020005000
20-02-202010005000
26-03-2020500010000
22-03-202060996182
23-03-20201600011000
13-04-202020001000
14-04-202070556
15-04-2020100001000

 

Thanks in advance

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end. I assume that the default value for 'DELETED' is 664.

 

Table:

a1.png

 

You may create an index column in 'Query Editor' as below.

a2.png

 

Then you can create measures as below.

DELETED = 
var tab = 
ADDCOLUMNS(
    'Table',
    "Result",
    IF(
        [Year]=2020&&[PERIOD]="Jan",
        664,
        var _lastactive = LOOKUPVALUE('Table'[ACTIVE],'Table'[Index],[Index]-1)
        return
        -_lastactive-[CREATED]+[ACTIVE]
    )
)
return
SUMX(
    tab,
    [Result]
)

 

Created Cumulative = 
var tab = 
ADDCOLUMNS(
    'Table',
    "Result",
    CALCULATE(
        SUM('Table'[CREATED]),
        FILTER(
            ALL('Table'),
            'Table'[Index]<=EARLIER('Table'[Index])
        )
    )
)
return
SUMX(
    tab,
    [Result]
)

 

DELETED Cumulative = 
var tab = 
ADDCOLUMNS(
    'Table',
    "Result1",
    IF(
        [Year]=2020&&[PERIOD]="Jan",
        664,
        var _lastactive = LOOKUPVALUE('Table'[ACTIVE],'Table'[Index],[Index]-1)
        return
        -_lastactive-[CREATED]+[ACTIVE]
    )
)
var newtab = 
ADDCOLUMNS(
    tab,
    "Result2",
    var _index = [Index]
    var t = 
    ADDCOLUMNS(
        ALL('Table'),
        "Result1",
        IF(
            [Year]=2020&&[PERIOD]="Jan",
            664,
            var _lastactive = LOOKUPVALUE('Table'[ACTIVE],'Table'[Index],[Index]-1)
            return
            -_lastactive-[CREATED]+[ACTIVE]
        )
    )
    return
    SUMX(
        FILTER(
            t,
            [Index]<=_index
        ),
        [Result1]
    )
)
return
SUMX(
    newtab,
    [Result2]
)

 

NET IMPACT Cumulative = [Created Cumulative]+[DELETED Cumulative]

 

Result:

a3.png

 

Best Regards

Allan

 

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

 

Anonymous
Not applicable

Hi Allan,

 

Thanks for your reply but the data starts from year 2004. So hard coded year and period and deleted value will not give the correct result.

 

I have given here the dummy data.

Hi @Anonymous,

 

Have you tried to build a measure similar to 

Created (Cummulative) = CALCULATE(sum('Table'[CREATED]), FILTER(ALL('Table'), 'Table'[PeriodId] <= MAX('Table'[PeriodId]))) 

 

Please also include a .pbix file as it will make solving the problem with your data and data model much easier.

 

Richard



I hope this helps,
Richard

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

Proud to be a Super User!


richbenmintz
Solution Sage
Solution Sage

Hi @Anonymous,

 

After adding a couple of columns to your data table

- PeriodId (yyyymm)

- PeriodNum(Month number used to sort the period column)

 

I created the following Measure as an example of how to created the cummulative total

Created (Cummulative) = CALCULATE(sum('Table'[CREATED]), FILTER(ALL('Table'), 'Table'[PeriodId] <= MAX('Table'[PeriodId]))) 

 

Hope this helps,

Richard 


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!



I hope this helps,
Richard

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

Proud to be a Super User!


amitchandak
Super User
Super User

@Anonymous , for that you can ytd with a date calendar

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

refer:

https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

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 :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

Greg_Deckler
Super User
Super User

@Anonymous - There is a running total quick measure you can use in the Desktop. 

 

Otherwise, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.