0% found this document useful (0 votes)
51 views

Dax

DAX (Data Analysis Expressions) is a collection of functions, operators, and constants used to create custom calculations and data models in Power BI, Power Pivot, and other Microsoft business analytics tools. DAX allows users to create calculated columns, measures, and tables to analyze

Uploaded by

analystmaniac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Dax

DAX (Data Analysis Expressions) is a collection of functions, operators, and constants used to create custom calculations and data models in Power BI, Power Pivot, and other Microsoft business analytics tools. DAX allows users to create calculated columns, measures, and tables to analyze

Uploaded by

analystmaniac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

# [ Power BI Advanced DAX Patterns ] CheatSheet

1. Advanced Time Intelligence Patterns

● Previous Period Same Year: Previous PYSD = CALCULATE([Sales],


SAMEPERIODLASTYEAR('Date'[Date]), DATEADD('Date'[Date], -1, MONTH))
● Moving Annual Total: MAT = CALCULATE([Sales], DATESINPERIOD('Date'[Date],
LASTDATE('Date'[Date]), -12, MONTH))
● Moving Year-to-Date: Moving YTD = CALCULATE([Sales],
DATESYTD(LASTDATE('Date'[Date])))
● Year-to-Date Growth: YTD Growth = DIVIDE([YTD Sales] - [PY YTD Sales], [PY
YTD Sales])
● Rolling N Periods: Rolling 6M = CALCULATE([Sales],
DATESINPERIOD('Date'[Date], LASTDATE('Date'[Date]), -5, MONTH))
● Custom Year Start: Custom YTD = CALCULATE([Sales], DATESYTD('Date'[Date],
"06-30"))
● Period over Period Growth: PoP Growth = DIVIDE([Sales] - [Previous Period
Sales], [Previous Period Sales])
● Rolling Average: 6M Rolling Avg = AVERAGEX(DATESINPERIOD('Date'[Date],
LASTDATE('Date'[Date]), -5, MONTH), [Sales])
● Progressive Total: Progressive Total = CALCULATE([Sales],
DATESINPERIOD('Date'[Date], FIRSTDATE('Date'[Date]),
DATEDIFF(FIRSTDATE('Date'[Date]), LASTDATE('Date'[Date]), DAY), DAY))
● Quarter to Date: QTD = CALCULATE([Sales], DATESQTD('Date'[Date]))

2. Advanced Filtering Patterns

● Dynamic Top N: Top N Sales = CALCULATE([Sales],


TOPN(SELECTEDVALUE(Parameters[TopN]), ALL(Product), [Sales], DESC))
● Relative Period Filter: Relative Filter = CALCULATE([Sales],
DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -[Selected Periods],
MONTH))
● Exclude Filter Context: Total Regardless of Filter = CALCULATE([Sales],
ALL('Product'))
● Keep Filters: Keep Category Filter = CALCULATE([Sales],
KEEPFILTERS(Product[Category] = "Electronics"))
● Remove Filter: Remove Product Filter = CALCULATE([Sales],
REMOVEFILTERS('Product'))

3. Hierarchical Navigation Patterns

● Parent Level Calculation: Parent Sales = CALCULATE([Sales],


GROUPBY(RELATEDTABLE(Hierarchy), Hierarchy[ParentID]))
By: Waleed Mousa
● Child Level Aggregation: Child Sum = SUMX(RELATEDTABLE(ChildTable),
[ChildValue])
● Hierarchy Level Detection: Current Level = ISINSCOPE(Product[Category]) +
ISINSCOPE(Product[Subcategory]) + ISINSCOPE(Product[Product])
● Dynamic Parent-Child: Dynamic Parent = IF(ISFILTERED(Hierarchy[Level]),
LOOKUPVALUE(Hierarchy[Parent], Hierarchy[Child],
SELECTEDVALUE(Hierarchy[Child])), BLANK())
● Level-Based Calculation: Level Calc = SWITCH(TRUE(),
ISINSCOPE(Product[Category]), [Category Total],
ISINSCOPE(Product[Subcategory]), [Subcategory Total], [Product Total])

4. Running Total Patterns

