+ Reply to Thread
Results 1 to 9 of 9

[DAX] Test if a consecutive series of cells fulfill a certain condition

  1. #1
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    [DAX] Test if a consecutive series of cells fulfill a certain condition

    Hi All,

    I am seeking your help again with a task at hand I'm trying to achieve with DAX.

    I have a requirement, which is to highlight weeks where:
    1. a certain condition is fulfilled for a single cell. I believe this is a relatively straight forward one.
    2. a certain condition is fulfilled for a consecutive number of weeks. For example: Highlight the cells if the value exceeds threshold for 3 weeks consecutively. I am attaching a sample file that clearly explains everything with Excel calculations etc...

    Is there a way to do this in DAX? I have already done it via Excel equations in the first tab (using many helper rows) just to explain the idea, however, I need to do this in DAX because the real dataset is actually huge.

    Note: I also need the ability to filter on those Lines/SKUs which DO violate the condition, because there will be a large list of them, and the user will need to filter. This basically means I also need some sort of a "key" to be able to filter this with in the table.

    Thank You!

    Picture for Forum.JPG
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    Good Morning All!

    I would really appreciate your insights on this one if possible.

    Thanks!

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,898

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    There seems to be only one member who answers anything about DAX - he usually visits once a day, so hopefully he'll see this and comment.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    There is probably a simpler solution, but I think this will work:

    Please Login or Register  to view this content.
    Rory

  5. #5
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    Quote Originally Posted by AliGW View Post
    There seems to be only one member who answers anything about DAX - he usually visits once a day, so hopefully he'll see this and comment.
    Thank you Ali! I appreciate your amazing effort in moderating the forum.


    Quote Originally Posted by rorya View Post
    There is probably a simpler solution, but I think this will work:

    Please Login or Register  to view this content.
    Hi Rory!

    Thank you very much for the solution. I appreciate it. I can't claim I fully understand how it works but I'm trying to breakdown the logic.

    I think however that the logic is inconsistent for some reason.


    When I tried ">3" in the equation, it did this. For some reason it acted as if it's supposed to detect anything greater than or equal 3 and highlighted the first group even though it shouldn't.

    Greater than 3.JPG


    But when I tried ">5" it did this. This time it decided to behave differently from the previous one, and ignored the last group which is a violation of 5 consecutive cells.

    Greater than 5.JPG

    Do you have any idea how to resolve that inconsistency? I just need it to highlight when the violation is greater than a certain number of cells. I'm attaching the latest workbook to this reply below.

    Thank You!
    Attached Files Attached Files

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    It should be >4 in the formula for a streak longer than 3. It might be clearer if I'd put:

    Please Login or Register  to view this content.
    Essentially the logice is to find the week number of the last week with a 0, then the week number of the next week with a 0 and subtract the difference less 1 to get the number of consecutive non-zero items.

  7. #7
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    Hi Rory,

    I think something might still be off. I tried the below code while changing the parameter to >4, however it hasn't highlighted the last group which is a streak of 5 cells.
    Please Login or Register  to view this content.
    NOT WORKING.JPG

    I am attaching the latest worksheet again here. Would you be able to help with that and advise what is going wrong?

    Also, I have another question if you don't mind, how can I blend the whole thing into 1 DAX expression instead of depending on the "1 for every single week violation" helper row?

    Thank you very much!
    Attached Files Attached Files
    Last edited by DizerX; 03-16-2024 at 05:34 PM.

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    The row doesn't need to be in the pivot table.

    I forgot that any sequence at the start or end will need an adjustment:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    Re: [DAX] Test if a consecutive series of cells fulfill a certain condition

    I think it's working now. Thank you so much for your great help throughout this Rory! I appreciate it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 07-20-2022, 06:42 PM
  2. [SOLVED] Asigning consecutive textbox values to multiple consecutive cells...
    By Hovoruha Octavian in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2019, 06:31 PM
  3. Return a Value in a Series of 3 or more Consecutive Values
    By Jonathan78 in forum Excel General
    Replies: 7
    Last Post: 05-16-2016, 04:45 PM
  4. [SOLVED] appears a consecutive series
    By Dumy in forum Excel General
    Replies: 12
    Last Post: 07-21-2015, 02:47 PM
  5. Sum a series of cells if a certain condition is met (Sumif?)
    By Didley in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-15-2013, 10:38 AM
  6. need help to count with condition on two consecutive cells
    By beyma in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-29-2012, 08:15 PM
  7. do while condition for a series of cells in a matrix
    By eedde in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-29-2012, 07:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1