Posts

Showing posts with the label DAX

Filtering rows if the text (string) match in Dax

 In Power BI, you can filter rows in a table or dataset using Data Analysis Expressions (DAX) by creating measures or calculated columns that use the `FILTER` function to specify a condition for filtering rows based on a text (string) match. Here's a basic example of how to filter rows in DAX when the text in a specific column matches a certain string: Assuming you have a table named "YourTable" with a column named "YourColumn" that contains text: ```dax FilteredTable = FILTER (     YourTable,     YourTable[YourColumn] = "YourTargetText" ) ``` In this DAX code: - `YourTable` is the name of your table. - `YourColumn` is the name of the column that you want to match against the text. - `"YourTargetText"` is the text you want to match. The `FILTER` function returns a table that includes only the rows where the condition (`YourTable[YourColumn] = "YourTargetText"`) is met. You can create a new measure or calculated column with this DAX

Ranking DAX measures

 In Power BI, you can rank DAX measures using functions like `RANKX()` or `TOPN()`. Here's how you can rank DAX measures: 1. **RANKX() Function:**    The `RANKX()` function is commonly used to rank items based on a measure. It assigns a rank to each item based on the measure's value. Here's a basic example:    ```DAX    Rank Measure = RANKX(ALL('YourTable'), [YourMeasure], , DESC)    ```    - `ALL('YourTable')` ensures that the ranking considers all items in the table.    - `[YourMeasure]` is the measure you want to rank by.    - The third argument can be used for grouping or categorization.    - `DESC` specifies the ranking order (descending). You can use `ASC` for ascending. 2. **TOPN() Function:**    The `TOPN()` function is used to get the top N items based on a measure. It effectively ranks items and then filters based on the rank. Here's an example:    ```DAX    Top 10 Items = TOPN(10, FILTER(ALL('YourTable'), [YourMeasure] > 0), [YourMe