● Running Total by Date: Running Total = CALCULATE([Sales],


FILTER(ALL('Date'), 'Date'[Date] <= MAX('Date'[Date])))
● Running Total by Category: Category Running Total = CALCULATE([Sales],
FILTER(ALL(Product[Category]), Product[CategoryRank] <=
MAX(Product[CategoryRank])))
● Running Total with Reset: Monthly Running Total = CALCULATE([Sales],
DATESYTD('Date'[Date], "12-31"))
● Cumulative Distinct Count: Cumulative Customers =
CALCULATE(DISTINCTCOUNT(Sales[CustomerID]), FILTER(ALL('Date'),
'Date'[Date] <= MAX('Date'[Date])))
● Running Average: Running Avg = DIVIDE([Running Total], [Running Count])

5. Market Share Patterns

● Market Share: Market Share = DIVIDE([Sales], CALCULATE([Sales],


ALL(Product)))
● Market Share by Category: Category Share = DIVIDE([Sales],
CALCULATE([Sales], ALL(Product[Product])))
● Running Market Share: Running Share = DIVIDE([Running Total],
CALCULATE([Running Total], ALL(Product)))
● Relative Market Position: Market Position = RANKX(ALL(Product), [Sales],,
DESC)
● Share of Parent: Parent Share = DIVIDE([Sales], CALCULATE([Sales],
ALL(Product[Subcategory])))

6. Advanced Aggregation Patterns

● Weighted Average: Weighted Avg = SUMX(Sales, Sales[Quantity] *


Sales[Price]) / SUM(Sales[Quantity])

By: Waleed Mousa


● Distinct Count with Conditions: Distinct Active Customers =
CALCULATE(DISTINCTCOUNT(Customer[CustomerID]), Customer[Status] =
"Active")
● Conditional Sum: Conditional Total = SUMX(Sales, IF(Sales[Quantity] > 10,
Sales[Amount], 0))
● First Non-Blank: First Sale = CALCULATE(MIN(Sales[Date]), Sales[Amount] >
0)
● Last Non-Blank: Last Sale = CALCULATE(MAX(Sales[Date]), Sales[Amount] > 0)

7. Statistical Patterns

● Z-Score: Z-Score = DIVIDE([Value] - AVERAGE([Value]), STDEV.P([Value]))


● Percentile: 95th Percentile = PERCENTILE.EXC(Sales[Amount], 0.95)
● Moving Standard Deviation: Moving StDev =
STDEV.P(DATESINPERIOD('Date'[Date], LASTDATE('Date'[Date]), -6, MONTH),
[Value])
● Correlation: Price-Sales Correlation = CALCULATE(CORRELATION(Sales[Price],
Sales[Quantity]))
● Linear Regression: Trend Line = AVERAGE([Value]) + (MAX('Date'[DateKey]) -
AVERAGE('Date'[DateKey])) * DIVIDE(SUMX(VALUES('Date'), ([Value] -
AVERAGE([Value])) * ('Date'[DateKey] - AVERAGE('Date'[DateKey]))),
SUMX(VALUES('Date'), POWER('Date'[DateKey] - AVERAGE('Date'[DateKey]),
2)))

8. Segmentation Patterns

● Dynamic Segmentation: Segment = SWITCH(TRUE(), [Value] > [95th Percentile],


"Top", [Value] > [75th Percentile], "High", [Value] > [25th Percentile],
"Medium", "Low")
● ABC Analysis: ABC Class = SWITCH(TRUE(), [Running Share] <= 0.7, "A",
[Running Share] <= 0.9, "B", "C")
● RFM Score: RFM Score = ([Recency Score] * 100) + ([Frequency Score] * 10)
+ [Monetary Score]
● Customer Lifecycle: Lifecycle Stage = SWITCH(TRUE(), [Days Since Last
Purchase] > 365, "Churned", [Purchase Count] = 1, "New", [Purchase
Frequency] > [Avg Purchase Frequency], "Active", "At Risk")
● Value Tiers: Value Tier = SWITCH(TRUE(), [Customer Value] >= [Tier 1
Threshold], "Platinum", [Customer Value] >= [Tier 2 Threshold], "Gold",
[Customer Value] >= [Tier 3 Threshold], "Silver", "Bronze")

