0% found this document useful (0 votes)
728 views7 pages

DAX Patterns PDF

The document discusses various DAX measures and calculations for analyzing sales, transactions, budgets, and other financial data over time. It includes measures to calculate year-to-date, moving annual total, prior year, and budgeted sales. Filters are applied to the measures to select specific date ranges, product categories, and budgets when analyzing the data.

Uploaded by

Chan Nyein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
728 views7 pages

DAX Patterns PDF

The document discusses various DAX measures and calculations for analyzing sales, transactions, budgets, and other financial data over time. It includes measures to calculate year-to-date, moving annual total, prior year, and budgeted sales. Filters are applied to the measures to select specific date ranges, product categories, and budgets when analyzing the data.

Uploaded by

Chan Nyein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

a brand of

a brand of
o
o
o


• •
• •

o o
o •

o
o

o

o

Cumulative Quantity := [UnitsInStock] := [Cumulative Quantity]


CALCULATE (
SUM ( Transactions[Quantity] ), Value :=
FILTER ( SUMX (
ALL ( 'Date'[Date] ), VALUES ( Products[ProductKey] ),
'Date'[Date] <= MAX ( 'Date'[Date] ) [ProductPrice] * [UnitsInStock]
) )
)

LastBuyPrice := LastSellPrice :=
IF ( IF (
HASONEVALUE ( Products[ProductKey] ), HASONEVALUE ( Products[ProductKey] ),
AVERAGEX ( AVERAGEX (
CALCULATETABLE ( CALCULATETABLE (
TOPN ( 1, Movements, Movements[DateKey] ), TOPN ( 1, Movements, Movements[DateKey] ),
Movements[Quantity] > 0, Movements[Quantity] < 0,
FILTER ( FILTER (
ALL ( 'Date'[Date] ), ALL ( 'Date'[Date] ),
'Date'[Date] <= MAX ( 'Date'[Date] ) 'Date'[Date] <= MAX ( 'Date'[Date] )
) )
), ),
Movements[UnitCost] Movements[UnitCost]
) )
) )
o
• [YTD] :=
CALCULATE (
o [OriginalMeasure],
FILTER (
• ALL ( 'Date' ),
'Date'[Year] = MAX ( 'Date'[Year] )
&& 'Date'[Date] <= MAX ( 'Date'[Date] )
)
)

o [MAT Sales] :=
CALCULATE (
o [Sales],
FILTER (
ALL ( 'Date' ),
'Date'[SequentialDayNumber]
> MAX ( 'Date'[SequentialDayNumber] ) - 365
&& 'Date'[SequentialDayNumber]
<= MAX ( 'Date'[SequentialDayNumber] )
)
)
SequentialDayNumber = CALCULATE (
COUNTROWS ( [Sales],
FILTER ( ALL ( 'Date' ),
ALL ( DATE ), FILTER (
'Date'[Date] <= EARLIER ( 'Date'[Date] ) ALL ( 'Date'[YearMonthNumber] ),
&& NOT ( 'Date'[YearMonthNumber]
MONTH ( 'Date'[Date] ) = 2 = EARLIER ( 'Date'[YearMonthNumber] ) -
&& DAY ( 'Date'[Date] ) = 29 1
) )
) )
)

[PY Sales] :=
CALCULATE ( SUMX (
VALUES ( 'Date'[YearMonthNumber] ), [PY Sales] :=
[Sales], IF (
CALCULATE ( COUNTROWS ( VALUES ( 'Date'[Date] ) ) )
= CALCULATE ( VALUES ( 'Date'[MonthDays] ) ),
SUMX (
VALUES ( 'Date'[YearMonthNumber] ),
ALL ( 'Date' ), CALCULATE (
[Sales],
ALL ( 'Date' ), IF (
CALCULATETABLE ( VALUES ( 'Date'[MonthDayNumber] ) ), FILTER (
ALL ( 'Date'[YearMonthNumber] ),
'Date'[YearMonthNumber]
< month fully selected >,
FILTER ( )
= EARLIER ( 'Date'[YearMonthNumber] ) - 12 < complete month 12 months before >,
), < selected days 12 months before >
ALL ( 'Date'[YearMonthNumber] ), CALCULATE (
[Sales], )
ALL ( 'Date' ),
'Date'[YearMonthNumber] CALCULATETABLE ( VALUES ( 'Date'[MonthDayNumber] ) ),
FILTER (
)
= EARLIER ( 'Date'[YearMonthNumber] ) - 1 ALL ( 'Date'[YearMonthNumber] ),
'Date'[YearMonthNumber]
= EARLIER ( 'Date'[YearMonthNumber] ) - 12
) )
)
)

) )
o

• 'Date'[YearMonth] =
'Date'[Year] * 100 +
o 'Date'[MonthNumber]

Budget[YearMonth] =
Budget[Year] * 100 + Budget[Month]

[Budget] := [IsBudgetValid] :=
(
IF ( COUNTROWS ( Sales )
[IsBudgetValid], = CALCULATE (
[BudgetCalc], COUNTROWS ( Sales ),
ALL ( Sales ),
[AllocatedBudget] VALUES ( 'Date'[YearMonth] ),
) VALUES ( Product[Category] )
)
)

[BudgetCalc] :=
CALCULATE (
SUM ( Budget[Budget] ),
// Filter argument per relazione virtuale
FILTER (
[AllocatedBudget] :=
FILTER (
ALL ( Budget[YearMonth] ),
CONTAINS (
ALL ( tab1[column] ),
CONTAINS (
SUMX (
VALUES ( 'Date'[YearMonth] ),
'Date'[YearMonth], Budget[YearMonth]
VALUES ( tab2[column] ),
tab2[column],
CROSSJOIN (
)
),
FILTER ( )
tab1[column]
VALUES ( 'Date'[YearMonth] ),
ALL ( Budget[Category] ),
CONTAINS (
VALUES ( Product[Category] ),
)
VALUES ( Product[Category] )
Product[Category], Budget[Category]
)
) ),
)
[AllocationFactor] * [BudgetCalc]
)
[AllocationFactor] :=
o
[QuantityPY] :=
[QuantityPY]
/ CALCULATE ( CALCULATE (
[QuantityPY], [Quantity],
ALLEXCEPT ( SAMEPERIODLASTYEAR ( 'Date'[Date] )
Product, )
Product[Category],
Product[ID_Category]
),
ALL ( 'Date' ),
VALUES ( 'Date'[YearMonth] ),
ALL ( Territory )
)

MonthsWithSales :=
o CALCULATE ( DISTINCTCOUNT ( Dates[MonthNumber] ), Sa
les )

• SoldCategories :=
CALCULATE (
DISTINCTCOUNT ( Subcategories[CategoryName] ),
• Sales
)
UniqueCustomers :=
CALCULATE (
DISTINCTCOUNT ( Customers[CustomerCode] ),
Sales
)

You might also like