Power BI for Data Analytics
May 18, 2025 at 08:36 AM
Today, let's understand the very important Power BI Topic: *DAX Expressions in Power BI* DAX, short for Data Analysis Expressions, is the formula language used in Power BI to perform custom calculations on your data. It’s similar to Excel formulas but optimized for working with data models, filters, and aggregations. *Types of DAX Expressions* *1. Calculated Columns* These are columns added to a table, where each row is calculated individually. For example, if you want to combine a customer's first and last name, you'd use: FullName = Customers[FirstName] & " " & Customers[LastName] *2. Measures* Measures perform aggregations like summing, averaging, or counting, and are calculated based on the current filters and context in your report. An example of a measure is: TotalSales = SUM(Sales[Amount]) *3. Calculated Tables* You can also create new tables using DAX, often used for filtered subsets of your existing data. For instance: HighValueSales = FILTER(Sales, Sales[Amount] > 1000) *Common DAX Functions* There are several categories of DAX functions: - Aggregation functions like SUM, AVERAGE, MIN, MAX, COUNT are used to perform calculations across rows. - Logical functions such as IF, SWITCH, AND, OR help you apply conditions in your logic. - Text functions like LEFT, RIGHT, CONCATENATE, FORMAT are used to manipulate string values. - Time intelligence functions such as DATEADD, SAMEPERIODLASTYEAR, TOTALYTD allow you to compare data across different time frames. - Filter functions like FILTER, CALCULATE, ALL, VALUES are used to control the data context within calculations. - Ranking functions such as RANKX help in ranking items like top-selling products. *Row Context vs Filter Context* Understanding context is crucial in DAX: - Row Context refers to the current row being evaluated, usually in calculated columns. - Filter Context is determined by slicers, filters, or visual elements, and it impacts how measures calculate results. *Useful DAX Patterns* - Running Total: You can calculate a cumulative total like this: - RunningTotal = CALCULATE(SUM(Sales[Amount]), FILTER(ALL(Sales[Date]), Sales[Date] <= MAX(Sales[Date]))) - Year-over-Year (YOY) Growth: A simple YOY growth formula: - YOYGrowth = DIVIDE([Total Sales] - [Total Sales LY], [Total Sales LY]) *Best Practices* - Use measures for aggregations instead of calculated columns, as they're more efficient. - Use variables (VAR) in complex formulas for better performance and readability. - Try to move business logic into DAX instead of relying only on filters in visuals. *React ❤️ for the next topic explanations* Power BI complete topics: https://whatsapp.com/channel/0029Vai1xKf1dAvuk6s1v22c/769
❤️ 👍 😂 👏 💔 😮 🙇‍♂️ 🥰 82

Comments