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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
WBscooby
Helper III
Helper III

Measure to filter table and then aggregate scores

Hi

I have a table of events and event scores. Dummy file attached.

I am trying to create a table which will show aggregate scores for PersonIDs for a given time period.

A person can have several Instance_IDs. I only want to select one instance_ID per personID. The logic for this is to count the most Event with the maximum seriousness. If there is more than one event with the same seriousness, I want to count the most recent Instance_ID by start date.

I have written a measure for this logic and have tested each stage individually. It seems to work. However, I am struggling to then use this to aggregate the scores.

Can anyone help. I need to use this methodology for a number of measures. I can't do this as a calculated column as the date range used needs to be dynamic - sometimes based on a whole year, sometimes quarters.

Thank you

 

Here is my dax code that I essentially need to use to filter the table:

MaxSeriousness =
VAR CountEvents = CALCULATE(
    COUNTROWS('Events'),
    ALLEXCEPT('Events', 'Events'[PersonID])
)
VAR MaxSeriousness = CALCULATE(
    MAX('Events'[Seriousness]),
    ALLEXCEPT('Events', 'Events'[PersonID])
)
VAR CountMostSerious = CALCULATE(
    COUNTROWS('Events'),
    ALLEXCEPT('Events', Events[PersonID]),
    Events[Seriousness] = MaxSeriousness
)
VAR MaxStartDateMostSerious = CALCULATE(
    MAX('Events'[START_DATE]),
    ALLEXCEPT('Events', Events[PersonID]),
    Events[Seriousness] = MaxSeriousness
)

Var Result = IF(
        CountEvents = 1 ||
        (CountMostSerious = 1 && MIN('Events'[Seriousness]) = MaxSeriousness) ||
        (MIN('Events'[Seriousness]) = MaxSeriousness && MIN('Events'[START_DATE]) = MaxStartDateMostSerious),
        1,
        0
    )

RETURN
 
    Result

 

https://url.uk.m.mimecastprotect.com/s/l9H4CZVyXHQD32KHzjqa4?domain=1drv.ms

2 REPLIES 2
v-xuxinyi-msft
Community Support
Community Support

Hi @WBscooby 

 

I can't open your link because of security policy, if I understand correctly, are you trying to find the sum of the scores for which the measure you gave returned a result of 1? If so, try the following formula:

SUMX(FILTER(ALL('YourTableName'), [Result] = 1), [YourScoresName])

 

If you are still having problems, please present the example data and your expected results as screenshots. Thank you for your time and efforts in advance.

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for looking at this @v-xuxinyi-msft

Does this link work?
https://1drv.ms/u/s!Ap6q8W-mvm27hKhFtwCabVyr8U-TDg?e=xYuhPL

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.