cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

Re: Measure to calculate how many times the same item occured in past weeks

Hi @Cactus26,

 

Did you try my solution?  If you did and the result is not as expected then let me know of that exact case.

 

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Cactus26 Regular Visitor
Regular Visitor

Re: Measure to calculate how many times the same item occured in past weeks

Hi @Ashish_Mathur,

 

The thing is that I do not store Occurence column in my project. As the occurence depends on filters chosen from slicers. Therefore I cannot create calculated column and I need a measure. Additionally I have thousands of items stored so it will be difficult to use your proposition. I tested @erik_tarnvik solution which is partially good but is missing the condition which check the items just for current week.

Re: Measure to calculate how many times the same item occured in past weeks

Hi Cactus,

 

This code looks fine, somewhat tricky, but it does its job.

 

 

Occ =
VAR CurrentWeek = CALCULATE ( MAX ( Test[Week] ), ALLSELECTED ( Test[Item] ) )
RETURN
    COUNTROWS (
        FILTER (
            CALCULATETABLE ( VALUES ( Test[Item] ), Test[Week] = CurrentWeek ),
            CALCULATE (
                COUNTROWS ( Test ),
                Test[Week] >= CurrentWeek - 2,
                Test[Week] <= CurrentWeek - 1
            )
                >= 2
        )
    )

 

Of course, you might need some minor modification and, most important, understand well how it works, since it hides some complexities in the definitino of CurrentWeek and the determination of the items.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

 

Alberto Ferrari - SQLBI

View solution in original post

erik_tarnvik Established Member
Established Member

Re: Measure to calculate how many times the same item occured in past weeks

Hi again @Cactus26,

glad we are close, did you test my second suggestion, or the one suggested by @AlbertoFerrari (more elegant as I would expect) from him)? My second suggestion does account for selecting a "current week". If this is not what you meant by that, please explain.

Cactus26 Regular Visitor
Regular Visitor

Re: Measure to calculate how many times the same item occured in past weeks

Hi @erik_tarnvik,

 

Yes I tested your two solutions but it did not get fully expected results. However now I tested formula given by @AlbertoFerrari and it works perfectly!  Thank you all for the help 🙂

Highlighted
erik_tarnvik Established Member
Established Member

Re: Measure to calculate how many times the same item occured in past weeks

Excellent!

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 452 members 4,634 guests
Please welcome our newest community members: