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
patrickoleary85
Frequent Visitor

Returning rows with a filter set

Hi - I have a table that contains 4 columns, where rows are returned when the value of [Hours} is greater than or equal to the value in [Goal]. To do this, I divide Hours by Goal and set the rows to return if the value in [Column] is greater than or equal to 1.0. 

I want to ONLY show ONE row per value in the [Region] column, the highest. 

 

For example, below, I want to ONLY show the Arizona row with [Hours] = 610.64; and ONLY show the Broward row with [Hours] = 3689.44. I want to show the row with the highest number of Hours for each [Region].

The values in [Hours] are a sum of the hours for that specific week. 

 

Can anyone help me figure this out? I've tried a few measures with MAX but it's not giving me the sum, nor is it giving me only one row. 

Thank you in advance

 

patrickoleary85_1-1667253025948.png

 

 

 

2 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

Hi @patrickoleary85 

 

Download example PBIX file

 

You mention that you've tried a few measures (which are DAX) but you've posted in the Power Query forum so I'm assuming you want a PQ solution.

 

One way to do this is to Group the rows on the Region using the MAX of the Goal Met column (here's my sample data)

grpby1.png

 

Merge the query with itself using the table resulting from the step where you create the Goal Met column.  In my cse this step is called #"Added Custom"

 

= Table.NestedJoin(#"Added Custom", {"Goal Met"}, #"Grouped Rows", {"Goal Met"}, "Grouped Rows", JoinKind.LeftOuter)

 

 

This gives you a column of tables, where there is only data in the table if that row is the max Hours for that Region.

 

nestd-join.png

 

Expand the tables

exptab.png

 

Filter out the nulls and then delete the last column as it is a duplicate of the Goal Met column

fintab.png

 

Here's the query in full but you can see this in my example file (linked above)

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

v-yanjiang-msft
Community Support
Community Support

Hi @patrickoleary85 ,

According to your description "The values in [Hours] are a sum of the hours for that specific week", I think the snapshot you provided is only a visual but not a table data. there's still a date column in which some have the same Week Ending and seperate Hours, then after put the Week Ending column in a visual, the Hours will add up.

Here's my solution, create a measure.

Check =
VAR _T =
    SUMMARIZE (
        ALL ( 'Table' ),
        'Table'[Region],
        'Table'[Week Ending],
        "Hours", SUM ( 'Table'[Hours] )
    )
RETURN
    IF (
        SUM ( 'Table'[Hours] )
            = MAXX ( FILTER ( _T, [Region] = MAX ( 'Table'[Region] ) ), [Hours] ),
        1,
        0
    )

Then put the measure in the visual filter and set to 1

vkalyjmsft_0-1667295032062.png

After apply filter, get the correct result.

vkalyjmsft_1-1667295079330.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @patrickoleary85 ,

According to your description "The values in [Hours] are a sum of the hours for that specific week", I think the snapshot you provided is only a visual but not a table data. there's still a date column in which some have the same Week Ending and seperate Hours, then after put the Week Ending column in a visual, the Hours will add up.

Here's my solution, create a measure.

Check =
VAR _T =
    SUMMARIZE (
        ALL ( 'Table' ),
        'Table'[Region],
        'Table'[Week Ending],
        "Hours", SUM ( 'Table'[Hours] )
    )
RETURN
    IF (
        SUM ( 'Table'[Hours] )
            = MAXX ( FILTER ( _T, [Region] = MAX ( 'Table'[Region] ) ), [Hours] ),
        1,
        0
    )

Then put the measure in the visual filter and set to 1

vkalyjmsft_0-1667295032062.png

After apply filter, get the correct result.

vkalyjmsft_1-1667295079330.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

This worked perfectly, thank you!

PhilipTreacy
Super User
Super User

Hi @patrickoleary85 

 

Download example PBIX file

 

You mention that you've tried a few measures (which are DAX) but you've posted in the Power Query forum so I'm assuming you want a PQ solution.

 

One way to do this is to Group the rows on the Region using the MAX of the Goal Met column (here's my sample data)

grpby1.png

 

Merge the query with itself using the table resulting from the step where you create the Goal Met column.  In my cse this step is called #"Added Custom"

 

= Table.NestedJoin(#"Added Custom", {"Goal Met"}, #"Grouped Rows", {"Goal Met"}, "Grouped Rows", JoinKind.LeftOuter)

 

 

This gives you a column of tables, where there is only data in the table if that row is the max Hours for that Region.

 

nestd-join.png

 

Expand the tables

exptab.png

 

Filter out the nulls and then delete the last column as it is a duplicate of the Goal Met column

fintab.png

 

Here's the query in full but you can see this in my example file (linked above)

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


I attempted this as well, and it worked great. I appreciate it!

Hi @patrickoleary85 

 

Glad that my PQ solution worked too.  Please mark my answer as another solution so that anyone else reading this knows how to solve the problem using Power Query.  This is the PQ forum after all!  🙂

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.

Top Solution Authors
Top Kudoed Authors