Sunday, December 15, 2024

How to calculate Growth from Previous Non Consecutive Dates in Power BI

How to use DAX to calculate Growth from Previous Non Consecutive Dates in Power BI
Scenario:
Suppose we have a Sample Data with Sales (Qnty_Sold) for non consecutive Order Dates as follows:

The simple Data Model is as follows, where Calendar date is connected to the Order date of the sample data.

Now we will calculate the Sales Growth from Previous Non Consecutive dates using the below DAX Logics:
Total Sales = SUM(tbl_Sample[Qnty_Sold])

Prev Sales =
VAR _PrevDate =
    MAXX(
        FILTER( ALLSELECTED(tbl_Calendar[cDate]),
            tbl_Calendar[cDate] < SELECTEDVALUE(tbl_Calendar[cDate])
        ),
    tbl_Calendar[cDate]
    )
VAR _PrevSales =
    CALCULATE( [Total Sales],
        FILTER( ALLSELECTED(tbl_Calendar[cDate]), tbl_Calendar[cDate]= _PrevDate)
        )
RETURN
_PrevSales

Sales Growth =     IF ( [Prev Sales]<>0 && [Total Sales]<>0, DIVIDE([Total Sales],[Prev Sales])-1 )

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