Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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.
Thanks !!!
Solved! Go to 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 () )
Best regards,
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 ()
)
Best regards,
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.
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,
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 () )
Best regards,
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
User | Count |
---|---|
131 | |
108 | |
101 | |
67 | |
64 |
User | Count |
---|---|
137 | |
115 | |
102 | |
71 | |
61 |