9. Date Intelligence Patterns

● Fiscal Year Calculations: Fiscal Year = YEAR(EDATE('Date'[Date], -6))

By: Waleed Mousa


● Business Days: Business Days = CALCULATE(COUNTROWS('Date'),
'Date'[IsBusinessDay] = TRUE)
● Custom Week Numbers: Week Number = WEEKNUM('Date'[Date], 2)
● Period to Date Toggle: PTD Toggle = IF(SELECTEDVALUE(Toggle[ShowPTD]) =
"Yes", [PTD Value], [Regular Value])
● Dynamic Time Comparison: Time Comparison =
SWITCH(SELECTEDVALUE(TimeCompare[Period]), "YOY", [YOY Growth], "MOM",
[MOM Growth], "QOQ", [QOQ Growth])

10. Advanced Cross-Filtering Patterns

● Bidirectional Cross-Filter: Cross Filter Sales = CALCULATE([Sales],


CROSSFILTER(Products[ProductID], Sales[ProductID], Both))
● Selective Cross-Filter: Filtered Sales = CALCULATE([Sales],
TREATAS(VALUES(SelectedProducts[ProductID]), Products[ProductID]))
● Multi-Table Filter: Complex Filter = CALCULATETABLE(Sales,
INTERSECT(FILTER(Products, [Condition1]), FILTER(Customers,
[Condition2])))
● Dynamic Relationship Filter: Dynamic Filter = CALCULATE([Sales],
USERELATIONSHIP(Sales[Date], Calendar[Date]))
● Prevent Filter Flow: Isolated Calculation = CALCULATE([Sales],
CROSSFILTER(Products[CategoryID], Sales[ProductID], None))

11. Conditional Formatting Patterns

● Dynamic Color Scaling: Color Scale = DIVIDE([Value] - [Minimum], [Maximum]


- [Minimum])
● Multi-Condition Format: Format Rule = SWITCH(TRUE(), [Value] > [Target] *
1.1, "Green", [Value] > [Target], "Yellow", "Red")
● Relative Performance Format: Performance Indicator = SWITCH(TRUE(), [Value]
> [Average] * 1.2, 3, [Value] > [Average], 2, 1)
● Time-Based Format: Time Format = IF([Days Since Last Purchase] > 90,
"Alert", "Normal")
● Variance-Based Format: Variance Format = IF(ABS([Actual] - [Target]) /
[Target] > 0.1, "Significant", "Normal")

12. Dynamic Measure Patterns

● Measure Switch: Dynamic Measure =


SWITCH(SELECTEDVALUE(MeasureSelector[Measure]), "Sales", [Total Sales],
"Profit", [Total Profit], "Units", [Total Units])

By: Waleed Mousa


● Dynamic Aggregation: Dynamic Agg = SWITCH(SELECTEDVALUE(AggType[Type]),
"Sum", SUM(Sales[Value]), "Average", AVERAGE(Sales[Value]), "Count",
COUNT(Sales[Value]))
● Dynamic Time Period: Dynamic Period = CALCULATE([Sales],
DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -[Selected Periods],
[Selected Time Grain]))
● Dynamic Comparison: Dynamic Compare =
SWITCH(SELECTEDVALUE(CompareType[Type]), "YOY", [YOY Comparison],
"Budget", [Budget Comparison], "Forecast", [Forecast Comparison])
● Dynamic Currency Conversion: Currency Convert = [Base Amount] *
LOOKUPVALUE(ExchangeRates[Rate], ExchangeRates[Currency],
SELECTEDVALUE(Currency[Code]))

13. Error Handling Patterns

● Division by Zero: Safe Division = IFERROR(DIVIDE([Numerator],


[Denominator]), 0)
● Null Handling: Safe Value = COALESCE([Value1], [Value2], [Value3], 0)
● Multiple Error Types: Protected Calc = IF(ISBLANK([Value]), 0,
IF(ISERROR([Calculation]), "Error", [Calculation]))
● Boundary Check: Valid Range = IF([Value] < [Min] || [Value] > [Max], "Out
of Range", [Value])
● Type Check: Type Safe = IF(ISTEXT([Value]), "Text", IF(ISNUMBER([Value]),
"Number", "Other"))

14. Performance Optimization Patterns

● Optimized Filter: Fast Filter = CALCULATE([Sales],


KEEPFILTERS(Products[Category] IN {"A", "B", "C"}))
● Materialized Calculation: Cached Value = CALCULATE([Expensive Calculation],
KEEPFILTERS(ALL('Date')))
● Selective Load: Efficient Load = CALCULATE([Sales], TOPN(1000, Sales,
[Amount], DESC))
● Indexed Search: Quick Lookup = LOOKUPVALUE(Products[Name], Products[ID],
[Selected ID], "Not Found")
● Optimized Join: Fast Join = CALCULATETABLE(Sales,
TREATAS(VALUES(Products[ID]), Sales[ProductID]))

15. Advanced Financial Patterns

● Rolling Forecast: Rolling Forecast = IF([Date] > TODAY(), [Forecast],


[Actual])

By: Waleed Mousa


● Compound Growth Rate: CAGR = POWER(DIVIDE(LASTNONBLANK([Value], [Year]),
FIRSTNONBLANK([Value], [Year])), 1/([Periods] - 1)) - 1
● Working Capital: Working Capital = [Current Assets] - [Current Liabilities]
● Debt-to-Equity Ratio: D/E Ratio = DIVIDE([Total Liabilities], [Total
Equity])
● Quick Ratio: Quick Ratio = DIVIDE([Current Assets] - [Inventory], [Current
Liabilities])

16. Advanced Sales Patterns

● Sales Velocity: Sales Velocity = DIVIDE([Opportunities] * [Win Rate] * [Avg


Deal Size], [Sales Cycle Length])
● Pipeline Coverage: Pipeline Coverage = DIVIDE([Pipeline Value], [Sales
Target])
● Win Rate: Win Rate = DIVIDE([Won Opportunities], [Total Opportunities])
● Average Sales Cycle: Avg Sales Cycle = AVERAGEX(FILTER(Opportunities,
[Status] = "Won"), DATEDIFF([Created Date], [Close Date], DAY))
● Sales Efficiency: Sales Efficiency = DIVIDE([Revenue], [Sales Cost])

17. Advanced Customer Analysis Patterns

● Customer Lifetime Value: CLV = [Average Purchase Value] * [Purchase


Frequency] * [Customer Lifespan]
● Churn Rate: Churn Rate = DIVIDE([Churned Customers], [Total Customers])
● Net Promoter Score: NPS = DIVIDE([Promoters] - [Detractors], [Total
Responses])
● Customer Acquisition Cost: CAC = DIVIDE([Marketing Spend], [New Customers])
● Retention Rate: Retention Rate = DIVIDE([Retained Customers], [Previous
Period Customers])

18. Advanced Inventory Patterns

● Days Inventory Outstanding: DIO = DIVIDE([Average Inventory], [COGS]) * 365


● Stockout Rate: Stockout Rate = DIVIDE([Stockout Days], [Total Days])
● Inventory Turnover: Inventory Turnover = DIVIDE([COGS], [Average
Inventory])
● Safety Stock Level: Safety Stock = [Average Daily Demand] * [Lead Time] *
[Safety Factor]
● Economic Order Quantity: EOQ = SQRT(DIVIDE(2 * [Annual Demand] * [Order
Cost], [Holding Cost]))

19. Advanced Marketing Patterns

By: Waleed Mousa


● Marketing ROI: Marketing ROI = DIVIDE([Revenue from Campaign] - [Campaign
Cost], [Campaign Cost])
● Cost Per Acquisition: CPA = DIVIDE([Marketing Spend], [New Customers])
● Conversion Rate: Conversion Rate = DIVIDE([Conversions], [Total Visitors])
● Attribution Modeling: Attribution =
SWITCH(SELECTEDVALUE(Attribution[Model]), "First Touch", [First Touch
Value], "Last Touch", [Last Touch Value], "Multi-Touch", [Multi-Touch
Value])
● Campaign Effectiveness: Campaign Effect = DIVIDE([Campaign Revenue], [Total
Revenue])

20. Statistical Analysis Patterns

● Moving Average Convergence: MACD = [12-Period EMA] - [26-Period EMA]


● Bollinger Bands: Upper Band = [20-Day MA] + (2 * [20-Day StDev])
● Relative Strength Index: RSI = 100 - (100 / (1 + [Average Gain] / [Average
Loss]))
● Standard Error: Standard Error = DIVIDE(STDEV.P([Values]),
SQRT(COUNT([Values])))
● Confidence Interval: CI = [Mean] + (1.96 * [Standard Error])

21. Advanced Analytical Patterns

● Cohort Analysis: Cohort Performance = CALCULATE([Metric],


FILTER(ALL(Users), Users[CohortDate] = SELECTEDVALUE(Calendar[Date])))
● Basket Analysis: Product Affinity =
DIVIDE(COUNTROWS(INTERSECT(Product1Sales, Product2Sales)),
COUNTROWS(Product1Sales))
● RFM Scoring: RFM Combined = ([Recency Score] * 100) + ([Frequency Score] *
10) + [Monetary Score]
● Decay Analysis: Value Decay = [Initial Value] * POWER((1 - [Decay Rate]),
[Periods])
● Propensity Score: Purchase Propensity = ([Historical Purchase Rate] * 0.4)
+ ([Engagement Score] * 0.3) + ([Demographics Score] * 0.3)

22. Advanced Time Series Patterns

● Seasonal Decomposition: Seasonality Factor = DIVIDE([Period Value],


CALCULATE(AVERAGE([Value]), ALL('Time')))
● Exponential Smoothing: EMA = [Alpha] * [Current Value] + (1 - [Alpha]) *
[Previous EMA]
● Double Moving Average: DMA = 2 * [SMA1] - [SMA2]

By: Waleed Mousa


● Holt-Winters Forecast: HW Forecast = ([Level] + [Trend] * [Periods]) *
[Seasonal Factor]
● Auto-Regression: AR = [Intercept] + SUMX(GENERATESERIES(1, [Order]),
[Coefficient] * [Lagged Value])

23. Business Metric Patterns

● Gross Margin: Gross Margin % = DIVIDE([Revenue] - [COGS], [Revenue])


● Operating Leverage: Operating Leverage = DIVIDE([Percent Change in EBIT],
[Percent Change in Revenue])
● Asset Turnover: Asset Turnover = DIVIDE([Revenue], [Average Total Assets])
● Return on Investment: ROI = DIVIDE([Net Profit], [Investment])
● Economic Value Added: EVA = [NOPAT] - ([Capital Employed] * [WACC])

24. Advanced Segmentation Patterns

● Value-Based Segmentation: Value Segment = SWITCH(TRUE(), [CLV] > [90th


Percentile], "High", [CLV] > [50th Percentile], "Medium", "Low")
● Behavior-Based Segmentation: Behavior Segment = CONCATENATE([Purchase
Pattern], "-", [Channel Preference], "-", [Price Sensitivity])
● Dynamic Clustering: Cluster = SWITCH(TRUE(), [Factor1] > [Threshold1] &&
[Factor2] > [Threshold2], "Cluster1", [Factor1] > [Threshold1],
"Cluster2", "Cluster3")
● Multi-Dimensional Segmentation: Complex Segment = CONCATENATE([Value
Segment], "-", [Behavior Segment], "-", [Loyalty Segment])
● Progressive Segmentation: Progressive Tier = SWITCH(TRUE(), [Current Tier] =
"Gold" && [Value] < [Gold Threshold], "Silver", [Current Tier] = "Silver"
&& [Value] > [Gold Threshold], "Gold", [Current Tier])

25. Advanced Risk Analysis Patterns

● Risk Score: Risk Score = ([Credit Risk] * 0.4) + ([Market Risk] * 0.3) +
([Operational Risk] * 0.3)
● Volatility Measure: Volatility = STDEV.P(DATESINPERIOD('Date'[Date],
LASTDATE('Date'[Date]), -12, MONTH), [Value])
● Value at Risk: VaR = [Mean] - ([Confidence Level] * [Standard Deviation])
● Risk-Adjusted Return: Risk Adjusted Return = DIVIDE([Return], [Risk])
● Probability of Default: PD = 1 - EXP(-[Hazard Rate] * [Time])

26. Advanced Pattern Recognition

● Trend Detection: Trend Direction = IF([Current MA] > [Previous MA], "Up",
IF([Current MA] < [Previous MA], "Down", "Sideways"))

By: Waleed Mousa


● Pattern Match: Pattern Match = IF(AND([Condition1], [Condition2],
[Condition3]), "Pattern Found", "No Pattern")
● Anomaly Detection: Is Anomaly = IF(ABS([Value] - [Mean]) > ([StDev] *
[Threshold]), "Anomaly", "Normal")
● Sequence Recognition: Sequence = IF(AND([Value1] > [Value2], [Value2] >
[Value3]), "Ascending", "Other")
● Change Point Detection: Change Point = IF(ABS([Current Value] - [Previous
Value]) > [Threshold], "Change", "Stable")

27. Advanced Forecasting Patterns

● Combined Forecast: Hybrid Forecast = ([Statistical Forecast] * [Statistical


Weight]) + ([ML Forecast] * [ML Weight])
● Safety Stock Forecast: Safety Stock = [Average Demand] * SQRT([Lead Time])
* [Service Factor]
● Demand Forecast: Demand Forecast = [Baseline] * [Seasonal Factor] * [Trend
Factor] * [Special Event Factor]
● Revenue Forecast: Revenue Forecast = [Unit Forecast] * [Price Forecast] *
(1 - [Discount Factor])
● Probabilistic Forecast: P90 Forecast = [Mean Forecast] + (1.28 * [Forecast
StDev])

28. Advanced Optimization Patterns

● Resource Allocation: Optimal Allocation = MAXIMIZE(SUMPRODUCT([Returns],


[Allocations]), [Constraints])
● Price Optimization: Optimal Price = [Base Price] * (1 + [Price Elasticity]
* [Demand Change])
● Inventory Optimization: Optimal Order Quantity = SQRT((2 * [Annual Demand]
* [Order Cost]) / [Holding Cost])
● Marketing Mix Optimization: Channel Mix = MAXIMIZE(SUMPRODUCT([Channel
Returns], [Channel Investments]), [Budget Constraint])
● Portfolio Optimization: Optimal Weight = MINIMIZE(PORTFOLIO_VARIANCE(),
[Return Target])

29. Advanced Machine Learning Integration

● Predictive Score: ML Score = [Feature1 Weight] * [Feature1] + [Feature2


Weight] * [Feature2] + [Bias]
● Classification Probability: Class Probability = 1 / (1 + EXP(-[ML Score]))
● Ensemble Prediction: Ensemble Result = ([Model1 Result] * [Weight1]) +
([Model2 Result] * [Weight2])

By: Waleed Mousa


● Feature Importance: Feature Impact = ABS([Feature Weight] * ([Feature
Value] - [Feature Mean])) / [Feature StDev]
● Model Performance: Model Accuracy = DIVIDE([Correct Predictions], [Total
Predictions])

30. Custom Advanced Patterns

● Custom Metric Blend: Blended Score = SQRT(POWER([Metric1], 2) +


POWER([Metric2], 2)) / SQRT(2)
● Complex Business Rule: Business Rule = SWITCH(TRUE(), AND([Condition1],
[Condition2]), [Result1], AND([Condition3], [Condition4]), [Result2],
[DefaultResult])
● Multi-Factor Ranking: Combined Rank = ([Factor1 Rank] * [Weight1] +
[Factor2 Rank] * [Weight2]) / ([Weight1] + [Weight2])
● Dynamic Thresholding: Adaptive Threshold = [Baseline] + ([Sensitivity] *
[Standard Deviation])
● Composite Performance Index: CPI = ([Financial Score] * 0.4) + ([Operational
Score] * 0.3) + ([Customer Score] * 0.2) + ([Innovation Score] * 0.1)

By: Waleed Mousa

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy