Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Laman
New Member

DAX Formula

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
)

 

3 REPLIES 3
Anonymous
Not applicable

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?

 

bhanu_gautam
Super User
Super User

@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
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.