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
StephenGW
Helper II
Helper II

Count by criteria

Hello all,

 

I'm pretty good with spreadsheet formulae but I'm struggling with measures. I have a large data table with a few columns. Area, Audit Date, and Pass/Fail. What I need for a measure is for each unique Area I need to find the most recent Audit Date where the Pass/Fail is a fail. So find the most recent fail for each unique area. Then count how many Passes since the most recent fail. What happens is when an area fails they get put on a probationary status. They must then get 10 passing audits to be removed from probationary status. I want to put this in a table and use conditional formatting to color the areas red that are in probation. Is this even possible with a measure?

 

Thanks,

Stephen

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @StephenGW 

Try to create 2 measures like below:
_AuditTime:

_AuditTime = MAX('Data'[Audit Time])

Probation:

Probation =
VAR _table =
    SUMMARIZE (
        FILTER (
            'Data',
            RANKX ( ALLEXCEPT ( 'Data', Data[Area] ), [_AuditTime],, DESC ) <= 10
                && [Pass/Fail] = "Fail"
        ),
        [Area]
    )
RETURN
    IF ( MAX ( 'Data'[Area] ) IN _table, "Yes", "No" )

 Note:

       There are some data errors in your sample data. I have corrected the errors when using them.

v-angzheng-msft_0-1623819727833.png

Result:

v-angzheng-msft_1-1623819796955.png

v-angzheng-msft_2-1623819885695.png

Please refer to the attachment below for details

 

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

9 REPLIES 9
v-angzheng-msft
Community Support
Community Support

Hi, @StephenGW 

Try to create 2 measures like below:
_AuditTime:

_AuditTime = MAX('Data'[Audit Time])

Probation:

Probation =
VAR _table =
    SUMMARIZE (
        FILTER (
            'Data',
            RANKX ( ALLEXCEPT ( 'Data', Data[Area] ), [_AuditTime],, DESC ) <= 10
                && [Pass/Fail] = "Fail"
        ),
        [Area]
    )
RETURN
    IF ( MAX ( 'Data'[Area] ) IN _table, "Yes", "No" )

 Note:

       There are some data errors in your sample data. I have corrected the errors when using them.

v-angzheng-msft_0-1623819727833.png

Result:

v-angzheng-msft_1-1623819796955.png

v-angzheng-msft_2-1623819885695.png

Please refer to the attachment below for details

 

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

@v-angzheng-msft 

 

Is there anyway to make it ignore the two slicers I mentioned while keeping the other 2? When I change months it changes the outcome of this measure?

 

Stephen

Hi, @StephenGW 

 

Sorry for not checking the messages in time.
You can add the filter you want to keep in the ALLEXCEPT function

Something like this:

vangzhengmsft_0-1623979107276.png

Hope this is what you want.

 

Best Regards,
Community Support Team _ Zeon Zheng

@v-angzheng-msft 

 

No problem. It works perfectly. Thank you very much!

 

StephenGW

@v-angzheng-msft 

 

That works exactly as I asked. I need to make a small modification that I can't figure out. I have 4 slicers and I would like this measure to ignore 2 of them. I need it to ignore the slicer for Data[Audit Year] and Data[Audit Month] but not ignore the other two. Do you know how I can add that to this measure?

 

Thanks,

Stephen

parry2k
Super User
Super User

@StephenGW It will be easier if you share sample data with the expected output, and if you can share a pbix with sample data even better. Remove any sensitive information before sharing.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anybody got any ideas on this?

 

Thanks

Also if it helps this data comes in from a Power App that I created so that might affect some of the formatting if that affects the measure.

 

StephenGW

@parry2k 

 

Sure I have created a a very simplified sample with sensitive data changed. But when I try to share the pbix it says that file type is not supported. Here is a link to the sample data. https://valmont-my.sharepoint.com/:x:/p/slg_na/EcZbe3m-ChNMhafKmIUOHrABVlZhjOnVCFrc_Shp-eATzA?e=K9Ll... in this sample areas Inside and Underground would be on probation because they have a recent fail with less than 10 passes since the most recent fail. In my BI I would like to have a table that will count how many passes since the most recent fail for each area and if it is less than 10 passes since the fail it would output yes to note that the area is on probation.

 

If you can explain how to upload a pbix I have a sample for this data too but it just has a table with areas in it and a simple chart as well. Drag and drop would not work.

 

StephenGW

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.