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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Consider stores with monthly sales

Hi everybody !

 

I have this problems:

I need to compare sales in the same stores, but I have to consider that if a store had sales in January 2019 but no sales in 2018, I don't have to take that value into account.

 

What do you recommend I do?

 

I give you the example together with the formula in excel.

 

example.PNG

 

Thanks !!!

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

 We can use the following measures to meet your requirement:

 

Sales last year = 
VAR y =
    YEAR ( TODAY () ) - 1
VAR t =
    ADDCOLUMNS (
        GROUPBY ( FILTER ( 'Table', YEAR ( [Date] ) = y ), 'Table'[Date].[MonthNo] ),
        "MonthSales",
        VAR temp = [Date].[MonthNo]
        RETURN
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                FILTER ( 'Table', YEAR ( [Date] ) = y && MONTH ( [Date] ) = temp )
            )
    )
VAR haszeromonth =
    COUNTX ( t, IF ( [MonthSales] = 0, 1, BLANK () ) )
RETURN
    IF ( haszeromonth > 0, 0, SUMX ( t, [MonthSales] ) )

 

Sales this year = 
VAR y =
    YEAR ( TODAY () )
VAR t =
    ADDCOLUMNS (
        GROUPBY ( FILTER ( 'Table', YEAR ( [Date] ) = y ), 'Table'[Date].[MonthNo] ),
        "MonthSales",
        VAR temp = [Date].[MonthNo]
        RETURN
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                FILTER ( 'Table', YEAR ( [Date] ) = y && MONTH ( [Date] ) = temp )
            )
    )
VAR haszeromonth =
    COUNTX ( t, IF ( [MonthSales] = 0, 1, BLANK () ) )
RETURN
    IF (
        [Sales last year] = 0,
        0,
        IF ( haszeromonth > 0, 0, SUMX ( t, [MonthSales] ) )
    )

 

Sales Growth = 
DIVIDE ( [Sales this year] - [Sales last year], [Sales last year], BLANK () )

 

24.PNG25.PNG26.PNG


Best regards,

Community Support Team _ Dong Li
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

7 REPLIES 7
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create following measures to meet your requirement:

 

Jan-April 2018 SSS = 
IF (
    SUM ( '2018'[ene-18] ) <= 0
        || SUM ( '2018'[feb-18] ) <= 0
        || SUM ( '2018'[mar-18] ) <= 0
        || SUM ( '2018'[abr-18] ) <= 0
        || SUM ( '2019'[ene-19] ) <= 0
        || SUM ( '2019'[feb-19] ) <= 0
        || SUM ( '2019'[mar-19] ) <= 0
        || SUM ( '2019'[abr-19] ) <= 0,
    0,
    SUM ( '2018'[ene-18] ) + SUM ( '2018'[feb-18] )
        + SUM ( '2018'[mar-18] )
        + SUM ( '2018'[abr-18] )
)

 

Jan-April 2019 SSS = 
IF (
    SUM ( '2018'[ene-18] ) = 0
        || SUM ( '2018'[feb-18] ) = 0
        || SUM ( '2018'[mar-18] ) = 0
        || SUM ( '2018'[abr-18] ) = 0
        || SUM ( '2019'[ene-19] ) = 0
        || SUM ( '2019'[feb-19] ) = 0
        || SUM ( '2019'[mar-19] ) = 0
        || SUM ( '2019'[abr-19] ) = 0,
    0,
    + SUM ( '2019'[ene-19] ) + SUM ( '2019'[feb-19] )
        + SUM ( '2019'[mar-19] )
        + SUM ( '2019'[abr-19] )
)

 

April YTD SSS Growth (%) = 
DIVIDE (
    [Jan-April 2019 SSS] - [Jan-April 2018 SSS],
    [Jan-April 2018 SSS],
    BLANK ()
)

 

4.PNG

 


Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-lid-msft  !  Thank you for your reply !

 

While I had given as an example from January to April, the idea is that it is according to a selected period. That's why your solution in that case would be complicated.

Stores 2.PNG

 

For example for "x" period selected I should consider the stores that had sales for this year and the previous year.

Regards!!

Hi @Anonymous ,

 

Does you have 12 columns as 12 months in every year table or  do you have the date column such as following?

 

Store ID Date Amount
Store 1 2019/1/1 10
Store 1 2019/1/2 20
Store 1 2018/1/1 30
Store 2 2018/2/1 10
Store 3 2019/3/1 20
Store 4 2018/3/1 30

 


Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-lid-msft I've got the date column like on your table.

Hi @Anonymous ,

 

 We can use the following measures to meet your requirement:

 

Sales last year = 
VAR y =
    YEAR ( TODAY () ) - 1
VAR t =
    ADDCOLUMNS (
        GROUPBY ( FILTER ( 'Table', YEAR ( [Date] ) = y ), 'Table'[Date].[MonthNo] ),
        "MonthSales",
        VAR temp = [Date].[MonthNo]
        RETURN
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                FILTER ( 'Table', YEAR ( [Date] ) = y && MONTH ( [Date] ) = temp )
            )
    )
VAR haszeromonth =
    COUNTX ( t, IF ( [MonthSales] = 0, 1, BLANK () ) )
RETURN
    IF ( haszeromonth > 0, 0, SUMX ( t, [MonthSales] ) )

 

Sales this year = 
VAR y =
    YEAR ( TODAY () )
VAR t =
    ADDCOLUMNS (
        GROUPBY ( FILTER ( 'Table', YEAR ( [Date] ) = y ), 'Table'[Date].[MonthNo] ),
        "MonthSales",
        VAR temp = [Date].[MonthNo]
        RETURN
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                FILTER ( 'Table', YEAR ( [Date] ) = y && MONTH ( [Date] ) = temp )
            )
    )
VAR haszeromonth =
    COUNTX ( t, IF ( [MonthSales] = 0, 1, BLANK () ) )
RETURN
    IF (
        [Sales last year] = 0,
        0,
        IF ( haszeromonth > 0, 0, SUMX ( t, [MonthSales] ) )
    )

 

Sales Growth = 
DIVIDE ( [Sales this year] - [Sales last year], [Sales last year], BLANK () )

 

24.PNG25.PNG26.PNG


Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

Try something like this. This should not give this year data, when last year data is not there

Sales YTD on LYTD = 
Var   _start_date=(minx('Date',STARTOFYEAR('Date'[Date]))) 
Var   _end_date=(max('Date'[Date]))

Var _last_year_mtd_val= CALCULATE(sum(Sales[Sales Amount]),Sales[Sales Date] >= _start_date && (Sales[Sales Date]) <= _end_date,filter(Sales,COUNTROWS(SAMEPERIODLASTYEAR(Sales[Sales Date]))>0))
return
_last_year_mtd_val

Using datesytd

 

Sales YTD on LYTD Using datesyrd = 
Var _last_year_mtd_val= CALCULATE(sum(Sales[Sales Amount]),DATESYTD('Date'[Date Filer]),filter(Sales,COUNTROWS(SAMEPERIODLASTYEAR(Sales[Sales Date]))>0))
return
_last_year_mtd_val

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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