In this post I would like to Record my DAX Learnings during my SQL Server Analysis Services days.
SQL Server Analysis Services
It is 1000X faster than SQL Server since the Data is stored in Memory in Compressed Format.
DAX
DAX stands for Data Analysis Expressions. It is widely used in Analysis Services, Power BI etc.
DAX looks similar to Excel Formulas.
DAX Measure
DAX Measure is the actual Formula.
DAX Variables
DAX Variables will be executed once they are Invoked
EVALUATE
Evaluates the Expression.
Eg: EVALUATE ( ‘DimProducts’)
Eg: EVALUATE( ‘DimProducts’ ) ORDER BY ‘DimProducts'[Date] DESC –Sorting Example
For Scalar Values, Use EVALUATE (ROW(“Column”, Variable)) syntax
Note: Add an EVALUATE in front of the Expression
ROW
Returns a Table with a Single Row.
Eg: EVALUATE ROW(“Total Sales”, SUM(FactSales[Price]),
“Total Quantity”, SUM(FactSales[Quantity]))
SUMMARY
Returns a summary table.
EVALUATE
SUMMARIZE(
DimProducts
, DimProducts[Id]
, DimProducts[Class]
, DimProducts[SubClass]
, “Sales Total”, SUM(FactSales[Price])
, “Quantity Total”, SUM(FactSales[Quantity])
)
CALCULATE
Evaluates an Expression when modified by a Filter.
FILTER
Returns a Subset of Table or Expression.
Eg: EVALUATE
FILTER(DimProducts,DimProducts[Class]=”Home Theatre”)
*Note the double quotes
More Filters: https://bit.ly/2L3iOdr
SUM
Sum is an Aggregator.
Eg: EVALUATE
SUMMARIZE (
DimProducts,
“Sum”, SUM ( DimProducts[Price] )
)
SUMX
SumX is an Iterator. Can Add Multiplications into this.
Eg: EVALUATE
SUMMARIZE (
DimProducts,
“Sum”, SUMX (DimProducts, DimProducts[Price] * 100)
)
ADDCOLUMNS
Adds calculated columns to the given table