Thursday, December 14, 2017

DAX Formula to Calculate Cumulative Sum for YTD, QTD and MTD in Power BI

How to Create a New Measure to Calculate the Cumulative Sum for YTD, QTD and MTD in Power BI
Scenario :
Suppose we have a FactSales Tables follows..


On this Table, I have created two new Calculated Measures "QTD_GrossSales" and "MTD_GrossSales" as below, to calculate the Cumulative Total by Quarter and Month.

QTD Cumulative Sum :
QTD_GrossSales = CALCULATE(SUM(FactSales[Gross_Sales]),
DATESQTD(FactSales[Order_Date]))


Result :
MTD Cumulative Sum :
MTD_GrossSales = CALCULATE(SUM(FactSales[Gross_Sales]),
DATESMTD(FactSales[Order_Date]))

Result :

Similarly we can calculate the Cumulative Sum / Running Total for YTD using the following DAX Formula..

YTD Cumulative Sum :
YTD_GrossSales = CALCULATE(SUM(FactSales[Gross_Sales]),
DATESYTD(tbl_Calendar[Date_Id]))

Similarly we can calculate the Cumulative Sum / Running Total for All the Years in the Data Model using the following DAX Formula..

Cumulative Sum for all Years:
Cumulative_Sales = 
CALCULATE (
   Sum(FactSales[Net_Sales]),
    FILTER (
        ALL ( tbl_Calendar[Date_Id] ),
        tbl_Calendar[Date_Id] <= MAX (tbl_Calendar[Date_Id] )
               )
                  )

Result :

-------------------------------------------------------------------------------------------------------- 
Thanks, TAMATAM ; Business Intelligence & Analytics Professional 
--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog