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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
akfir
Helper V
Helper V

Products Assortment with sales>0 count in the last 3 months

My data contains a monthly data of products sales. I wish to create a measure that counts the number of products with sales above zero in the last 3 month. Capture.PNG
I already created successfully a measure that sums up the sales in the last 3 months (by using DATESINPERIOD).
i tried this formula: 

Assortment = CALCULATE(count(Sales[product]),filter(sales,[SalesLast3Months]>0),filter(Sales,Sales[Date]=max(Sales[Date])))
but all i get is indeed the number of products with sales>0 but only as of the LAST month and not three aggregated.

appreciate your help in advance!
5 REPLIES 5
az38
Community Champion
Community Champion

Hi @akfir 

show please your SalesLast3Months statement

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

SalesLast3Months = CALCULATE([Sales],DATESINPERIOD(Sales[Date],max(Sales[Date]),-3,MONTH))

I would go with something like as follows. Create a var containing current date, then create a Summary table in a variable per product, with a column "lastthreemonths" using your [SalesLast3Months] measure. Then use COUNTX to filter out all rows with 0 as 'lastthreemonths' and return that value. Something like this (this is without intellisense so probably won't work right away ;))

Measure = 
VAR curDate = MAX(ALLSELECTED(Sales[Date])) //returns 1/1/2019 for January, 1/2/2019 for Feb etc
VAR summaryTable = SUMMARIZE(Sales, Sales[Product], "Last3Months", CALCULATE([Sales], DATESINPERIOD(ALL(Sales[Date]), curDate, -3, MONTH)))
RETURN
COUNTX(FILTER(summaryTable, [Last3Months] > 0), [Product])

 

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




does not work unfortunately ("DatesBetween and DatesInPeriod functions are only accepting date column refernce as a first argument")

i tried this one but it only worked sometimes and now it seems too heavy to load in a table visual:

CALCULATE(distinctcount(Sales[SKU]),filter(sales,[SalesLast3Months]>0),DATESINPERIOD(Sales[Date],LASTDATE(Sales[Date]),-3,MONTH))

is it a lighter way of this?

thanks

 

Hmm that makes sense, sorry for not testing my proposed solution. 

Is it possible to share your pbix? That will help a lot in creating the correct DAX for me.  If you want, you can share the link via PM and I will have a look shortly 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors