Posts

Showing posts with the label dax function

Step-by-Step Guide to Using TOPN in Power BI for Dynamic Data Analysis

  DAX Function: TOPN with CALCULATE The TOPN function is one of the most powerful DAX functions for ranking and filtering data in Power BI. Combined with CALCULATE, it can be used to create dynamic, insightful measures. Below is an example of how to use TOPN with CALCULATE to find the top N items based on a certain criterion. Scenario Suppose you have a sales dataset and you want to calculate the total sales of the top 5 products by revenue. This measure will dynamically adjust based on any filters applied in your report (e.g., date, region, etc.). Function Syntax TOPN(<N_value>, <Table>, <OrderBy_Expression>[, <Order>[, <OrderBy_Expression> [, <Order>]]…]) <N_value>: The number of top rows to return. <Table>: The table to evaluate. <OrderBy_Expression>: The expression to order by. <Order>: Optional. Specifies the order direction (ASC for ascending, DESC for descending). Default...

Calculate Sales for Last Year Month to date

Sameperiodlastyear till to date based on selection in year and month selection Problem:  If the current year and month are selected, sales data from the same period of the previous year up to the current date is needed. For instance, if it's March 2024, you'd require sales data from March 2023 up to today's date. If the selection is for a different year and month, such as January 2023, you need the entire sales data for January 2022. Solution:  For this scenario you need to create Three Dax Measures Measure 1 = (This measure is to calculate current month sales till the date) CALCULATE( SUM(CST[Total Financed Amount]), SAMEPERIODLASTYEAR( DATESYTD('Calendar Table'[Date]) ), FILTER( ALL('Calendar Table'), 'Calendar Table'[MonthNum] = MONTH(NOW()) && DAY('Calendar Table'[Date]) <= DAY(NOW()) ) ) Explanation: CALCULATE : This is a DAX function used to modify or filter the context for a calculation. It can apply additional filters to a ...

Create Calendar Table in Power BI using DAX Function

 Calendar Table using Dax Syntax: CalendarTable = ADDCOLUMNS ( CALENDAR (DATE(2024, 1, 1), DATE(2024, 12, 31)), "Year", YEAR([Date]), "MonthNumber", MONTH([Date]), "MonthName", FORMAT([Date], "MMMM"), "Quarter", QUARTER([Date]), "DayOfWeek", WEEKDAY([Date]), "DayOfMonth", DAY([Date]), "WeekdayName", FORMAT([Date], "dddd"), "IsWeekend", IF( OR(WEEKDAY([Date]) = 1, WEEKDAY([Date]) = 7), TRUE(), FALSE()), "IsHoliday", IF( OR( MONTH([Date]) = 1 && DAY([Date]) = 1, MONTH([Date]) = 7 && DAY([Date]) = 4), TRUE(), FALSE()) ) Explanation: CALENDAR (DATE(2024, 1, 1), DATE(2024, 12, 31)) Creates a table with a single column containing dates from January 1, 2024, to December 31, 2024. ADDCOLUMNS ( Adds new columns to the table created by the CALENDAR function. "Year", YEAR([Date]), Adds a column named "Year" that...