March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi! I want to get products which are sold n month sequentially. i wrote a dax measure , doest give an error but also doesnt works well. Example: if i want to find products which are sold 6 month sequentially, in a result it gives a product whcih are sold 3 month sequentially.
VAR NumberOfMonths = 6
VAR LastNMonths =
DATESINPERIOD(
'Date'[Date],
MAX('Date'[Date]),
-NumberOfMonths,
MONTH
)
VAR SelectedProductIDs =
SUMMARIZE(
FILTER(
'_Measures - Sales Invoice',
'_Measures - Sales Invoice'[SalesInvoiceDateID] IN LastNMonths
),
'_Measures - Sales Invoice'[ProductSID],
"MonthCount", DISTINCTCOUNT('_Measures - Sales Invoice'[SalesInvoiceDateID])
)
VAR ProductsWithSales =
FILTER(
SelectedProductIDs,
[MonthCount] = NumberOfMonths
)
RETURN
IF(
COUNTROWS('_Measures - Sales Invoice') > 0,
1,
0
)
I feel the below revised formula may works
VAR NumberOfMonths = 6
VAR LastNMonths =
DATESINPERIOD(
'Date'[Date],
MAX('Date'[Date]),
-NumberOfMonths,
MONTH
)
VAR SelectedProductIDs =
SUMMARIZE(
FILTER(
'_Measures - Sales Invoice',
'_Measures - Sales Invoice'[SalesInvoiceDateID] IN LastNMonths
),
'_Measures - Sales Invoice'[ProductSID],
"MonthCount", DISTINCTCOUNT('_Measures - Sales Invoice'[SalesInvoiceDateID].[Month])
)
VAR ProductsWithSales =
FILTER(
SelectedProductIDs,
[MonthCount] = NumberOfMonths
)
RETURN
IF(
COUNTROWS(FILTER('_Measures - Sales Invoice', '_Measures - Sales Invoice'[ProductSID] IN ProductsWithSales)) > 0,
1,
0
)
Hello @Anonymous thanks for repling. I got this error " Expression: The number of arguments is invalid. Function CONTAINSROW must have a value for each column in the table expression." how can i fix it?
@Laman , Try updating your measure as
VAR NumberOfMonths = 6
VAR LastNMonths =
DATESINPERIOD(
'Date'[Date],
MAX('Date'[Date]),
-NumberOfMonths,
MONTH
)
VAR SalesInLastNMonths =
FILTER(
'_Measures - Sales Invoice',
'_Measures - Sales Invoice'[SalesInvoiceDateID] IN LastNMonths
)
VAR ProductMonthCount =
ADDCOLUMNS(
SUMMARIZE(
SalesInLastNMonths,
'_Measures - Sales Invoice'[ProductSID],
'Date'[YearMonth]
),
"MonthCount", COUNTROWS(SalesInLastNMonths)
)
VAR ProductsWithSalesInAllMonths =
FILTER(
ProductMonthCount,
[MonthCount] = NumberOfMonths
)
RETURN
IF(
COUNTROWS(ProductsWithSalesInAllMonths) > 0,
1,
0
)
Proud to be a Super User! |
|
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
87 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |