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
Paulien1989
Advocate II
Advocate II

I need to group rows and exclude rows from a measure: please help

Hi everyone, I have the following data (with abstract ficticious data) from a log book;

 

 

I want 2 things:

 

1. I want to add a group to each row specifying what group that Dimension belongs in, based on its last status; but only when the last status is 2 or 3! So when the last status is 2, the entire dimension should be grouped as "2" on every row. If the last status is 4, then Group should be blank.

 

2. Time 3 is basically AVERAGEX(Time1-Time2). The total average substracts Time2 from Time1 and then divides it by the number of rows, even by a row that has 0. I want to create a measure that results in the total average of (17,5+6+0)/2=11,75 or (2+0)/1=2 (example for dimensions A and B).

 

Please advise.

1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @Paulien1989

 

You may add an index column in query editor first. Then you may get the group and Time3_Total with below measures. Here is the sample file for your reference.

1.

LastIndex = CALCULATE(MAX(Table1[Index]),ALLEXCEPT(Table1,Table1[Dimension]))
LastStatus =
CALCULATE (
    MAX ( Table1[Status] ),
    FILTER ( ALLEXCEPT ( Table1, Table1[Dimension] ), Table1[Index] = [LastIndex] )
)
Group = IF([LastStatus]=3||[LastStatus]=2,[LastStatus])

2.

Time3 = CALCULATE(SUM(Table1[Time1])-SUM(Table1[Time2]))
Count =
CALCULATE (
    COUNTROWS ( Table1 ),
    FILTER ( ALLEXCEPT ( Table1, Table1[Dimension] ), [Time3] <> 0 )
)
Time3_Total =
IF ( HASONEFILTER ( Table1[Time1] ), [Time3], [Time3] / [Count] )

 

Regards,

Cherie

 

 

 

 

Community Support Team _ Cherie Chen
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

1 REPLY 1
v-cherch-msft
Employee
Employee

Hi @Paulien1989

 

You may add an index column in query editor first. Then you may get the group and Time3_Total with below measures. Here is the sample file for your reference.

1.

LastIndex = CALCULATE(MAX(Table1[Index]),ALLEXCEPT(Table1,Table1[Dimension]))
LastStatus =
CALCULATE (
    MAX ( Table1[Status] ),
    FILTER ( ALLEXCEPT ( Table1, Table1[Dimension] ), Table1[Index] = [LastIndex] )
)
Group = IF([LastStatus]=3||[LastStatus]=2,[LastStatus])

2.

Time3 = CALCULATE(SUM(Table1[Time1])-SUM(Table1[Time2]))
Count =
CALCULATE (
    COUNTROWS ( Table1 ),
    FILTER ( ALLEXCEPT ( Table1, Table1[Dimension] ), [Time3] <> 0 )
)
Time3_Total =
IF ( HASONEFILTER ( Table1[Time1] ), [Time3], [Time3] / [Count] )

 

Regards,

Cherie

 

 

 

 

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

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.