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
bajimmy1983
Helper V
Helper V

Cumulative Sales only by Selected Year

Hi all,

 

I am using power pivot with all relationships created and OK. There is one Dim Table called "date" and another Transaction Table called "pipe".

 

In "date" table there is a column with full date (DD/MM/YY) and another derived from it called "Year;

In "pipe" table I have same columns;

Relationship was created between Date columns from "date" table and Date column from "pipe" table.  

 

My objective is to set up a Calculated Filed (Measure) called CUMULATIVE ACTUAL BRL that will bring RUNNING TOTAL SALES month by month, but just from the year selected in the pivot table (FILTERS area in Pivot) and not all years <= this year.

 

In case my explanation is not clear... "pipe" table has sales from 2015 up to April, 2017, but I want to have a calculated field that will bring cumulative sales according to selected year PivotTable filters.

 

 

PivotTable Filter = 2017  Desired Outcome
   
Month NameACT. BIL. BRLCUMULATIVE ACT. BRL
JAN740.085740.085
FEV507.9421.248.027
MAR2.708.7073.956.734
ABR2.489.9696.446.703
MAI2.269.6158.716.318
JUN3.017.91011.734.228
JUL3.300.62115.034.849
AGO2.242.94517.277.794
SET1.701.14218.978.936
OUT1.971.31320.950.249
NOV1.704.31422.654.563
DEZ1.222.44723.877.010
Grand Total23.877.01023.877.010

 

Thank you so much in advance,

 

Jaderson Almeida
Business Coordinator
1 ACCEPTED SOLUTION

Hi all.

 

I think I found a solution regarding to my last reply. Talking to my wife today about it (and Yeah, she does not know anything about DAX) she helped me to figure out a way using a different approach of IF statement. Funny! At least it is working.

 

I know that you may have a lot of other ways to reach same outcome and I kindly ask you to share with us. Regardless this issue is a very basic one I think it is important to know about other ways and of course I am learning a lot with Power BI Community.

 

My New Calculated Field

 

ACT. Y. BIL. BRL :=
IF (
    OR (
        CALCULATE ( [ACT. BIL. BRL]; FILTER ( 'date'; 'date'[Month Number] ) ) = 0;
        CALCULATE ( [ACT. BIL. BRL]; FILTER ( 'date'; 'date'[Month Number] ) )
            = BLANK ()
    );
    BLANK ();
    CALCULATE (
        [ACT. BIL. BRL];
        FILTER (
            ALL ( 'date' );
            'date'[Year] = MAX ( 'date'[Year] )
                && 'date'[Date] <= MAX ( 'date'[Date] )
        )
    )
)

Thanks again,

 

 

 

Jaderson Almeida
Business Coordinator

View solution in original post

7 REPLIES 7

You need time intelligence. Everything you need to know is in this article I wrote

 

http://exceleratorbi.com.au/dax-time-intelligence-beginners/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Hi Matt, thanks for your reply. 

 

Actually I saw your article last week, but I forgot. Sorry. Thanks for remembering me. 

 

So, I start with this Calculated Field: 

CALCULATE([ACT. BIL. BRL];FILTER(ALL('date');'date'[Year] = MAX('date'[Year]) && 'date'[Date] <= MAX('date'[Date]))

 

I ended up with this result:

Year2017 
MONTHACT. BIL. BRLTOT YTD ACT. BIL. BRL
JAN22247482224748
FEV13709403595688
MAR03595688
ABR03595688
MAI03595688
JUN03595688
JUL03595688
AGO03595688
SET03595688
OUT03595688
NOV03595688
DEZ03595688
Grand Total35956883595688

 

I found another good article about "Cumulative Total" (http://www.daxpatterns.com/cumulative-total/). Here Marco Russo also give an example on how to "... avoid the propagation of the last value in periods that are later than the last transactions in your data."

 

I tried this Measure, but fail:

TOT YTD ACT. BIL. BRL :=
IF (
    MIN ( 'date'[Date] )
        < CALCULATE ( MAX ( pipe[MES CONTAB BILLING LOCAL] )ALL ( pipe ) );
    CALCULATE (
        [ACT. BIL. BRL];
        FILTER (
            ALL ( 'date' );
            'date'[Year] = MAX ( 'date'[Year] )
                && 'date'[Date] <= MAX ( 'date'[Date] )
        )
    )
)

 

Year2017 
   
MONTHACT. BIL. BRLTOT YTD ACT. BIL. BRL
JAN2.224.7482.224.748
FEV1.370.9403.595.688
MAR03.595.688
ABR00
MAI00
JUN00
JUL00
AGO00
SET00
OUT00
NOV00
DEZ00
Grand Total3.595.6883.595.688
Jaderson Almeida
Business Coordinator

Hi all.

 

I think I found a solution regarding to my last reply. Talking to my wife today about it (and Yeah, she does not know anything about DAX) she helped me to figure out a way using a different approach of IF statement. Funny! At least it is working.

 

I know that you may have a lot of other ways to reach same outcome and I kindly ask you to share with us. Regardless this issue is a very basic one I think it is important to know about other ways and of course I am learning a lot with Power BI Community.

 

My New Calculated Field

 

ACT. Y. BIL. BRL :=
IF (
    OR (
        CALCULATE ( [ACT. BIL. BRL]; FILTER ( 'date'; 'date'[Month Number] ) ) = 0;
        CALCULATE ( [ACT. BIL. BRL]; FILTER ( 'date'; 'date'[Month Number] ) )
            = BLANK ()
    );
    BLANK ();
    CALCULATE (
        [ACT. BIL. BRL];
        FILTER (
            ALL ( 'date' );
            'date'[Year] = MAX ( 'date'[Year] )
                && 'date'[Date] <= MAX ( 'date'[Date] )
        )
    )
)

Thanks again,

 

 

 

Jaderson Almeida
Business Coordinator

You are a life saver. 

 

Kudos.

I forgot to place final result: 

 

Desired_Outcome_OK.PNG

Jaderson Almeida
Business Coordinator

Hi @bajimmy1983,

I am very glad you have resolved your issue. Please mark right replay as answer, so other people will find solution easily.

In addtion, in the article, the date comes from Date table, so you'd better use the month in Date table, and the condition is  less than and equals to(<=highlighted in red line). You can modify your statement and row level, and check if it works fine.

Capture1.PNG

Best Regards,
Angelia

Hi Angelia, thanks for your reply.

 

Please check if I did correct, because if so, you can see "propagation" issue came back.

I do not want to have last cumulative Billings (7.615.365) replicated in months there is not billings yet. 

 

Note that in PivotTable I am using a field from 'date'Table called MONTH (which is the name of month. So a string). I tried to use MONTH in the calculated field, but as you already know I got an error because MIN function cannot handle strings, right?

 

 

ACT. Y. BIL. BRL TEST :=
IF (
    MIN ( 'date'[Month Number] )
        <= CALCULATE ( MAX ( pipe[MES CONTAB BILLING LOCAL] ); ALL ( pipe ) );
    CALCULATE (
        [ACT. BIL. BRL];
        FILTER (
            ALL ( 'date' );
            'date'[Year] = MAX ( 'date'[Year] )
                && 'date'[Date] <= MAX ( 'date'[Date] )
        )
    )
)

 

Outcome: 

 

ACT. Y. BIL. BRL TEST.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 Thanks again,

 

 

 

Jaderson Almeida
Business Coordinator

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.