ALLSELECTED looks like a special function that is able to understand what the user selected in the pivot table, retrieving the original filter context under which the pivot table is running. However, how it is possible that a DAX function knows what a user selected in a pivot table? If
Analyzing table and column size is an important step in optimizing a data model for Power Pivot, Power BI, or Analysis Services Tabular. This article describes VertiPaq Analyzer, an Excel workbook to analyze detailed information extracted from Dynamic Management Views.
DAX is a functional language that does not allow you to create functions. However, if you need to pass a parameter to an algorithm, you can use a measure passing a value through a filter argument in CALCULATE, as described in the following article.