So big thanks for mentioning this as a requirement! Now this is what I’ve got for you:
For the Count Type a simple SWITCH, TRUE statement will do:
Count Type =
SWITCH( TRUE(),
ISBLANK([Sales YTD]) && ISBLANK([Sales PYTD]), BLANK(),
[Increase_Decrease] >0, "Increase",
[Increase_Decrease] <0, "Decrease",
[Increase_Decrease] =0, "No Change"
)
.
Also relatively straight forward the Increase count:
Count Increase =
COUNTROWS(
FILTER(
SUMMARIZE( Orders, Orders[Product ID], People[Sales Rep] ),
[Increase_Decrease] >0
)
)
.
This is where it gets tricky because for the Decrease count we have to account for the PYTD values:
Count Decrease =
VAR ThisYear =
DISTINCT(
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
SUMMARIZE( Orders, Orders[Product ID], People[Sales Rep] ),
"__YTD Sales", CALCULATE( [Total Sales], DATESYTD('calendar'[Date] )),
"__PYTD Sales", CALCULATE( [Total Sales], SAMEPERIODLASTYEAR ( 'calendar'[Date] ), 'calendar'[IsPast] = TRUE() )
),
([__YTD Sales] - [__PYTD Sales]) <0
), "ProdID", [Product ID]
)
)
VAR LastYear =
DISTINCT(
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
SUMMARIZE( CALCULATETABLE( Orders, SAMEPERIODLASTYEAR( 'calendar'[Date] )), Orders[Product ID], People[Sales Rep] ),
"__YTD Sales", CALCULATE( [Total Sales], DATESYTD('calendar'[Date] )),
"__PYTD Sales", CALCULATE( [Total Sales], SAMEPERIODLASTYEAR ( 'calendar'[Date] ), 'calendar'[IsPast] = TRUE() )
),
([__YTD Sales] - [__PYTD Sales]) <0
), "ProdID", [Product ID]
)
)
VAR Result = DISTINCT( UNION( ThisYear, LastYear ))
RETURN
COUNTROWS( Result )
.
And the same is true for both No Change calculations here we also have to account for the PYTD
Count No Change =
VAR ThisYear =
DISTINCT(
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
SUMMARIZE( Orders, Orders[Product ID], People[Sales Rep] ),
"__YTD Sales", CALCULATE( [Total Sales], DATESYTD('calendar'[Date] )),
"__PYTD Sales", CALCULATE( [Total Sales], SAMEPERIODLASTYEAR ( 'calendar'[Date] ), 'calendar'[IsPast] = TRUE() )
),
([__YTD Sales] - [__PYTD Sales]) =0
), "ProdID", [Product ID]
)
)
VAR LastYear =
DISTINCT(
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
SUMMARIZE( CALCULATETABLE( Orders, SAMEPERIODLASTYEAR( 'calendar'[Date] ), 'calendar'[IsPast] = TRUE ), Orders[Product ID], People[Sales Rep] ),
"__YTD Sales", CALCULATE( [Total Sales], DATESYTD('calendar'[Date] )),
"__PYTD Sales", CALCULATE( [Total Sales], SAMEPERIODLASTYEAR ( 'calendar'[Date] ), 'calendar'[IsPast] = TRUE() )
),
([__YTD Sales] - [__PYTD Sales]) =0
), "ProdID", [Product ID]
)
)
VAR Result = DISTINCT( UNION( ThisYear, LastYear ))
RETURN
COUNTROWS( Result )
.
Count No Change v2 =
VAR ThisYear =
DISTINCT(
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
SUMMARIZE( Orders, Orders[Product ID], People[Sales Rep] ),
"__YTD Sales", CALCULATE( [Total Sales], DATESYTD('calendar'[Date] )),
"__PYTD Sales", CALCULATE( [Total Sales], SAMEPERIODLASTYEAR ( 'calendar'[Date] ), 'calendar'[IsPast] = TRUE() )
),
([__YTD Sales] - [__PYTD Sales]) =0
), "ProdID", [Product ID]
)
)
VAR LastYear =
DISTINCT(
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
SUMMARIZE( CALCULATETABLE( Orders, SAMEPERIODLASTYEAR( 'calendar'[Date] )), Orders[Product ID], People[Sales Rep] ),
"__YTD Sales", CALCULATE( [Total Sales], DATESYTD('calendar'[Date] )),
"__PYTD Sales", CALCULATE( [Total Sales], SAMEPERIODLASTYEAR ( 'calendar'[Date] ), 'calendar'[IsPast] = TRUE() )
),
([__YTD Sales] - [__PYTD Sales]) =0
), "ProdID", [Product ID]
)
)
VAR Result = DISTINCT( UNION( ThisYear, LastYear ))
RETURN
COUNTROWS( Result )
.
Now if someone has a better way to calculate these values, I would certainly like to know about it - so then please respond to this post. Thanks!
This is what it looks like on the report.
Thanks Kevin - I certainly learned from this post
Sample Dataset for PYTD.pbix (217.9 KB)