Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
heetu24
Helper I
Helper I

Cumulative sales

Hello, All I am stuck in one scenario.

 

Scenario: As per below screens shot. There is filter of Period and Year in Green color. In Power BI Period and Year are slicers.

In Year column records are  : (TY:-This Year), (YA:-Year Ago), & (2YA: 2 Year ago)

In Period column records are : MAT, YTD  & QTR.

I want to calculate Cumulative sales for "MAT" Period only and and each year such as TY, YA and 2 YA.

Note: API: Average Price Index column is given in the table. so against API cumulative sales value will be there.
  Brand Name are same because imagine item level data so each brand represents  different item you can ignore why it is same Brand in this scenario.


heetu24_0-1723573849724.png

 

Above screen shot is in Excel. How to do in Power BI. I am beginner in DAX. Thank you to read my query 🙂

1 ACCEPTED SOLUTION

Hi All
Fisrtly Irwan  thank you for your solution!
And @heetu24, We just need to make a slight change in Irwan's DAX, and the filtering of YEARS with the selectedvalue function can be done to accumulate different years.

Measure = 
VAR A=SELECTEDVALUE('data'[Year])
VAR C=MAX(data[Index])
VAR B=CALCULATE(
    SUM('data'[Sales Value]),FILTER(ALL('data'),
   'data'[Year]=A&&'data'[Index]<=C)
    )
    RETURN
    IF(
        MAX('data'[Index])=1,
        0,
        B)

vxingshenmsft_0-1723785532440.png

vxingshenmsft_1-1723785542173.png

If you have any other questions, check out the pbix file I uploaded, I hope it helps!

 

Hope it helps!

 

Best regards,
Community Support Team_ Tom Shen

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

3 REPLIES 3
Irwan
Super User
Super User

hello @heetu24 

 

please check if this accomodate your need.

 

since i dont see any order in that sample data, i assumed you have another column for sorting or indexing cummulative in that excel calculation. So i created another column for indexing from power query (this should be adjusted to your order column).

 

Irwan_0-1723594518084.png

create a new measure with following DAX 

Cummulative 1 = 
var _Index = SELECTEDVALUE('Table'[Index])
var _Sum =
CALCULATE(
    SUM('Table'[Sales Value]),
    FILTER(
        ALL('Table'),
        'Table'[Index]<=_Index
    )
)
Return
IF(
    _Index=1,
    0,
    _Sum
)
Cummulative 2 = 
var _Index = SELECTEDVALUE('Table'[Index])
var _Sum =
SUMX(
    FILTER(
        ALL('Table'),
        'Table'[Index]<=_Index
    ),
    'Table'[Sales Value]
)
Return
IF(
    _Index=1,
    0,
    _Sum
)

both measure Cummulative 1 and Cummulative 2 have same result, but Cummulative 1 is using CALCULATE while Cummulative 2 is using SUMX. Choose either way should be fine.

 

Hope this will help you.

Thank you.

Hi Thank you for this solution.

 

As I mentioned in screen shot. I am looking cumulative for year  wise that you provided cumulative for TY and same for YA and 2 YA .

So if user select year select on TY/YA /2YA any of this so dynamically it can change cumulative sales. Is it possible to use summarize DAX function?

Hi All
Fisrtly Irwan  thank you for your solution!
And @heetu24, We just need to make a slight change in Irwan's DAX, and the filtering of YEARS with the selectedvalue function can be done to accumulate different years.

Measure = 
VAR A=SELECTEDVALUE('data'[Year])
VAR C=MAX(data[Index])
VAR B=CALCULATE(
    SUM('data'[Sales Value]),FILTER(ALL('data'),
   'data'[Year]=A&&'data'[Index]<=C)
    )
    RETURN
    IF(
        MAX('data'[Index])=1,
        0,
        B)

vxingshenmsft_0-1723785532440.png

vxingshenmsft_1-1723785542173.png

If you have any other questions, check out the pbix file I uploaded, I hope it helps!

 

Hope it helps!

 

Best regards,
Community Support Team_ Tom Shen

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.