Tuesday, November 10, 2026

Rolling Period Calculation - DATESINPERIOD

 Sometimes , we have to calculate total amount for rolling 12 month/rolling 3 month.

For such rolling period calculations, we can use Time intelligence function "DATESINPERIOD"


Rolling 3 month Sales =

VAR vMaxSalesDate = MAX(Sales[OrderDate])

RETURN
CALCULATE([Sales Amount], DATESINPERIOD(dim_date[Date], vMaxSalesDate, -3,MONTH))

Monday, November 9, 2026

Calculate customers whose sales are above average customer sales.

 First we need Total Sales Amount 

Sales Amount = SUM(Sales[SalesAmount])

Then we need to calculate Average Sales Amount
If we use below formula, it will give us the average. But we want to compare this average with sales amount of each customer. This average will change for each row as it operates on row context
DIVIDE([Sales Amount], DISTINCTCOUNT(Customers[CustomerName]), 0)

Hence we use below formula:
Avg Sales = AVERAGEX(ALL(Customers[CustomerName]), [Sales Amount])

Now, we need a flag which states if the Sales Amount is greater than Avg Sales

Above Avg Customer = IF([Sales Amount] > [Avg Sales], 1, 0)

In the table visual we can display CustomerName, SalesAmount. In Visual Filter we can add "Above Avg Customer = 1" and apply filter





ISINSCOPE()

Friday, November 6, 2026

HASONEVALUE

 Say there are scenarios where we want to link table & graph.

 Depending on the values of table the graph value also should   change.

Say in a table we have product category: Bike , cars, scooter

We want to show Bike Sales when Bike is selected in the table, when car is selected the graph should show sales of graph.

When all product category is selected, by default the chart should show car.


Then we can write an expression like 

IF (HASONEVALUE('Product'[Category]), 'Product'[Category], [Bike Sales])

Selected Category = IF(HASONEVALUE('Product'[Category]), 'Product'[Category], "Bike"

Other scenario is when we want to show multiple selected values
selectedyear =
 IF
 (HASONEVALUE(Fiscal_year[FY_desc]),
 SELECTEDVALUE(Fiscal_year[FY_desc]),
 CONCATENATEX(Fiscal_year, Fiscal_year[FY_desc], ",")
 )