Posts

Showing posts from February, 2025

Daily DAX : Day 139 DATESMTD

 The DATESMTD function in Power BI's Data Analysis Expressions (DAX) language is a time intelligence function used to return a table containing a set of dates from the start of the current month up to a specified date. It’s particularly useful for creating month-to-date (MTD) calculations, such as sales totals, revenue, or other metrics aggregated from the beginning of the month to a given point in time. Syntax DATESMTD(<dates>)     <dates>: A column that contains date values. This is typically a date column from a date table in your data model. How It Works     DATESMTD takes a date column as input and returns a single-column table of dates.     The returned dates start from the first day of the month of the specified date (or the current context date) and end at the specified date.     It operates within the current filter context, meaning it respects any filters applied to the date column (e.g., slicers or row contexts in a rep...

Daily DAX : Day 138 CONTAINSSTRING

 The CONTAINSSTRING function in Power BI's DAX (Data Analysis Expressions) language is a handy tool for checking whether a specific substring exists within a given text string. It’s case-sensitive and returns a simple TRUE or FALSE result, making it great for filtering, conditional logic, or flagging data based on text patterns. Here’s the basic syntax: CONTAINSSTRING(text, search_text)     text: The string you’re searching in (e.g., a column or a text value).     search_text: The substring you’re looking for. For example, if you have a column called ProductDescription and want to check if it contains the word "Premium," you’d write: CONTAINSSTRING('Products'[ProductDescription], "Premium") If "Premium" is in the description, it returns TRUE; otherwise, FALSE. Main Use Case The primary use case for CONTAINSSTRING is text-based filtering or categorization. It’s especially useful when you need to identify rows in a dataset that contain specific k...

Daily DAX : Day 137 DB

DB Function in DAX Syntax: DAX DB(<cost>, <salvage>, <life>, <period>[, <month>]) Explanation: The DB function calculates the depreciation of an asset for a specific period using the fixed-declining balance method. This method applies a fixed depreciation rate to the asset’s remaining book value each period, resulting in higher depreciation amounts early in the asset’s life and lower amounts later. It’s an accelerated depreciation technique, often used for assets that lose value more quickly upfront, like machinery or vehicles.     <cost>: The initial cost of the asset (a numeric value).     <salvage>: The value of the asset at the end of its depreciation (salvage value), which can be zero.     <life>: The number of periods (e.g., years) over which the asset is depreciated (its useful life).     <period>: The specific period (e.g., year) for which you want to calculate depreciation. Must use th...

Daily DAX : Day 136 INFO.ROLES

What is INFO.ROLES? INFO.ROLES is a DAX function in Power BI that exposes the metadata about security roles defined in a semantic model, effectively replacing the older TMSCHEMA_ROLES DMV query syntax. It was part of the wave of over 50 INFO.* functions introduced in the December 2023 Power BI Desktop update, designed to make model metadata more accessible directly through DAX. These functions mirror the tabular model’s schema rowsets, providing a native DAX way to inspect objects like tables, measures, columns, and—in this case—roles. The function returns a table with details about the roles in your Power BI model, such as their names, descriptions, and potentially other attributes like the DAX filter expressions tied to them (though the exact columns can vary slightly based on the model and Power BI version). How Does It Work? You use INFO.ROLES in a DAX query, typically within the DAX Query View in Power BI Desktop or tools like DAX Studio. It’s not meant for use in measures, calcul...

Daily DAX : Day 135 FLOOR

 The FLOOR function in Power BI's DAX (Data Analysis Expressions) language is used to round a number down to the nearest multiple of a specified significance. Essentially, it helps you "snap" a value down to a defined interval or grid, which can be really useful for simplifying data or aligning it to specific increments. Syntax The FLOOR function has the following syntax: FLOOR(<number>, <significance>)     <number>: The value you want to round down.     <significance>: The multiple to which you want to round the number down. This must be a positive number. The function returns the largest multiple of significance that is less than or equal to number. If either argument is non-numeric or if significance is negative, it will return an error. How It Works Let’s break it down with some examples:     FLOOR(7.8, 1)           Rounds 7.8 down to the nearest multiple of 1.         ...

Daily DAX : Day 134 INFO.PARTITIONSTORAGES

 In Power BI, the DAX function INFO.PARTITIONSTORAGES is one of the newer "INFO" functions introduced to provide metadata about a data model. Specifically, INFO.PARTITIONSTORAGES retrieves information about the storage details of partitions within the model. It’s part of a family of functions that mirror the Dynamic Management Views (DMVs) traditionally used in tools like SQL Server Analysis Services, but now made accessible directly within DAX for Power BI. What It Does INFO.PARTITIONSTORAGES returns a table containing details about how partitions are stored in the data model. This includes metadata such as partition names, sizes, row counts, and other storage-related attributes. It’s designed to give you insight into the underlying structure and performance characteristics of your data model’s partitions. The function doesn’t take any arguments—it simply evaluates the current model and returns the relevant partition storage information. You’d typically use it in a DAX query...

Daily DAX : Day 133 TOTALYTD

 The TOTALYTD function in Power BI's Data Analysis Expressions (DAX) is a time intelligence function that calculates the year-to-date (YTD) total of an expression within a specified date column. It’s particularly useful for financial reporting, sales tracking, or any scenario where you need to aggregate data from the start of the year up to a given date. Syntax TOTALYTD(<expression>, <dates>[, <filter>][, <year_end_date>])     <expression>: The measure or calculation you want to aggregate (e.g., SUM(Sales[Amount])).     <dates>: A column containing dates, typically from a date table in your data model.     <filter> (optional): A filter expression to apply additional conditions to the calculation.     <year_end_date> (optional): A string literal defining a custom year-end date (e.g., "06/30" for a fiscal year ending June 30). If omitted, it defaults to December 31. How It Works TOTALYTD evaluates...

Daily DAX : Day 132 INFO.CATALOGS

 The INFO.CATALOGS function in Power BI's Data Analysis Expressions (DAX) is part of a set of relatively new "INFO" functions introduced to provide metadata about the semantic model in which it is used. These functions, including INFO.CATALOGS, were made available with the DAX query view updates around December 2023, drawing inspiration from the Dynamic Management Views (DMVs) used in Power BI, Azure Analysis Services, and SQL Server Analysis Services. What is INFO.CATALOGS? INFO.CATALOGS is a DAX function that returns a table containing information about the catalogs (databases) available in the current semantic model. In the context of Power BI, a "catalog" typically refers to the database or dataset that the model is based on. This function is particularly useful for introspecting the model's metadata without needing external tools or different query syntaxes like those used with traditional DMVs. When you execute INFO.CATALOGS, it generates a table with ...

Daily DAX : Day 131 SELECTEDMEASURE

 The SELECTEDMEASURE function in Power BI's DAX (Data Analysis Expressions) language is a powerful tool used primarily within calculation groups to dynamically reference the measure currently being evaluated in a report. It’s part of the calculation group feature introduced to streamline complex reporting scenarios and improve maintainability by reducing the need to duplicate measure logic. What is SELECTEDMEASURE? SELECTEDMEASURE is a DAX function that returns a reference to the measure that is currently active or "selected" in the context of a calculation group. It doesn’t take any arguments and is typically used in the expression of a calculation item within a calculation group. This allows you to write generic logic that can dynamically apply to whichever measure is being evaluated in a visual, without hardcoding specific measure names. Syntax SELECTEDMEASURE()     Returns: A reference to the measure currently being evaluated in the report context. Use Case SELECTEDME...

Daily DAX : Day 130 ADDCOLUMNS

 Power BI DAX Function: ADDCOLUMNS Function Overview: The ADDCOLUMNS function in Data Analysis Expressions (DAX) is used to add one or more columns to a table expression. This function allows you to enhance existing tables by appending new calculated columns without modifying the source data. Syntax: dax ADDCOLUMNS(<table>, <name>, <expression>[, <name>, <expression>]...)     <table>: The table to which new columns will be added.     <name>: The name of the new column to be added.     <expression>: The DAX expression that defines the values for the new column. How it Works:     ADDCOLUMNS does not alter the original table but returns a new table with additional columns.     Each <name> and <expression> pair adds a new column to the table. You can add multiple columns by repeating the <name>, <expression> pattern. Use Cases:     Data Enrichment:   ...

Daily DAX : Day 129 T.INV.2T

 The DAX function `T.INV.2T` calculates the two-tailed inverse of the Student's t-distribution. Let's break down what that means and its use cases: Understanding the T.INV.2T Function * Student's t-distribution : This distribution is used when dealing with small sample sizes where the population standard deviation is unknown.  It's similar to the normal distribution but has heavier tails, reflecting the increased uncertainty due to the smaller sample size. * Two-tailed :  In a two-tailed test, you're looking for differences in *either* direction (greater than or less than).  Think of it like testing if a new drug has *any* effect, whether it's positive or negative.  `T.INV.2T` reflects this by calculating the critical t-value that separates the extreme 2.5% of the distribution in *both* tails (making a total of 5% combined, or whatever alpha you specify). * Inverse : The "inverse" part means you're providing the *probability* (alpha) and degrees ...

