All Dax Function Definition With Examples: 1. Aggregation Functions
All Dax Function Definition With Examples: 1. Aggregation Functions
Datasets:- https://www.kaggle.com/datasets/apoorvaappz/global-super-store-dataset
1. Aggregation Functions
(i) AVERAGE:- The AVERAGE function calculates the arithmetic mean (average) of a
column that contains numeric values. Non-numeric values like text or blanks are
ignored.
Syntax: AVERAGE(<Column>)
Example:-
➢ Avg_Sales= AVERAGE(Global_Superstore2[Sales])
➢ Avg_Discount = AVERAGE(Global_Superstore2[Discount])
➢ Avg_Progit_Margin = AVERAGE(Global_Superstore2[Profit])
➢ Avg_Qty_Sold = AVERAGE(Global_Superstore2[Quantity])
➢ Avg_Shipp_Cost = AVERAGE(Global_Superstore2[Shipping Cost])
(ii). AVERAGEA:- The AVERAGEA function calculates the arithmetic mean (average) of a
column but considers non-numeric values differently:
Syntax: AVERAGEA(<Column>)
Example:-
Goutam Kuiri
(iii) AVERAGEX:- The AVERAGEX function calculates the arithmetic mean of an expression
evaluated for each row in a table.
➢ AverageProfitPerCategory=
AVERAGEX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Category],"Total_Profit
",SUM(Global_Superstore2[Profit])),SUM(Global_Superstore2[Profit]))
➢ Average(x)_Sales_Per_Region =
AVERAGEX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Region],"Total_Sales",
SUM(Global_Superstore2[Sales])),SUM(Global_Superstore2[Sales]))
➢ AverageDiscountPerOrder(X) =
AVERAGEX(Global_Superstore2,Global_Superstore2[Discount]*Global_Superstore2[Qua
ntity])
➢ AverageShippingDays(X) =
AVERAGEX(Global_Superstore2,DATEDIFF(Global_Superstore2[Order
Date],Global_Superstore2[Ship Date],DAY))
➢ AverageTop10CustomerSales(X) =
AVERAGEX(TOPN(10,Global_Superstore2,Global_Superstore2[Sales],DESC),Global_Super
store2[Sales])
Syntax: COUNT(<column>)
➢ HighDiscountOrders(countax) =
COUNTAX(Global_Superstore2,IF(Global_Superstore2[Discount]>0.1,1,BLANK()))
➢ LargeOrderCount(Countax) =
COUNTAX(Global_Superstore2,IF(Global_Superstore2[Quantity]>10,1,BLANK()))
➢ OrdersWithProfit(Countax) =
COUNTAX(Global_Superstore2,IF(Global_Superstore2[Profit]>0,1,BLANK()))
➢ ZeroProfitOrders(countax) =
COUNTAX(Global_Superstore2,IF(Global_Superstore2[Profit]=0,1,BLANK()))
(vi) COUNTBLANK :- A DAX function that counts the number of blank or empty values in a
specified column.
Syntax: COUNTBLANK(<column>)
(vii) COUNTROWS :- A DAX function that counts the total number of rows in a table or a table
expression.
Syntax: COUNTROWS(<table>)
➢ TotalRows(CR) = COUNTROWS(Global_Superstore2)
➢ ProductCategoriesCount(CR) = COUNTROWS(VALUES(Global_Superstore2[Category]))
➢ ShippingModesCount(CR) = COUNTROWS(VALUES(Global_Superstore2[Ship Mode]))
➢ SubcategoriesCount(CR) = COUNTROWS(VALUES(Global_Superstore2[Sub-Category]))
➢ UniqueRegion(CR) = COUNTROWS(VALUES(Global_Superstore2[Region]))
(viii) DISTINCTCOUNT:- A DAX function that counts the number of unique (distinct) values in a
column.
Syntax: DISTINCTCOUNT(<column>)
(ix) MAX:- A DAX function that returns the largest value in a column.
Syntax: MAX(<column>)
➢ MaxSales(M) = MAX(Global_Superstore2[Sales])
➢ MaxProfit(M) = MAX(Global_Superstore2[Profit])
➢ MaxDiscount(M) = MAX(Global_Superstore2[Discount])
➢ MaxShippingCost(M) = MAX(Global_Superstore2[Shipping Cost])
➢ MaxQuantityOrdered(M) = MAX(Global_Superstore2[Quantity])
(x) MAXX:- A DAX function that evaluates an expression for each row of a table and returns
the largest value resulting from those calculations.
➢ MaxDiscountByProduct(MX) =
MAXX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Product
ID],"ProductDiscount",SUM(Global_Superstore2[Discount])),[ProductDiscount])
➢ MaxSalesPerCustomer(MX) =
MAXX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Customer
Name],"CustomerSales",SUM(Global_Superstore2[Sales])),[CustomerSales])
➢ MaxProfitByRegion(MX) =
MAXX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Region],"RegionProfit",SUM(Glo
bal_Superstore2[Profit])),[RegionProfit])
➢ MaxQuantityByProduct(MX) =
MAXX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Product
ID],"ProductQuantity",SUM(Global_Superstore2[Quantity])),[ProductQuantity])
➢ MaxShippingCostPerOrder(MX) =
MAXX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Order
ID],"OrderShippingCost",SUM(Global_Superstore2[Shipping Cost])),[OrderShippingCost])
Syntax: MIN(<column>)
➢ MinSales(Min) = MIN(Global_Superstore2[Sales])
➢ MinShippingCost(Min) = MIN(Global_Superstore2[Shipping Cost])
➢ MinQuantity(Min) = MIN(Global_Superstore2[Quantity])
➢ MinProfit(Min) = MIN(Global_Superstore2[Profit])
➢ MinDiscount(Min) = MIN(Global_Superstore2[Discount])
(Xii) MINX:- MINX evaluates an expression for each row of a table and returns the smallest value.
➢ MinSalesPerCustomer(MinX) =
MINX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Customer
Name],"CustomerSales",sum(Global_Superstore2[Sales])),[CustomerSales])
➢ MinShippingCostPerOrder(MinX) =
MINX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Order
ID],"OrderShippingCost",SUM(Global_Superstore2[Shipping Cost])),[OrderShippingCost])
➢ MinQuantityByProduct(MinX) =
MINX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Product
ID],"ProductQuantity",SUM(Global_Superstore2[Quantity])),[ProductQuantity])
➢ MinProfitByRegion(Minx) =
MINX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Region],"RegionProfit",SUM(Glob
al_Superstore2[Profit])),[RegionProfit])
➢ MinDiscountByProduct(MinX) =
MINX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Product
ID],"ProductDiscount",SUM(Global_Superstore2[Discount])),[ProductDiscount])
(Xiii) SUM:- SUM returns the total (sum) of all numeric values in a column.
Syntax: SUM(<column>)
➢ TotalSales(S) = SUM(Global_Superstore2[Sales])
➢ TotalShippingCosts(S) = SUM(Global_Superstore2[Shipping Cost])
➢ TotalQuantity(S) = SUM(Global_Superstore2[Quantity])
➢ TotalProfit(S) = SUM(Global_Superstore2[Profit])
➢ TotalDiscount(S) = SUM(Global_Superstore2[Discount])
(Xiv)SUMX:- SUMX evaluates an expression for each row in a table and returns the sum of the
resulting values.
➢ TotalSalesPerCustomer(SumX) =
SUMX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Customer
Name],"CustomerSales",SUM(Global_Superstore2[Sales])),[CustomerSales])
➢ TotalShippingCostPerOrder(SumX) =
SUMX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Order
ID],"OrderShippingCost",SUM(Global_Superstore2[Shipping Cost])),[OrderShippingCost])
➢ TotalQuantityByCategory(SumX) =
SUMX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Category],"CategoryQuantity",S
UM(Global_Superstore2[Quantity])),[CategoryQuantity])
➢ TotalProfitByRegion(SumX) =
SUMX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Region],"RegionP
rofit",SUM(Global_Superstore2[Profit])),[RegionProfit])
➢ TotalDiscountByProduct(SumX) =
SUMX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Product
ID],"ProductDiscount",SUM(Global_Superstore2[Discount])),[ProductDiscount])
(XV) PRODUCT :- PRODUCT calculates the product of all non-blank numeric values in a column.
Syntax: PRODUCT(<column>)
Use Case
Use PRODUCT when you need to calculate a multiplicative total of a single column's values,
such as finding the compounded growth rate or multiplicative factors across multiple items.
Represents Cumulative Multiplication
If you calculate the compounded growth rate, each year’s growth factor multiplies with the
next:
Cumulative Growth=1.05×1.10×1.08=1.2474
➢ ProductSales(Prod) = PRODUCT(Global_Superstore2[Sales])
➢ ProductOfQuantities(Prod) = PRODUCT(Global_Superstore2[Quantity])
➢ ProductOfDiscounts(Prod) = PRODUCT(Global_Superstore2[Discount])
➢ ProductOfProfitsByCustomer(ProdX) =
PRODUCTX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Customer
Name],"CustomerProfit",SUM(Global_Superstore2[Profit])),[CustomerProfit])
➢ CompoundedDiscountByProduct(ProdX) =
PRODUCTX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Product
ID],"ProductDiscount",SUM(Global_Superstore2[Discount])),[ProductDiscount])
➢
➢ CumulativeShippingCostPerOrder(ProdX) =
PRODUCTX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Order
ID],"OrderShippingCost",SUM(Global_Superstore2[Shipping Cost])),[OrderShippingCost])
➢ ProductOfQuantitiesByCategory(ProdX) =
PRODUCTX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Category],"CategoryQuanti
ty",SUM(Global_Superstore2[Quantity])),[CategoryQuantity])
➢ ProductofSalesByRegion(ProdX) =
PRODUCTX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Region],"RegionSales",SUM
(Global_Superstore2[Sales])),[RegionSales])
Why Use PRODUCT or PRODUCTX for Cumulative Calculations?
•Handles scenarios where cumulative multiplication is necessary across rows or columns.
•PRODUCT simplifies operations on a single column.
•PRODUCTX provides flexibility to include complex row-wise expressions.
These functions are essential for tasks like financial modeling, production analysis, or any
cumulative scaling calculations.
(XVII) MEDIAN:- MEDIAN calculates the middle value of a numeric column. If the column has
an even number of values, it returns the average of the two middle values.
Syntax: MEDIAN(<column>)
➢ MedianSales(Median) = MEDIAN(Global_Superstore2[Sales])
➢ MedianShippingCost(Median) = MEDIAN(Global_Superstore2[Shipping Cost])
➢ MedianQuantity(Median) = MEDIAN(Global_Superstore2[Quantity])
➢ MedianProfit(Median) = MEDIAN(Global_Superstore2[Profit])
➢ MedianDiscount(Median) = MEDIAN(Global_Superstore2[Discount])
(XVIII) MEDIANX:- MEDIANX evaluates a custom expression for each row in a table and returns
the median of the calculated results.
Syntax: MEDIANX(<table>, <expression>)
➢ MedianSalesPerCustomer(MedX) =
MEDIANX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Customer
Name],"CustomerName",SUM(Global_Superstore2[Sales])),[CustomerName])
➢ MedianShippingCostPerOrder(MedX) = MEDIANX(SUMMARIZE(Global_Superstore2,
Global_Superstore2[Order ID],"OrderShippingCost",SUM(Global_Superstore2[Shipping
Cost])),[OrderShippingCost])
➢ MedianQuantityByCategory(MedX) =
MEDIANX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Category],"CategoryQuantit
y",SUM(Global_Superstore2[Quantity])),[CategoryQuantity])
➢ MedianProfitByRegion(MedX) =
MEDIANX(SUMMARIZE(Global_Superstore2,Global_Superstore2[Region],"RegionProfit",SUM
(Global_Superstore2[Sales])),[RegionProfit])
What is Standard Deviation?
Standard deviation (SD) tells us how spread out the values in a dataset are from the mean
(average). A smaller SD means the data points are closer to the mean, while a larger SD
means the data points are more spread out.
1. STDEV.S
Definition
STDEV.S calculates the standard deviation for a sample of data. It assumes the data is a
representative subset of a larger population.
Formula
The formula for sample standard deviation is:
Where:
•s: Sample standard deviation
•n: Number of observations
•Xi: Each individual value
•xˉ: Mean of the sample
Syntax: STDEV.S(<column>)
Example Example
Consider the following dataset:
SampleStdDev = STDEV.S(Sales[Revenue])
SalesID Revenue
1 500
2 600
3 700
4 800
The sample standard deviation (s) of the Revenue column is approximately 129.10.
Key Takeaway
A low standard deviation indicates consistency, while a high standard deviation suggests
variability. Use this to assess:
•Stability in sales, scores, or performance (e.g., business planning).
•Risk in investments (e.g., choosing steady vs. volatile stocks).
•Consistency in processes (e.g., manufacturing quality).
➢ STDDEVSales(STDEV.S) = STDEV.S(Global_Superstore2[Sales])
➢ STDDEVPROFIT(STDDEV.S) = STDEV.S(Global_Superstore2[Profit])
➢ STDDEVSHIPPINGCOST(STDDEV.S) = STDEV.S(Global_Superstore2[Shipping Cost])
➢ STDDEVDiscount(STDDEV.S) = STDEV.S(Global_Superstore2[Discount])
Meaning:
Calculates the variation or spread in sales amounts across transactions.
Business Implication:
A higher standard deviation indicates significant variability in sales values, suggesting that some
transactions are significantly larger or smaller than others. A lower value implies more
consistency.
2. STDEV.P
Definition
STDEV.P calculates the standard deviation for the entire population. It assumes the data
represents the full set of values.
Formula
The formula for population standard deviation is:
Syntax: STDEV.P(<column>)
➢ Sales(Stddev.P) = STDEV.P(Global_Superstore2[Sales])
➢ Quantity(STDDEV.P) = STDEV.P(Global_Superstore2[Quantity])
➢ Discount(STDDEV.P) = STDEV.P(Global_Superstore2[Discount])
➢ OrderYearDate(M Date) =
FORMAT(DATE(YEAR(Global_Superstore2[Order_Date].[Date]),1,1),"DD MMM YYYY")
➢ DefaultDate(M Date) =
IF(ISBLANK(Global_Superstore2[Order_Date].[Date]),DATE(2000,1,1),Global_Superstore2[Ord
er_Date])
➢ FiscalYearStart(M Date) =
FORMAT(DATE(YEAR(Global_Superstore2[Order_Date].[Date]),4,1),"DD MMM YYYY")
(ii) DATEDIFF:- The DATEDIFF function calculates the difference between two dates in specified
units such as days, months, quarters, or years. The syntax is:
➢ DaysToShip(DateDiff) =
DATEDIFF(Global_Superstore2[Order_Date].[Date],Global_Superstore2[Ship_Date].[Date],DAY
)
➢ MonthsSinceOrder(DateDiff) =
DATEDIFF(Global_Superstore2[Order_Date].[Date],TODAY(),MONTH)
(iii) DATEADD:- The DATEADD function shifts a date by a specified number of intervals (days,
months, quarters, or years) forward or backward in time. The syntax is:
➢ PreviousYearDate(DateADD) = DATEADD(Global_Superstore2[Order_Date].[Date],-1,YEAR)
➢ NextQuarterDate(DateADD) = DATEADD(Global_Superstore2[Order_Date],1,QUARTER)
➢ PreviousWeekDate = DATEADD(Global_Superstore2[Order_Date].[Date],-7,DAY)
➢ RollingSixMonth(DateADD) = DATEADD(Global_Superstore2[Order_Date].[Date],-
6,MONTH)
➢ NextMonthSameMonth(DateAdd) =
DATEADD(Global_Superstore2[Order_Date].[Date],12,MONTH)
(iv) DAY:- The DAY function extracts the day of the month (1–31) from a given date. The syntax
is:
Syntex:- DAY(<date>)
➢ OrderDay(Day) = DAY(Global_Superstore2[Order_Date].[Date])
➢ IsFirstOrLastDay(Day) =
IF(DAY(Global_Superstore2[Order_Date].[Date])=1||DAY(Global_Superstore2[Order_Date].
[Date])=DAY(EOMONTH(Global_Superstore2[Order_Date].[Date],0)),"Yes","No")
➢ Promotion_Flag(Day) = IF(DAY(Global_Superstore2[Order_Date].[Date])=15,"Special
Promo","No Promo")
(v) ENDOFMONTH:- The ENDOFMONTH function returns the last date of the month for a
specified date column. The syntax is:
Syntex:- ENDOFMONTH(<date_column>)
➢ LastSippingDate(EOM) = ENDOFMONTH(Global_Superstore2[Ship_Date].[Date])
➢ LastOrderDate(EOM) = ENDOFMONTH(Global_Superstore2[Order_Date].[Date])
➢ EOMonthSales(EOM) =
VAR LastDayMonth=ENDOFMONTH(Global_Superstore2[Order_Date].[Date])
RETURN
CALCULATE(
SUM(Global_Superstore2[Sales]),
Global_Superstore2[Order_Date]=LastDayMonth
)
➢ EOMProfitMargin(EOM) =
VAR LastOrderDate = ENDOFMONTH(Global_Superstore2[Order_Date].[Date])
RETURN
ROUNDUP(
DIVIDE(
CALCULATE(
SUM(Global_Superstore2[Profit]),
FILTER(Global_Superstore2, Global_Superstore2[Order_Date] = LastOrderDate)
),
CALCULATE(
SUM(Global_Superstore2[Sales]),
FILTER(Global_Superstore2, Global_Superstore2[Order_Date] = LastOrderDate)
)
),
2 -- Rounding up to two decimal places
)
(vi) ENDOFYEAR:-The ENDOFYEAR function returns the last date of the year for a specified
date column. The syntax is:
➢ LastOrderDate(EOY) = ENDOFYEAR(Global_Superstore2[Order_Date].[Date])
➢ YearEndSales(EOY) =
VAR LastDateOfYear = ENDOFYEAR(Global_Superstore2[Order_Date].[Date])
RETURN
ROUND(CALCULATE(
SUM(Global_Superstore2[Sales]),
FILTER(
Global_Superstore2,
Global_Superstore2[Order_Date]= LastDateOfYear
)
),2
)
➢ FiscalYearClosingDate(EOY) = ENDOFYEAR(Global_Superstore2[Order_Date].[Date],3)
➢ YearEndProfit(EOY) =
var Lastorderdate=ENDOFYEAR(Global_Superstore2[Order_Date].[Date])
Return
ROUND(CALCULATE(
SUM(Global_Superstore2[Profit]),
FILTER(Global_Superstore2,Global_Superstore2[Order_Date].[Date]=Lastorderdate
)
),2
)
(vii) FORMAT
The FORMAT function in DAX is used to convert a value into a string with a specified format.
Syntax
FORMAT(<value>, <format_string>)
<value>: The value to be formatted (can be a date, number, or currency).
<format_string>: A string that defines how the value should be displayed.
➢ FormattedDate(Format) =
FORMAT(Global_Superstore2[Order_Date].[Date],"MMM DD,YYYY")
➢ FormattedSales(Format) = FORMAT(Global_Superstore2[Sales],"#,##0")
➢ FormattedProfit(Format) =
FORMAT(Global_Superstore2[Profit],"₹#,##0.00")
Important Notes
1.FORMAT() returns a text value, so you cannot use it in calculations.
2.It is best used for display purposes in reports.
(viii) QUARTER
The QUARTER function in DAX returns the quarter number (1 to 4) for a given date.
Syntax
QUARTER(<date>)
➢ <date>: A column or expression containing a date.
OrderQuarter(Quarter) = "Q"&QUARTER(Global_Superstore2[Order_Date].[Date])
FinancialQuarter =
SWITCH(QUARTER(Global_Superstore2[Order_Date].[Date]),
1, 4, -- Jan-Mar → Q4
2, 1, -- Apr-Jun → Q1
3, 2, -- Jul-Sep → Q2
4, 3 -- Oct-Dec → Q3
)
Key Takeaways
QUARTER(date) returns 1, 2, 3, or 4 based on the date.
You can use SWITCH() to display formatted quarter names.
Use CALCULATE() to aggregate sales by quarter.
Adjust quarters for a Fiscal Year starting in April.
(ix) STARTOFMONTH
The STARTOFMONTH function is used to return the first date of the month for a given date
column or table. This is useful when working with monthly aggregations, time intelligence
calculations, or financial reports.
Syntax:- STARTOFMONTH(<dates>)
• <dates> → A column containing date values or a table with a date column.
• Returns: The first date of the month for each row in the column.
FirstDayOfMonth = STARTOFMONTH(Global_Superstore2[Order_Date].[Date])
MonthlySales(Som) =
CALCULATE(SUM(Global_Superstore2[Sales]),FILTER(Global_Superstore2,Globa
l_Superstore2[Order_Date].[Date]=STARTOFMONTH(Global_Superstore2[Order_D
ate].[Date])))
Key Takeaways
STARTOFMONTH(date_column) returns the first day of each month.
Useful for time-based calculations, such as monthly comparisons & aggregations.
Can be used in measures & calculated columns to filter data.
(x) STARTOFYEAR
The STARTOFYEAR function in DAX is used to return the first date of the year for a given date
column. It is commonly used in time intelligence calculations like Year-to-Date (YTD) analysis,
comparing current vs. previous year sales, and more.
FirstDayofYear = STARTOFYEAR(Global_Superstore2[Order_Date].[Date])
FirstDayofFiscalYear = STARTOFYEAR(Global_Superstore2[Order_Date].[Date],"3/31")
(xi) TODAY()
The TODAY() function in DAX returns the current system date without the time component.
Syntax:- Today()
➢ No parameters required.
➢ Returns a date value with only the current date (no time).
➢ The value updates automatically every day when the report refreshes.
CurrentDate = TODAY()
DaysSinceOrder = DATEDIFF(Global_Superstore2[Order_Date].[Date], TODAY(), DAY)
CurrentYearSales = CALCULATE(SUM(Global_Superstore2[Sales]),
YEAR(Global_Superstore2[Order_Date]) = YEAR(TODAY()))
Key Points
TODAY() returns the current system date (without time).
Updates automatically when the Power BI dataset refreshes.
Useful for calculating age, filtering data, and comparisons.
(xii) YEAR()
The YEAR() function in DAX extracts the year from a given date value.
Syntax:- YEAR(<date>)
• <date> → A column or expression containing a date value.
• Returns an integer representing the year of the given date.
• OrderYear = YEAR(Global_Superstore2[Order_Date].[Date])
• CurrentYearSales(Year) =
CALCULATE(
SUM(Global_Superstore2[Sales]),
FILTER(Global_Superstore2,
YEAR(Global_Superstore2[Order_Date]) =
YEAR(MAX(Global_Superstore2[Order_Date].[Date]))
)
)
• LastYearSales =
CALCULATE(
SUM(Global_Superstore2[Sales]),
FILTER(Global_Superstore2,
YEAR(Global_Superstore2[Order_Date].[Date]) =
YEAR(MAX(Global_Superstore2[Order_Date].[Date])) - 1)
)
• FinancialYear =
IF(
MONTH(Global_Superstore2[Order_Date].[Date]) >= 4,
YEAR(Global_Superstore2[Order_Date].[Date]),
YEAR(Global_Superstore2[Order_Date].[Date]) - 1
)
Key Points
YEAR() extracts the year from a date value.
Works well with filters, calculations, and comparisons.
Combine with TODAY() for dynamic time-based analysis.
(xiii) YEARFRAC
The YEARFRAC() function in DAX calculates the fractional year between two dates. It returns a
decimal number representing the total number of days between the two dates as a fraction of a
year.
Arguments:
•<start_date> → The beginning date.
•<end_date> → The ending date.
•<basis> (optional) → Determines how the year is calculated.
•If omitted, the default basis is 0 (360-day year).
Syntax:- SAMEPERIODLASTYEAR(<date_column>)
--> <date_column>: A column with date values.
--> Returns: A table containing dates from the same period in the previous year.
➢ Sales_LastYear(SPLY) =
CALCULATE(SUM(Global_Superstore2[Sales]),SAMEPERIODLASTYEAR(Global_Superstore2[Or
der_Date].[Date]))
➢ YOY_Sales_Growth(SPLY) =
var
lastyearsales=CALCULATE(SUM(Global_Superstore2[Sales]),SAMEPERIODLASTYEAR(Global_Su
perstore2[Order_Date].[Date]))
VAR currentYearSales=SUM(Global_Superstore2[Sales])
RETURN
IF(ISBLANK(lastyearsales),0,DIVIDE(currentYearSales-lastyearsales,lastyearsales,0))
➢ Order_LastYear(SPLY) = CALCULATE(COUNT(Global_Superstore2[Order
ID]),SAMEPERIODLASTYEAR(Global_Superstore2[Order_Date].[Date]))
➢ Profit_LastYear(SPLY) =
CALCULATE(SUM(Global_Superstore2[Sales]),SAMEPERIODLASTYEAR(Global_Superstore2[Or
der_Date].[Date]))
➢ Discount_LastYear(SPLY) =
CALCULATE(SUM(Global_Superstore2[Discount]),SAMEPERIODLASTYEAR(Global_Superstore2
[Order_Date].[Date]))
SAMEPERIODLASTYEAR helps compare sales, orders, profit, discounts, or any metric with the
same period last year.
(xv) TOTALYTD
The TOTALYTD function calculates the Year-to-Date (YTD) total of a given measure (e.g.,
Sales, Profit) based on a specified date column.
➢ Sales_YTD =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESYTD(Global_Superstore2[Order_D
ate].[Date]))
➢ Orders_YTD = TOTALYTD(COUNT(Global_Superstore2[Order
ID]),Global_Superstore2[Order_Date].[Date])
➢ Profit_YTD
=TOTALYTD(SUM(Global_Superstore2[Profit]),Global_Superstore2[Order_Date].[Date
])
➢ Discount_YTD =TOTALYTD(SUM(Global_Superstore2[Discount]),
Global_Superstore2[Order_Date].[Date])
➢ Sales_YTD_FirstClass =
TOTALYTD(CALCULATE(SUM(Global_Superstore2[Sales]),Global_Superstore2[Ship
Mode]="First Class"),Global_Superstore2[Order_Date].[Date])
❖ TOTALYTD calculates Year-to-Date totals for Sales, Profit, Orders, or any measure.
❖ Filters can be applied (e.g., for specific product categories).
(xvi) DATESBETWEEN
The DATESBETWEEN function returns a date range between a start date and an end date,
helping to filter calculations within a specific timeframe.
➢ Sales_Between_Dates(DateBetween) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESBETWEEN(Global_Superstore2[Order_D
ate].[Date],DATE(2012,01,01),DATE(2013,12,31)))
➢ Sales_Last_30_Days(DateBetween) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESBETWEEN(Global_Superstore2[Order_D
ate].[Date],MAX(Global_Superstore2[Order_Date])-
30,MAX(Global_Superstore2[Order_Date])))
➢ Sales_Last_Month(DateBetween) =
VAR LastMonthStart=EOMONTH(MAX(Global_Superstore2[Order_Date].[Date]),-1)+1
VAR LastMonthEnd= EOMONTH(MAX(Global_Superstore2[Order_Date].[Date]),0)
RETURN
CALCULATE(SUM(Global_Superstore2[Sales]),DATESBETWEEN(Global_Superstore2[Order_Date]
.[Date],LastMonthStart,LastMonthEnd))
➢ Sales_NatCarroll_Q4_2014(DateBetween) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESBETWEEN(Global_Superstore2[Order_D
ate].[Date],date(2014,10,1),date(2014,12,31)),Global_Superstore2[Customer Name]="Nat
Carroll")
➢ Orders_Q2_2014(DatesBetween) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESBETWEEN(Global_Superstore2[Order_D
ate].[Date],DATE(2014,4,1),DATE(2014,6,30)))
➢ Sales_Last_7_Days(DATESINPERIOD) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESINPERIOD(Global_Superstore2[Order_Da
te].[Date],MAX(Global_Superstore2[Order_Date]),-7,DAY))
➢ Sales_Last_Quarter(DATESINPERIOD) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESINPERIOD(Global_Superstore2[Order_Da
te].[Date],MAX(Global_Superstore2[Order_Date]),-1,QUARTER))
➢ Profit_Last_3_Months(DATESINPERIOD) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESINPERIOD(Global_Superstore2[Order_Da
te].[Date],MAX(Global_Superstore2[Order_Date]),-3,MONTH))
➢ Orders_Last_Year(DATESINPERIOD) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESINPERIOD(Global_Superstore2[Order_Da
te].[Date],MAX(Global_Superstore2[Order_Date]),-1,YEAR))
➢ Future_Sales_3_Months(DATESINPERIOD) =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESINPERIOD(Global_Superstore2[Order_Da
te].[Date],MAX(Global_Superstore2[Order_Date]),3,MONTH))
Syntax:- DATESMTD(<date_column>)
➢ Sales_MTD =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESMTD(Global_Superstore2[Order_Da
te].[Date]))
➢ Profit_MTD =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESMTD(Global_Superstore2[Order_Da
te].[Date]))
➢ Orders_MTD = CALCULATE(COUNT(Global_Superstore2[Order
ID]),DATESMTD(Global_Superstore2[Order_Date].[Date]))
➢ Sales_MTD_2012 =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESMTD(Global_Superstore2[Order_Da
te].[Date]),YEAR(Global_Superstore2[Order_Date])=2012)
Syntax:- DATESMTD(<date_column>)
➢ Sales_MTD =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESMTD(Global_Superstore2[Order_Date].[
Date]))
➢ Profit_MTD =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESMTD(Global_Superstore2[Order_Date].[
Date]))
➢ Orders_MTD = CALCULATE(COUNT(Global_Superstore2[Order
ID]),DATESMTD(Global_Superstore2[Order_Date].[Date]))
➢ Sales_MTD_2012 =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESMTD(Global_Superstore2[Order_Date].[
Date]),YEAR(Global_Superstore2[Order_Date])=2012)
(xix) DATESQTD
The DATESQTD function returns a set of dates from the beginning of the current quarter to the
latest available date in that quarter. It is commonly used to calculate Quarter-to-Date (QTD)
metrics, such as QTD Sales, QTD Profit, and QTD Orders.
Syntax:- DATESQTD(<date_column>)
➢ Profit_QTD =
CALCULATE(SUM(Global_Superstore2[Profit]),DATESQTD(Global_Superstore2[Order_Date].[
Date]))
➢ Sales_QTD =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESQTD(Global_Superstore2[Order_Date].[
Date]))
➢ Sales_QTD_2013 =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESQTD(Global_Superstore2[Order_Date].[
Date]),YEAR(Global_Superstore2[Order_Date])=2013)
(XX) DATESYTD
The DATESYTD function returns a set of dates from the beginning of the year to the latest
available date within the same year. It is used to calculate Year-to-Date (YTD) metrics, such as
YTD Sales, YTD Profit, and YTD Orders.
Syntax:- DATESYTD(<date_column>)
• <date_column>: A column containing date values.
➢ Orderss_YTD=CALCULATE(COUNT(Global_Superstore2[OrderID]),DATESYTD(Global_Supersto
re2[Order_Date].[Date]))
➢ Profits_YTD =
CALCULATE(SUM(Global_Superstore2[Profit]),DATESYTD(Global_Superstore2[Order_Date].[
Date]))
➢ Sales_YTD_2013 =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESYTD(Global_Superstore2[Order_Date]),Y
EAR(Global_Superstore2[Order_Date]) = 2013)
➢ Saless_YTD =
CALCULATE(SUM(Global_Superstore2[Sales]),DATESYTD(Global_Superstore2[Order_Date].[D
ate]))
(xxi) PREVIOUSMONTH
The PREVIOUSMONTH function returns a table of dates from the previous month, based on a
given date column. It is used to compare sales, profit, or other metrics from last month.
Syntax: PREVIOUSMONTH(<date_column>)
<date_column>: A column containing date values.
➢ Orders_PreviousMOnth = CALCULATE(count(Global_Superstore2[Order
ID]),PREVIOUSMONTH(Global_Superstore2[Order_Date].[Date]))
➢ Profit_PreviousMonth =
CALCULATE(SUM(Global_Superstore2[Profit]),PREVIOUSMONTH(Global_Superstore2[Orde
r_Date].[Date]))
➢ Sales_Growth_LastMonth =
VAR Sales_Current = SUM(Global_Superstore2[Sales])
VAR Sales_Previous =
CALCULATE(
SUM(Global_Superstore2[Sales]),
PREVIOUSMONTH(Global_Superstore2[Order_Date])
)
RETURN
I F(
NOT(ISBLANK(Sales_Previous)),
DIVIDE(Sales_Current - Sales_Previous, Sales_Previous, 0)
)
➢ Sales_PreviousMonth =
CALCULATE(SUM(Global_Superstore2[Sales]),PREVIOUSMONTH(Global_Superstore2[Orde
r_Date].[Date]))
Syntax: NEXTMONTH(<date_column>)
<date_column>: A column containing date values.
➢ Sales_NextMonth =
CALCULATE(SUM(Global_Superstore2[Sales]),NEXTMONTH(Global_Superstore2[Order_Da
te].[Date]))
➢ Order_NextMonth = CALCULATE(COUNT(Global_Superstore2[Order
ID]),NEXTMONTH(Global_Superstore2[Order_Date].[Date]))
➢ Profit_NextMonth =
CALCULATE(SUM(Global_Superstore2[Profit]),NEXTMONTH(Global_Superstore2[Order_Da
te].[Date]))
➢ Sales_Growth_NextMonth =
VAR Sales_Current=SUM(Global_Superstore2[Sales])
VAR
Sales_NextMonth=CALCULATE(SUM(Global_Superstore2[Sales]),NEXTMONTH(Global_Supers
tore2[Order_Date].[Date]))
RETURN
IF(Sales_NextMonth=0,0,(Sales_NextMonth-Sales_Current)/Sales_Current)
➢ Sales_PreviousMonth(PARALLELPERIOD) =
CALCULATE(SUM(Global_Superstore2[Sales]),PARALLELPERIOD(Global_Superstore2[Orde
r_Date].[Date],-1,MONTH))
➢ Profit_PreviousMonth(ParallelPeriod) =
CALCULATE(SUM(Global_Superstore2[Profit]),PARALLELPERIOD(Global_Superstore2[Ord
er_Date].[Date],-1,MONTH))
➢ Orders_LastYearSameMonth(ParallelPeriod) =
CALCULATE(COUNT(Global_Superstore2[Order
ID]),PARALLELPERIOD(Global_Superstore2[Order_Date].[Date],-1,YEAR))
➢ Sales_Growth_LastYear(PrallelPeriod) =
VAR Sales_Crrent=SUM(Global_Superstore2[Sales])
VAR
Sales_LastYear=CALCULATE(SUM(Global_Superstore2[Sales]),PARALLELPERIOD(Global_Supe
rstore2[Order_Date].[Date],-1,YEAR))
RETURN
IF(Sales_LastYear=0,0,(Sales_Crrent-Sales_LastYear)/Sales_LastYear)
Syntax: FIRSTDATE(<date_column>)
<date_column> – A column containing date values.
➢ First_Order_Date(FirstDate) = FIRSTDATE(Global_Superstore2[Order_Date].[Date])
➢ Product_First_Sales(FirstDate) =
CALCULATE(FIRSTDATE(Global_Superstore2[Order_Date].[Date]),ALLEXCEPT(Global_Superst
ore2,Global_Superstore2[Product ID]))
➢ Customer_FirstOrder(FirstDate) =
CALCULATE(FIRSTDATE(Global_Superstore2[Order_Date].[Date]),ALLEXCEPT(Global_Superst
ore2,Global_Superstore2[Customer ID]))
➢ Categort_First_Sales(FirstDate) =
CALCULATE(FIRSTDATE(Global_Superstore2[Order_Date].[Date]),ALLEXCEPT(Global_Superst
ore2,Global_Superstore2[Category]))
(XXV) LASTDATE
The LASTDATE function returns the most recent date in a column or within a given filter
context. It is useful for identifying the latest order date, last purchase per customer, or the last
recorded date for any analysis.
Syntax: LASTDATE(<date_column>)
<date_column> – A column containing date values.
➢ Last_Order_Date(LASTDATE) = LASTDATE(Global_Superstore2[Order_Date].[Date])
➢ Product_Last_Sale(LASTDATE) =
CALCULATE(
LASTDATE(Global_Superstore2[Order_Date].[Date]),
ALLEXCEPT(Global_Superstore2, Global_Superstore2[Product ID]))
➢ Customer_LastOrder(LastDate) =
CALCULATE(LASTDATE(Global_Superstore2[Order_Date].[Date]),ALLEXCEPT(Global_Super
store2,Global_Superstore2[Customer ID]))
(XXVi) LASTNONBLANK
The LASTNONBLANK function returns the last (most recent) non-blank value in a column,
based on a given expression. This is useful when analyzing sales trends, last recorded data,
or finding the last available entry before a missing value.
➢ Last_Sales_Date(LASTNONBLANK) =
LASTNONBLANK(Global_Superstore2[Order_Date].[Date],SUM(Global_Superstore2[Sales]
))
➢ Customer_LastOrder(LASTNONBLANK) =
CALCULATE(LASTNONBLANK(Global_Superstore2[Order_Date].[Date],SUM(Global_Supers
tore2[Sales])),ALLEXCEPT(Global_Superstore2,Global_Superstore2[Customer ID]))
➢ Product_Last_Sales(LASTNONBLANK) =
CALCULATE(LASTNONBLANK(Global_Superstore2[Order_Date].[Date],SUM(Global_Supers
tore2[Sales])),ALLEXCEPT(Global_Superstore2,Global_Superstore2[Product ID]))
➢ Total_Sales_All =
CALCULATE(SUM(Global_Superstore2[Sales]),ALL(Global_Superstore2))
➢ Total_Sales_All_Categories(All) =
CALCULATE(SUM(Global_Superstore2[Sales]),ALL(Global_Superstore2[Category]))
➢ Total_Sales_All_Region(All) =
CALCULATE(SUM(Global_Superstore2[Sales]),all(Global_Superstore2[Region]))
➢ Total_Orders_All_Customers(All) =
CALCULATE(SUM(Global_Superstore2[Sales]),all(Global_Superstore2[Customer ID]))
➢ Sales_Percentage_Region(All) =
DIVIDE(SUM(Global_Superstore2[Sales]),CALCULATE(SUM(Global_Superstore2[Sales
]),ALL(Global_Superstore2[Region])))*100
➢ Average_Sales_Per_Order_All =
CALCULATE(
AVERAGE(Global_Superstore2[Sales]),
ALL(Global_Superstore2))
Summary
•ALL removes filters from a table or column.
•Useful for calculating totals, percentages, and ignoring slicers.
•Works with SUM, AVERAGE, COUNT, and other aggregate functions.
(II) ALLSELECTED
The ALLSELECTED function removes filters except those applied in the visual or report-
level filters. It is useful when you want to calculate totals while respecting filters applied
in slicers.
Syntax: ALLSELECTED(<table_or_column>)
<table_or_column> – The table or column where filters should be kept from the
report.
➢ Total_Sales_Selected(AllSelected) =
CALCULATE(
SUM(Global_Superstore2[Sales]),
ALLSELECTED(Global_Superstore2)
)
➢ Total_Sales_Region_Selected(ALLSELECTED) =
CALCULATE(
SUM(Global_Superstore2[Sales]),
ALLSELECTED(Global_Superstore2[Region])
)
➢ Total_Orders_Selected_Customers(ALLSELECTED) =
CALCULATE(
COUNT(Global_Superstore2[Order ID]),
ALLSELECTED(Global_Superstore2[Customer ID])
)
➢ Sales_Percentage_Category_Selected(ALLSELECTED) =
DIVIDE(
SUM(Global_Superstore2[Sales]),
CALCULATE(SUM(Global_Superstore2[Sales]),
ALLSELECTED(Global_Superstore2[Category]))
) * 100
ALLSELECTED Ekdum Real-Life Example
(III) ALLEXCEPT
The ALLEXCEPT function removes all filters from a table except for the specified column(s).
It is useful when you want to calculate totals while keeping certain filters applied.
(ALLEXCEPT ek DAX function hai jo table ke sabhi filters ko hata deta hai, sirf un columns
ke filter ko rakh ke jo hum specify karte hain. Matlab, ye ALL function jaisa kaam karta hai,
lekin ek ya zyada columns ke filter ko preserve karta hai.)
➢ Total_Sales_Except_Category(AllExcept) =
CALCULATE(SUM(Global_Superstore2[Sales]),ALLEXCEPT(Global_Superstore2,Global_Su
perstore2[Category]))
➢ Total_Sales_Except_Region_SubCategory(Allexcept) =
CALCULATE(SUM(Global_Superstore2[Sales]),ALLEXCEPT(Global_Superstore2,Global_Su
perstore2[Region],Global_Superstore2[Sub-Category]))
➢ Total_Profit_Except_OrderDate(AllExcept) =
CALCULATE(
SUM(Global_Superstore2[Profit]),
ALLEXCEPT(Global_Superstore2, Global_Superstore2[Order_Date].[Date]))
➢ Total_Orders_Except_Segment(AllExcept) =
CALCULATE(count(Global_Superstore2[Order
ID]),ALLEXCEPT(Global_Superstore2,Global_Superstore2[Segment]))
➢ Average_Discount_Except_Product(AllExcept) =
CALCULATE(
AVERAGE(Global_Superstore2[Discount]),
ALLEXCEPT(Global_Superstore2, Global_Superstore2[Product Name])
)
•ALLEXCEPT removes all filters except for the columns you specify.
•Works well with SUM, AVERAGE, COUNT, and percentage calculations.
•Ensures only selected columns retain filtering in reports.
(iV) REMOVEFILTERS
The REMOVEFILTERS function removes all filters from a table or a column. It is useful when you
want to calculate values without being affected by filters applied in a report.
(REMOVEFILTERS() ek DAX function hai jo kisi table ya column se saare filters hata deta hai. Yeh
mostly tab use hota hai jab hume poore dataset ka aggregate result dikhana ho bina kisi filter
ke. )
➢ Total_Sales_Without_Filters(REMOVEFILTERS) =
CALCULATE(
SUM(Global_Superstore2[Sales]),
REMOVEFILTERS(Global_Superstore2))
➢ Total_Profit_Without_Category_Filter(REMOVEFILTERS) =
CALCULATE(
SUM(Global_Superstore2[Profit]),
REMOVEFILTERS(Global_Superstore2[Category]))
➢ Total_Orders_Without_Region_Filter(REMOVEFILTERS) =
CALCULATE(
COUNT(Global_Superstore2[Order ID]),
REMOVEFILTERS(Global_Superstore2[Region]))
➢ Average_Discount_Without_Segment(REMOVEFILTERS) =
CALCULATE(
AVERAGE(Global_Superstore2[Discount]),
REMOVEFILTERS(Global_Superstore2[Segment]))
•REMOVEFILTERS removes filters from an entire table or specific columns.
•Ignores slicers, filters, or selections in a report.
•Works well with SUM, COUNT, AVERAGE calculations.
(V) SELECTEDVALUE
The SELECTEDVALUE function returns the value of a column when only one value is selected. If
multiple values are selected, it returns the alternate result (optional) or BLANK() by default.
(SELECTEDVALUE() ek DAX function hai jo ek column se single selected value return karta hai.
Agar ek se zyada values select hoti hain, toh yeh blank ya default value return karta hai.)
❑ Selected_Category(SelectedValue) =
SELECTEDVALUE(Global_Superstore2[Category], "All Categories")
❑ Selected_Region(SelectedValue) = SELECTEDVALUE(Global_Superstore2[Region],"Multiple
Regions Selected")
❑ Selected_Segment(SELECTEDVALUE) =
SELECTEDVALUE(Global_Superstore2[Segment], "Multiple Segments Selected")
❑ Selected_Ship_Mode(SELECTEDVALUE) =
SELECTEDVALUE(Global_Superstore2[Ship Mode], "Select a Ship Mode")
❑ Selected_Year(SelectedValue) = SELECTEDVALUE(Global_Superstore2[OrderYear],"Multiple
Years Selected")
1️⃣ Display the Selected Region Name
Returns the name of the selected Region from the slicer.
Selected_Region =
SELECTEDVALUE(Global_Superstore2[Region], "Multiple Regions Selected")
What it does?
•If one region (e.g., "West") is selected → it returns "West".
•If multiple regions are selected → it returns "Multiple Regions Selected".
Example Output
Selected Region(s) Output
West West
Multiple Regions
West, East
Selected
Kya Hoga?
•Agar ek Region select hai → Wahi Region dikhayega.
•Agar multiple ya koi bhi select nahi hai → "All Regions" dikhayega
Sales_Status =
IF(
SELECTEDVALUE(Sales_Data[Sales]) > 5000,
"Above Target",
"Below Target"
)
Kya Hoga?
•Agar Sales 5000 se zyada hai, toh "Above Target" return karega.
•Agar 5000 se kam hai ya multiple values select hain, toh "Below Target" return karega.
Summary
•SELECTEDVALUE returns the selected value of a column when only one value is chosen.
•If multiple values are selected, it returns an alternate result (or BLANK).
•Very useful for slicers and user selections in reports.
Final Thoughts:
•SELECTEDVALUE single value ko extract karne ke liye best hai, lekin agar multiple
values hain toh iska use carefully karna chahiye.
•Agar tumhe multiple values manage karni hain, toh VALUES() ya CONCATENATEX() ka
use kar sakte ho.
•Conditional logic aur dynamic text ke liye yeh ek useful function hai.
(VI) VALUES
The VALUES function returns a single-column table containing unique values from a
column. It is commonly used to:
•Retrieve unique values for filtering.
•Work with slicers and dynamic measures.
•Handle relationships in calculated columns and measures.
(VALUES() ek DAX function hai jo ek column ki unique values ka table return karta hai.
Yeh filtered data ke basis par dynamic list deta hai aur slicer ya filter ke saath kaam
karta hai.)
Syntax: VALUES(<column>)
<column> – The column from which to return unique values. (Column ka naam jisme se
unique values extract karni hai.)
→ Measure me use nahi hota hai direct use karna hai to calculated column me use hoga
➢ Unique_Order_Years(VALUES) = VALUES(Global_Superstore2[OrderYear])
➢ Selected_Ship_Mode(VALUES) = IF(HASONEVALUE(Global_Superstore2[Ship
Mode]),VALUES(Global_Superstore2[Ship Mode]),"Multiple Selected")
➢ Category_Count(VALUES)=COUNTROWS(VALUES(Global_Superstore2[Category]))
➢ SELECTEDVALUES_VALUES(VALUES) = VALUES(Global_Superstore2[Region])
Unique_Regions = VALUES(Global_Superstore2[Region])
Unique Regions
What it does? East
•Retrieves unique region names from the dataset.
West
•Can be used in tables, slicers, or filters.
Example Output Central
South
Summary
•VALUES returns a table of unique values from a column.
•Used in filtering, slicers, and calculations.
•When combined with COUNTROWS, HASONEVALUE, or IF, it can create powerful
measures.
Key Takeaways:
1.VALUES() ko measure me use mat karo → Measure me CONCATENATEX() use
karo.
2.VALUES() calculated column me work karega → Direct Region column use karo.
3.Agar unique region ka slicer banana hai → Global_Superstore2[Region] ko
directly slicer me drag karo.
(VII) FILTER
The FILTER function returns a table with rows that meet a specific condition. It is
commonly used for:
•Creating custom filtered tables.
•Working with CALCULATE for conditional aggregations.
•Applying row-level filters in DAX measures.
❑ Orders_2014(FILTER) =
CALCULATE(SUM(Global_Superstore2[Sales]),FILTER(Global_Superstore2,YEAR(Globa
l_Superstore2[Order_Date])=2014))
❑ Last30Days_Sales(FILTER) =
CALCULATE(SUM(Global_Superstore2[Sales]),filter(Global_Superstore2,Global_Super
store2[Order_Date].[Date]>=MAX(Global_Superstore2[Order_Date].[Date])-30))
❑ High_Value_Sales(FILTER) =
CALCULATE(SUM(Global_Superstore2[Sales]),filter(Global_Superstore2,Global_Super
store2[Sales]>1000))
❑ East_Region_Sales(FILTER) =
CALCULATE(SUM(Global_Superstore2[Sales]),FILTER(Global_Superstore2,Global_Sup
erstore2[Region]="East"))
❑ Count_High_Value_Orders(FILTER) = CALCULATE(COUNT(Global_Superstore2[Order
ID]),FILTER(Global_Superstore2,Global_Superstore2[Sales]>1000))
Example 1: Filtered Sales for a Specific Region
Agar tumhe sirf 'East' region ke sales ka total chahiye, toh FILTER ka use aise hoga:
East_Region_Sales =
CALCULATE(
SUM(Global_Superstore2[Sales]),
FILTER(Global_Superstore2, Global_Superstore2[Region] = "East")
)
Explanation:
FILTER(Global_Superstore2, Global_Superstore2[Region] = "East") → Table se sirf ‘East’
region ke rows return karega.
CALCULATE(SUM(Global_Superstore2[Sales]), …) → East region ke total sales ka sum
karega.
High_Value_Sales =
CALCULATE(
SUM(Global_Superstore2[Sales]),
FILTER(Global_Superstore2, Global_Superstore2[Sales] > 1000)
)
Explanation:
FILTER(Global_Superstore2, Global_Superstore2[Sales] > 1000) → Sirf un rows ko select
karega jisme sales 1000 se zyada hai.
CALCULATE(SUM(Global_Superstore2[Sales]), …) → Un filtered orders ka sum return
karega.
Summary
•FILTER returns a table with rows meeting a condition.
•Commonly used with CALCULATE for advanced aggregations.
•Powerful for filtering data dynamically in reports.
FILTER table return karta hai, isliye direct measure me use nahi hota.
CALCULATE() ka use karo FILTER ke saath taaki measure properly kaam kare.
Agar sum ya count chahiye, toh CALCULATE(SUM(...)) ya CALCULATE(COUNT(...)) ka use
karo.
(VIII) CALCULATE
The CALCULATE function modifies the context of a calculation by applying filters. It is one
of the most powerful DAX functions because it allows:
•Conditional aggregations (e.g., Total Sales for a specific year).
•Dynamic filtering of tables.
•Combining multiple conditions in calculations
(CALCULATE() DAX function ka sabse powerful function hai. Yeh kisi bhi expression (SUM,
AVERAGE, COUNT, etc.) ko ek specified filter context ke saath evaluate karne ke liye use
hota hai. )
•<expression> – The aggregation or calculation to perform. (Jo calculation karni hai (SUM,
COUNT, AVERAGE, etc.))
•<filter1>, <filter2>, ... – One or more conditions applied to modify the context. (Jitne filters
chahiye, utne laga sakte ho)
❑ Total_Sales_2014(CALCULATE) =
CALCULATE(SUM(Global_Superstore2[Sales]),YEAR(Global_Superstore2[Order_Date])=201
4)
❑ Total_Sales_High_Discount(CALCULATE) =
CALCULATE(SUM(Global_Superstore2[Sales]),Global_Superstore2[Discount]>0.10)
❑ Total_Profit_West(CALCULATE) =
CALCULATE(SUM(Global_Superstore2[Sales]),Global_Superstore2[Region]="West")
❑ Consumer_Orders_Count(CALCULATE)=CALCULATE(count(Global_Superstore2[Order
ID]),Global_Superstore2[Segment]="Consumer")
❑ Avg_Discount_Technology(CALCULATE) =
CALCULATE(AVERAGE(Global_Superstore2[Discount]),Global_Superstore2[Category]="Tec
hnology")
Summary (Why is CALCULATE() Important?)
CALCULATE() kisi bhi measure ko filter context ke saath evaluate karne ke liye use hota hai.
Iska sabse bada advantage hai ki tum multiple filters apply kar sakte ho.
Isko SUM, COUNT, AVERAGE, etc. ke saath combine karke powerful calculations bana sakte ho.
(IX) CALCULATETABLE
The CALCULATETABLE function returns a filtered table instead of a single aggregated
value. It allows you to:
•Apply dynamic filters to a table.
•Modify the context of calculations.
•Use the filtered table inside other DAX functions.
(CALCULATETABLE() function poore table ka data modify karta hai filters apply karke.
Yeh CALCULATE() ke jaisa hi hai, bas yeh ek table return karta hai instead of a single
value.)
➢ <table> – The original table you want to filter. (Jis table ka filter apply karna hai)
➢ <filter1>, <filter2>, ... – One or more conditions applied to modify the table’s
context. (Jo conditions apply karni hai)
CALCULATETABLE() sirf New Table banane ke liye use hota hai, isko Measure me nahi likh
sakte.
Sahi Tarika (New Table ke liye):
West_Region_Table = CALCULATETABLE(Global_Superstore2,
Global_Superstore2[Region] = "West")
Yeh Power BI me "New Table" create karega, sirf West region ka data rakh kar.
Isko "Table Visual" me dalo, to sirf West region ka data dikhega.
➢ Orders_2024
=CALCULATETABLE(Global_Superstore2,YEAR(Global_Superstore2[Order_Date]) = 2014)
❑ All_Regions_Orders =
CALCULATETABLE(Global_Superstore2,REMOVEFILTERS(Global_Superstore2[Region]))
(X) TREATAS
The TREATAS function applies a table of values as a filter to another unrelated table. It is
useful when you need to:
•Apply filters from one table to another (without direct relationships).
•Create virtual relationships in DAX calculations.
•Use aggregated values from one table to filter another.
<Table> → A table containing values that will be treated as filters. (Yeh woh table hai
jiska data filter ke roop me use hoga.)
<Column1>, <Column2>, ... → The columns where these filters will be applied. (Yeh
woh column(s) hai jo filter apply karenge dusre table me. )
1️⃣ Filter Global_Superstore2 Sales Using a Separate Region Table
We use a table of selected regions as a filter for Global_Superstore2.
Filtered_Sales =
CALCULATE(
SUM(Global_Superstore2[Sales]),
TREATAS(
{"East", "West"},
Global_Superstore2[Region]
)
)
What it does?
•Filters Global_Superstore2 to only show East and West regions.
•Calculates total sales for these regions without needing a direct relationship.
Example Output:
Total Sales in East & West → $ 24334894
➢ Filtered_Orders =
CALCULATE(COUNTROWS(Global_Superstore2),TREATAS(VALUES(YearTable[Year]),Glo
bal_Superstore2[Order Year] ))
➢ Filtered_Profit = CALCULATE(SUM(Global_Superstore2[Profit]),
TREATAS(VALUES(SegmentTable[Segment]), Global_Superstore2[Segment]))
USERELATIONSHIP() ek DAX function hai jo inactive relationship ko active karne ke liye use
hota hai. Agar Power BI ya SSAS me do tables ke beech multiple relationships ho, toh
Power BI ek relationship ko active rakhta hai aur doosre ko inactive bana deta hai.
USERELATIONSHIP() ka use tab hota hai jab hume inactive relationship activate karna
ho kisi specific calculation ke liye.
DimDate = CALENDARAUTO()
DimDate = ADDCOLUMNS(
CALENDAR(DATE(2011,1,1), DATE(2014,12,31)),
"Year", YEAR([Date]),
"Month", FORMAT([Date], "MMMM"),
"Month Number", MONTH([Date]),
"Quarter", "Q" & FORMAT([Date], "Q"),
"Weekday", FORMAT([Date], "dddd")
)
Check_Active_Relationship =
IF(
ISCROSSFILTERED(DimDate[Date]),
"Active",
"Not Active"
)
(XII) CROSSFILTER
The CROSSFILTER function modifies the filter direction between two related tables.
Why use CROSSFILTER?
•Power BI normally applies filters in one direction (e.g., from DateTable to
Global_Superstore2).
•CROSSFILTER lets you change the filter direction dynamically:
•None → Removes filtering between tables.
•Both → Filters work in both directions.
•One → Resets to default filtering direction.
CROSSFILTER function table relationships ka filter direction control karne ke liye use hota
hai. Agar tumhe kisi relationship ka filter flow change ya disable karna ho, to ye kaam karta
hai.
Iska Matlab:
"Total Sales ka sum nikalo, lekin DimDate[Date] aur Order_Date ke beech jo relationship
hai, usko ignore kar do (disable kar do)!"
Result: DimDate ka filter kaam nahi karega, aur sales poore dataset ka sum return
karega.
CALCULATE(SUM(Global_Superstore2[Sales]),CROSSFILTER(DimDate[Date],
Global_Superstore2[Order_Date], BOTH))
Iska Matlab:
"Total Sales ka sum nikalo, aur DimDate aur Order_Date ke beech jo relationship hai usko
bi-directional filtering me convert kar do!"
Result: Ab DimDate bhi Global_Superstore2 ko filter karega aur vice versa.
Iska Matlab:
"Total Sales ka sum nikalo, aur filter direction ko default (one-way) rakhne do!"
Result: Filter sirf DimDate se Global_Superstore2 ki taraf jayega, par ulta nahi.
Summary
•CROSSFILTER modifies the filter direction between two related tables.
•"None" → Removes filtering.
•"Both" → Enables bidirectional filtering.
•"One" → Resets to default filtering.
•Used inside CALCULATE to override relationships dynamically.
CROSSFILTER tables ke relationships ka filter control karta hai!
•NONE → Filter hata do (disable relationship)
•BOTH → Filter dono taraf apply karo (bi-directional)
•ONEWAY → Default direction maintain karo (Dim → Fact)
(XIII) KEEPFILTERS
The KEEPFILTERS function in DAX is used inside CALCULATE to preserve existing filters
when applying new ones.
Normally, CALCULATE replaces existing filters with the new ones applied.
KEEPFILTERS ensures that both old and new filters work together instead of
overwriting each other.
Syntax: KEEPFILTERS(<Expression>)
<Expression> → The filtering condition you want to apply without removing previous
filters. (Jo bhi calculation tum CALCULATE ya CALCULATETABLE me kar rahe ho)
Total_Sales_Overwritten =
CALCULATE(
SUM(Global_Superstore2[Sales]),
Global_Superstore2[Sub-Category]
= "Chairs")
Total_Sales_KeepFilters =
CALCULATE(
SUM(Global_Superstore2[Sales]),
KEEPFILTERS(Global_Superstore2[Sub-Category]
= "Chairs"))
❑ Total_Profit_KeepFilters =
CALCULATE(SUM(Global_Superstore2[Profit]),KEEPFILTERS(Global_Superstore2[Region]="
West"),KEEPFILTERS(Global_Superstore2[Segment]="Consumer"))
❑ Sales_2014_Keepfilter =
CALCULATE(SUM(Global_Superstore2[Sales]),KEEPFILTERS(YEAR(Global_Superstore2[Orde
r_Date])=2014))
❑ Sales_Furniture_Technology(KeepFilter) =
CALCULATE(SUM(Global_Superstore2[Sales]),KEEPFILTERS(Global_Superstore2[Category]
IN {"Furniture","Technology"}))
Summary
•KEEPFILTERS preserves existing filters when using CALCULATE.
•Without KEEPFILTERS, new filters replace old ones.
•Useful in dashboards to avoid removing user-selected filters.
•Best for multi-filter scenarios where different filters should remain active together.
(XIV) ISFILTERED
The ISFILTERED function checks if a column has an active direct filter applied in the
current context.
It returns TRUE if the column is filtered, otherwise, it returns FALSE.
This is useful when creating dynamic calculations that change based on whether a filter
is applied.
Syntax: ISFILTERED(<ColumnName>)
ColumnName → The column for which you want to check if a filter is applied.
❑ Category_Filter_Status(ISFILTERED) =
IF(ISFILTERED(Global_Superstore2[Category]),"Filtered","Not Filtered")
❑ Date_Filter_Status(ISFILTERED) =
IF(ISFILTERED(Global_Superstore2[Order_Date]),"Filtered","No filter")
❑ Dynamic_Sales_Calculation(ISFILTERED) = IF(ISFILTERED(Global_Superstore2[Sub-
Category]),AVERAGE(Global_Superstore2[Sales]),SUM(Global_Superstore2[Sales]))
❑ Is_Category_Filtered(ISFILTERED) = ISFILTERED(Global_Superstore2[Category])
❑ Sales_Only_If_Region_Filtered(ISFILTERED) =
IF(ISFILTERED(Global_Superstore2[Region]),SUM(Global_Superstore2[Sales]),0)
Summary
•ISFILTERED(ColumnName) checks if a column has an active filter.
•Useful for dynamic calculations in dashboards & reports.
•Combines well with IF to create conditional logic.
•Works for both categorical (text) and date columns
(XV) ISBLANK
ISBLANK(Value) is a DAX function that checks whether a value is blank (empty/null) or not.
•Returns TRUE → If the value is blank (BLANK()).
•Returns FALSE → If the value is not blank (i.e., it contains data).
Syntax: ISBLANK(<expression>)
expression → The value or calculation you want to check for blank (BLANK()).
❑ Is_Profit_Blank(ISBLANK) = ISBLANK(Global_Superstore2[Profit])
❑ Discount_Status(ISBLANK)=IF(ISBLANK(Global_Superstore2[Discount]),0
,Global_Superstore2[Discount])
❑ Sales_Handling_Blank = IF(ISBLANK(Global_Superstore2[Sales]),0,
Global_Superstore2[Sales])
❑ Total_Profit_No_Blank(ISBLANK)
=IF(ISBLANK(Global_Superstore2[Profit]),0,Global_Superstore2[Profit])
❑ Total_Profit_No_Blank(ISBLANK) =
IF(ISBLANK(Global_Superstore2[Profit]),0,Global_Superstore2[Profit])
Summary
•ISBLANK(expression) checks if a value is blank (BLANK()).
•Useful for handling missing data and avoiding errors.
•Combines well with IF to create conditional logic.
•Works with numbers, text, dates, and measures.
4. Information Functions
(I) ISERROR
The ISERROR function checks whether an expression or calculation results in an error in DAX.
It returns TRUE if the expression results in an error and FALSE otherwise.
Useful for handling errors in calculations and preventing report failures.
Syntax: ISERROR(<expression>)
❑ Is_Error_Division(ISERROR) =
ISERROR(Global_Superstore2[Sales]/Global_Superstore2[Quantity])
❑ Sales_Per_Quantity(ISERROR) =
IF(ISERROR(Global_Superstore2[Sales]/Global_Superstore2[Quantity]),0,Global_Superstore2[Sal
es]/Global_Superstore2[Quantity])
❑ Total_Profit_NO_Error(ISERROR) =
IF(ISERROR(SUM(Global_Superstore2[Profit])),0,SUM(Global_Superstore2[Profit]))
❑ Is_Error_Profit_Per_Order(ISERROR)=ISERROR(SUM(Global_Superstore2[Profit]) /
COUNT(Global_Superstore2[Order ID]))
❑ Discount_Percentage(ISERROR)
=IF(ISERROR(Global_Superstore2[Discount]/Global_Superstore2[Sales]),
"Error",FORMAT(Global_Superstore2[Discount]/Global_Superstore2[Sales], "0.00%"))
Summary of ISERROR
The ISERROR function in DAX is used to detect errors in calculations and return TRUE if an
error occurs, otherwise FALSE.
It helps prevent report failures by allowing error handling and replacement with alternative
values.
(II) ISNONTEXT
Definition:
The ISNONTEXT function in DAX checks whether a value is not a text (string). If the value is not
text, it returns TRUE; otherwise, it returns FALSE.
Syntax: ISNONTEXT(<value>)
<value> → The value you want to check.
How It Works:
•Returns TRUE if the value is not text (e.g., numbers, dates, Boolean, blank, errors).
•Returns FALSE if the value is text.
❑ Non_Text() = ISNONTEXT(Global_Superstore2[Sales])
❑ Handling_Non_Text_Value = IF(ISNONTEXT(Global_Superstore2[Discount]),"Numeric
Value","Text Value")
(III) ISNUMBER
Definition:
The ISNUMBER function in DAX checks whether a given value is a number.
•If the value is a number, it returns TRUE.
•If the value is not a number (text, date, blank, Boolean, or error), it returns FALSE.
Syntax: ISNUMBER(<value>)
<value> → The value you want to check.
❑ Sales_Is_Number = ISNUMBER(Global_Superstore2[Sales])
❑ OrderDate_Is_Number = ISNUMBER(Global_Superstore2[Order_Date])
❑ CustomerName_Is_Number = ISNUMBER(Global_Superstore2[Customer Name])
❑ Discount_Type = IF(ISNUMBER(Global_Superstore2[Discount]), "Numeric", "Non-Numeric")
❑ Profit_Cleaned = IF(ISNUMBER(Global_Superstore2[Profit]), Global_Superstore2[Profit], 0)
(IV) ISTEXT
Definition:
The ISTEXT function in DAX checks whether a given value is text (string).
•If the value is text, it returns TRUE.
•If the value is not text (number, date, Boolean, blank, or error), it returns FALSE.
Syntax: ISTEXT(<value>)
<value> → The value or column to check.
Syntax: ISLOGICAL(<value>)
<value> → The value or column to check.
❑ Discount_Is_Logical = ISLOGICAL(Global_Superstore2[Discount])
❑ High_Sales = IF(Global_Superstore2[Sales] > 500, TRUE(), FALSE())
❑ High_Sales_Is_Logical = ISLOGICAL([High_Sales])
❑ Order_Priority_Is_Logical = IF(ISLOGICAL(Global_Superstore2[Order Priority]), "Boolean",
"Non-Boolean")
❑ Filtered_Logical_Values = FILTER(Global_Superstore2, ISLOGICAL(Global_Superstore2[Ship
Mode]))
❑ Customer_Segment_Logical = IF(ISLOGICAL(Global_Superstore2[Customer Segment]),
Global_Superstore2[Customer Segment], FALSE())
5. Logical Functions
(I) IFERROR
The IFERROR function in DAX is used to handle errors in calculations.
•If the given expression returns an error, IFERROR replaces it with a specified value.
•If there is no error, it simply returns the result of the expression.
SWITCH() function ka kaam hai multiple conditions check karna aur uske hisaab se
output dena – bilkul jaise IF..ELSE LADDER ki tarah!
•<expression> → The value to compare. (Yeh evaluate hoga (e.g., column value ya
measure)).
•<value1>, <value2>, ... → The possible values of the expression. (Yeh values compare ki
jayengi.)
•<result1>, <result2>, ... → The output corresponding to each value. (Inke corresponding
output return honge.)
•[<else_result>] (optional) → The default value if no match is found. (Agar koi match nahi
mila, to yeh default value return karega.)
Shipping_Type(SWITCH) =
SWITCH(
Global_Superstore2[Ship Mode],
"Same Day", " Express Shipping",
"First Class", " Fast Shipping",
"Second Class", " Standard Shipping",
"Standard Class", " Economy Shipping",
"Unknown"
)
Discount_Label(SWITCH) =
SWITCH(
TRUE(),
Global_Superstore2[Discount] >= 0.5, " Huge Discount",
Global_Superstore2[Discount] >= 0.3, " Big Discount",
Global_Superstore2[Discount] > 0, " Small Discount",
"No Discount"
)
Why Use SWITCH?
Customer_Segment(SWITCH) =
Easier to read than multiple IF
SWITCH(
statements.
Global_Superstore2[Segment],
Faster performance in Power BI reports.
"Consumer", " Individual Customer",
Great for categorization and grouping
"Corporate", " Business Client",
data dynamically.
"Home Office", " Small Business",
By using SWITCH, you can create cleaner
"Unknown"
and more efficient logic for your Power BI
)
dashboards!
(III) ISINSCOPE
The ISINSCOPE function in DAX checks whether a specific column is currently being filtered
within a hierarchical structure (e.g., when using row-level grouping in Power BI tables,
matrices, or visuals).
•It is useful for identifying if a field is inside a specific hierarchy level.
•Mainly used in dynamic calculations and conditional formatting based on drill-down levels.
(ISINSCOPE() ka kaam hai check karna ki koi column ek particular hierarchy level pe filter ho
raha hai ya nahi. Yeh mainly hierarchies (jaise Category -> Sub-Category) ke andar filter
detect karne ke liye use hota hai.)
Syntax: ISINSCOPE(<columnName>)
❑ <columnName> → The column you want to check if it's currently in scope (filtered or
grouped).
❑ Returns TRUE if the column is in the current scope. (Yeh TRUE return karta hai jab ek
specific column ka filter apply ho)
❑ Returns FALSE if the column is not in scope. (FALSE return karega agar us column ka filter
apply nahi hai)
❑ Mostly tables ya matrix visualizations me use hota hai
❑ Is_Category_In_Scope = ISINSCOPE(Global_Superstore2[Category])
❑ Is_SubCategory_In_Scope = ISINSCOPE(Global_Superstore2[Sub-Category])
❑ Sales_Display =
IF(ISINSCOPE(Global_Superstore2[Category]),SUM(Global_Superstore2[Sales]),
AVERAGE(Global_Superstore2[Sales])
COALESCE() ek Power BI DAX function hai jo pehli non-blank value return karta hai. Agar sab
blank hai, to ek default value return hoti hai.
❑ Sales_Corrected(COALESCE) = COALESCE(SUM(Global_Superstore2[Sales]), 0)
❑ Order_Quantity_Corrected(COALESCE) =COALESCE(SUM(Global_Superstore2[Quantity]), 1)
❑ Discount_Profit(COALESCE)
=COALESCE(SUM(Global_Superstore2[Discount]),SUM(Global_Superstore2[Profit]), 0)
If Discount is blank, it returns Profit; if both are blank, it returns 0.
o Discount_Percentage(VAR) =
o VAR TotalDiscount = SUM(Global_Superstore2[Discount])
o VAR TotalSales = SUM(Global_Superstore2[Sales])
o RETURN IF(TotalSales > 0, TotalDiscount / TotalSales, 0)
o Avg_Sales_Per_Order(VAR) =
o VAR TotalSales = SUM(Global_Superstore2[Sales])
o VAR OrderCount = DISTINCTCOUNT(Global_Superstore2[Order ID])
o RETURN TotalSales / OrderCount
o Adjusted_Region_Profit(VAR) =
o VAR RegionSales = SUM(Global_Superstore2[Sales])
o VAR RegionProfit = SUM(Global_Superstore2[Profit])
o RETURN IF(RegionSales > 5000, RegionProfit * 1.1, RegionProfit)
Why Use VAR in DAX?
Improves performance by avoiding repetitive calculations.
Makes DAX easier to read by breaking down complex formulas.
Enhances flexibility for conditional logic and dynamic calculations.
Using VAR makes your DAX formulas cleaner, faster, and easier to debug!
6. Text Functions
(I) CONCATENATE
The CONCATENATE function in DAX is used to combine two text values into a single string.
It only accepts two arguments at a time (unlike CONCATENATEX).
If more than two values need to be combined, multiple CONCATENATE functions must be
nested.
(II) CONCATENATEX
The CONCATENATEX function in DAX joins text values from a table or column, separated by a
specified delimiter. Unlike CONCATENATE, which works with only two values, CONCATENATEX
can concatenate multiple values dynamically.
Works well when combining multiple rows into a single string.
Allows custom sorting of values before concatenation.
Can apply calculations before concatenation (e.g., converting numbers to text).
(Ye table ke multiple rows ka data ek string me combine karne ke kaam aata hai, aur
custom delimiter bhi add kar sakte hain!)
Products_Per_Order(CONCATENATEX) = CONCATENATEX(VALUES(Global_Superstore2[Product
Name]), Global_Superstore2[Product Name], ", ")
Customer_Purchases = CONCATENATEX(FILTER(Global_Superstore2,
Global_Superstore2[Customer Name] = "John Doe"), Global_Superstore2[Product Name], "
| ", Global_Superstore2[Product Name], ASC)
Categories_By_Region = CONCATENATEX(VALUES(Global_Superstore2[Category]),
Global_Superstore2[Category], ", ")
(III) REPLACE
The REPLACE function in DAX is used to replace part of a text string with a new text value. It is
useful for modifying text data dynamically, such as correcting typos, masking sensitive
information, or standardizing formats.
❑ Masked_Customer_Name(REPLACE) = REPLACE(Global_Superstore2[Customer
Name], 2, 4, "****")
(V) TEXT
The TEXT function in DAX converts a value into a formatted text string using a specified format.
It is useful for customizing number, date, and time formats, making reports more readable and
visually appealing.
Syntax: VALUE(<Text>)
(VII) SUBSTITUTE
The SUBSTITUTE function in DAX replaces a specific part of a text string with another text string.
It is useful for cleaning or transforming text data.
(VIII) FIND
The FIND function in DAX searches for a substring within a text string and returns the starting
position of the substring. If the substring is not found, it returns an error.
7. Parent-Child Functions
(I) LOOKUPVALUE
The LOOKUPVALUE function returns a single value from a column based on specified search
conditions. It works like a VLOOKUP in Excel but is more flexible and powerful.
•Result_ColumnName → The column from which you want to retrieve the value. (Jo value
return karni hai)
•Search_ColumnName → The column where the function searches for a match. (Jisme search
karna hai)
•Search_Value → The value to search for in Search_ColumnName. (Jo value match karni hai)
•Alternate_Result (Optional) → The value returned if no match is found (default = error). (Agar
match na mile to kya return kare)
Key Notes:
Returns a single value (if multiple matches exist, it returns an error).
Can use multiple search conditions (Search_ColumnName2, Search_Value2, etc.).
Works well for retrieving related data without relationships.
LOOKUPVALUE tabhi sahi kaam karega jab search ki gayi value (Customer Name ya koi bhi
column) UNIQUE ho.
Agar multiple rows match hoti hain, to LOOKUPVALUE error de sakta hai ya BLANK return kar
sakta hai.
LOOKUPVALUE() ka Simple Example
Scenario:
Maan lo tumhare paas ek Customers table hai, jisme Customer Name aur Region diya gaya hai.
Tumhe Orders table me har Customer Name ka corresponding Region lana hai.
Region_Lookup =
LOOKUPVALUE(Customers[Region], Customers[Customer Name], Orders[Customer Name])
Row ID Sales_Lookup =
LOOKUPVALUE(Global_Superstore2[Sales], Global_Superstore2[Row ID],15810)
9. Rank Functions
(I) RANKX
The RANKX function in DAX is used to return the ranking of a value in a column based on a
specified expression. It assigns a rank to each row based on the order defined in the
expression.
(RANKX() ek ranking function hai jo kisi table ke ek column ke values ko compare karke unka
rank assign karta hai, highest ya lowest value ke basis pe.)
Key Notes:
Ranks are assigned dynamically based on the filtered context.
Can be used with ALL, ALLEXCEPT, or ALLSELECTED to control ranking scope.
Works best with numerical data like Sales, Profit, or Quantity Sold.
Category_Rank_Segment =
RANKX(ALLEXCEPT(Global_Superstore2,Global_Superstore2[Segment]),CALCULATE(SUM(Globa
l_Superstore2[Sales])), , DESC, Skip)
Customer_Profit_Rank = RANKX(ALLSELECTED(Global_Superstore2[Customer
ID]),CALCULATE(SUM(Global_Superstore2[Profit])),,DESC,Dense)
Product_Sales_Rank = RANKX(ALL(Global_Superstore2[Product
Name]),CALCULATE(SUM(Global_Superstore2[Sales])),,DESC,Dense)
Region_Sales_Rank =
RANKX(ALL(Global_Superstore2[Region]),CALCULATE(SUM(Global_Superstore2[Sales])),,DESC,Skip)
Sales_Rank_By_Category
=RANKX(ALLSELECTED(Global_Superstore2[Category]),CALCULATE(SUM(Global_Superstore2[Sales])
),,DESC, DENSE)
(RANK.EQ() ek ranking function hai jo kisi column ya measure ki ranking calculate karta hai ties ke
saath. Matlab agar do values same hoti hain, to unko same rank assign hoti hai, aur next rank
skip ho jata hai.)
•Number → The value whose rank you want to determine. (Jo value rank karni hai (usually
SUM, AVERAGE, etc.))
•Column → The column containing the values to rank against. (Jisme ranking karni hai)
Order (Optional, Default = Descending) → (
•ASC ya DESC (Ascending ya Descending order))
•0 (Descending) → Highest value gets Rank 1.
•1 (Ascending) → Lowest value gets Rank 1.