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. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.