Daily DAX : Day 128 T.DIST.RT

 The T.DIST.RT function in Power BI DAX (Data Analysis Expressions) is used to calculate the right-tailed Student's t-distribution. Here's a breakdown of the function: Syntax dax T.DIST.RT(x, deg_freedom)     x: The numeric value at which to evaluate the distribution. This is the t-value in the context of statistical testing.     deg_freedom: The number of degrees of freedom, which should be a positive integer. Explanation:     Right-tailed: The function calculates the probability that a t-distributed random variable is greater than x, given the degrees of freedom. This is useful for one-tailed tests where you're interested in values in one direction (to the right of the mean in this case). Use Case:     Hypothesis Testing:          When performing t-tests for small samples where the population standard deviation is unknown, T.DIST.RT can be used to find the p-value for one-tailed tests. For example, if you're testing...

Daily DAX : Day 127 COLLAPSE

 The DAX function `COLLAPSE` in Power BI is used to aggregate data at a higher level than the detail data present in a table. It essentially "rolls up" the data based on the grouping columns you specify.  Think of it like the opposite of drilling down.  It's particularly useful when you're dealing with hierarchical data or when you need to perform calculations on aggregated values. Here's a breakdown: Syntax COLLAPSE(<table name>, <grouping column1>, <grouping column2>, ...) *   `<table name>`: The name of the table containing the data you want to collapse. *   `<grouping column1>, <grouping column2>, ...`: The columns by which you want to group the data.  These are the columns that define the higher level you're aggregating to. How it Works: `COLLAPSE` takes a table and aggregates the rows based on the specified grouping columns.  Any columns *not* specified as grouping columns are implicitly aggregated....

Daily DAX : Day 126 USERPRINCIPALNAME

 The USERPRINCIPALNAME function in Power BI's DAX (Data Analysis Expressions) language is used to return the user principal name of the current user accessing the report. Here's a breakdown: Function Syntax: USERPRINCIPALNAME() Explanation:     User Principal Name (UPN): This is essentially an Internet-style login name for the user based on the Internet standard RFC 822. It typically has the format username@domain.com. Main Use Cases:     Row-Level Security (RLS):         One of the primary uses of USERPRINCIPALNAME() is in implementing row-level security within Power BI. You can use this function to dynamically filter data based on who is viewing the report. For instance, you might restrict access so that users only see data pertinent to themselves or their specific department by comparing the UPN with a column in your data model.     Example:     DAX     SecurityFilter =      'User'[UserPrincipal...

Daily DAX : Day 125 BETA.INV

 The BETA.INV function in Power BI's Data Analysis Expressions (DAX) is used to calculate the inverse of the beta cumulative distribution function for a set of parameters. Here's a detailed breakdown: Syntax: DAX BETA.INV(probability, alpha, beta [, A] [, B])     probability: The probability associated with the beta distribution. Must be between 0 and 1.     alpha: A parameter of the distribution. Must be positive.     beta: Another parameter of the distribution. Must be positive.     A (optional): The lower bound of the interval over which the beta distribution is defined. Defaults to 0.     B (optional): The upper bound of the interval. Defaults to 1. Function Explanation:     The BETA.INV function returns the value of x such that the cumulative distribution function (CDF) for the beta distribution, with parameters alpha and beta, equals the specified probability.      If A and B are not provided, it assum...

Daily DAX : Day 124 ALL

  Power BI DAX Function: ALL Function Description: The ALL function in Data Analysis Expressions (DAX) for Power BI is used to remove filters from one or more columns or tables. It essentially returns all the rows in a table, ignoring any filters that might be applied at the time. Here's how it works: Syntax : ALL([TableNameOrColumn], [ColumnName1], [ColumnName2], ...) If you specify a table, ALL returns all rows from that table. If you specify column names, it returns all unique values from those columns, regardless of any filter context in effect. Parameters: TableNameOrColumn : Can be a table or a column from which you want to remove filters. ColumnName : Optional, you can specify multiple columns if you're removing filters from specific columns within a table. Key Points: ALL can be used with tables, columns, or both within the same function call. When used with tables, it removes all filters on that table. When used with columns, it removes filters only on those spec...

Daily DAX : Day 123 EOMONTH

  EOMONTH (End of Month) Function in Power BI DAX : Function Syntax: EOMONTH(<start_date>, <months>) <start_date> : This is the date from which you want to calculate the end of the month. It can be a date value, a column reference, or any expression that results in a date. <months> : An integer that specifies how many months before or after the start_date you want to find the end of the month. A positive number moves forward in time, while a negative number moves backward. How it Works: The EOMONTH function returns the last day of the month that is the specified number of months away from the start_date . If you specify 0 for months , it simply returns the last day of the month of the start_date . Main Use Cases: Financial Reporting : Closing Dates : Often, financial periods close at the end of the month. EOMONTH can be used to automatically calculate the closing date for any given month in financial reports or dashboards. Example: EOMONTH([TransactionDa...