cancel
Showing results 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.

Resolver I

## Group order lines then apply filters

Hello,

I am struggling to get the same answer as the visual I created. I have data that shows order #s broken out by lines. When I create the filter to show orders greater than 250,000, it is filtering order lines by 250,000 and not the order itself. Examples

 Order # Line # Amount 1122 1 50000 1122 2 150000 1122 3 200000 1122 4 50000 2233 1 25000 2233 2 25000

Order 1122 is over 250,000 and order 2233 is not. However, when I filter by order #'s greater than 250,000, it will show none.

I finally went one step at a time and got to this

I made a visual with the same filters as the measure I created. The numbers come out the same.

I then go one step furter and ask it to group the table by order # and only shows orders over 250,000 and I get this

Once I try and add a measure to group the orders by 250,000, the numbers dont match. The visual is correct and I used the filters on the right and just threw the orders in the rows. In the filter on the visual, I said orders greater than 250000.

I can't for the life of me figure out what I am doing wrong.

Any help is appreciated.

Thanks!

1 ACCEPTED SOLUTION
Solution Sage

If its a single table and I have used the data which you shared and the numbers match.

I have uploaded pbix file here, please let me know once you have copied.

The Left table is with filters applied with a simple SUM amount measure.

On the right is Table with measure.

18 REPLIES 18
Solution Sage

hi @jwin2424 ,

Please use this measure, you need to add all the filters in FILTER as well as add these columns in SUMMARIZE.

In screenshot, table on right is my source data.

AmountFilter =
SUMMARIZE( FILTER(Orders, Orders[OnATP] = "Yes" && Filter2 && Filter3.....), Orders[OredrNo], Orders[OnATP], Add filter columns here. ),
"@SumAmt", CALCULATE(SUM(Orders[Amount]))
)

RETURN SUMX( FILTER(_SummTbl, [@SumAmt] > 250000), [@SumAmt])

Resolver I

THANK YOU!!!

That worked. However, can you help with ONE more thing?

Here is the DAX measure:

Orders Over 250k =
VAR _SummTbl =
SUMMARIZE(
FILTER('Backlog Reports', 'Backlog Reports'[On ATP] = "No" && 'Backlog Reports'[PF] <> 2505 && 'Backlog Reports'[Has Fixed Holds] = "Has Fixed Hold" && ('Backlog Reports'[Schedule Category] = "Q2+ 24" || 'Backlog Reports'[Schedule Category] =" Unscheduled")), 'Backlog Reports'[Order #], 'Backlog Reports'[On ATP], 'Backlog Reports'[Has Fixed Holds], 'Backlog Reports'[Schedule Category] ),
"@SumAmt", CALCULATE(SUM('Backlog Reports'[Ext Price-USD]))
)

RETURN SUMX( FILTER(_SummTbl, [@SumAmt] > 250000), [@SumAmt])

However, I can't seem to get the OR statement to apply. I need to filter "Q2+ 24" OR " Unscheduled" and it seems to be only applying the Q2+ 24 filter.

Thanks!
Solution Sage

I see a space before Unscheduled, please confirm if that is correct.

" Unscheduled"

I see that you have not included 'Backlog Reports'[PF] in Summarize which means that it will not be applied as filter when calculating this CALCULATE(SUM('Backlog Reports'[Ext Price-USD]))

Resolver I

The " Unscheduled" indeed has a space before the word. For sake of simplifying things, I wanted to show you just Q2+ 24 for this example:

When I leave out PF, I get the right number as the visual with the exact same filters.

When I add in PF, the numbers in the measure change.

I have also notived another weird thing with the power bi visual and the filters.

I have the fields Customer and Order # in the rows section of the visual with the power bi "Filters on this visual." When I remove Order # from the rows, the total changes.

The total \$5,581,139 is the total I get when I create a pivot in excel with these same filters. I am not sure why adding or removing the order # is changing the result in the visual with the filters on the right. It doesn't affect the measure when i remove the order # (which is what I would expect).

Solution Sage

The problem lies with Measure, since PF has a <> operator, it means all values other than 2505, since one order no can have multiple line items and may be has different PF values, SUMMARIZE and @Sum will calculate sum at grup level and this group includes all the columns that are part of Summarize, so when you add PF total is incorrect.

Please try below measure and let me know. Also I am using single table, if you have multiple tables then it may require modification. Providing explanation with measure in screenshot.

AmountFilter =
-- Group data by Order#
SUMMARIZE( Orders, Orders[OredrNo] ),
"@SumAmt",
--Here I am adding SUM of amount at Order level(I have only used OrderNo in SUMMARIZE so that @SumAMt is calculated at Order level rather than order line item level.)
--I am passing order# to CALCULATE along with all the filters.
VAR _OrderNo = [OredrNo]
RETURN CALCULATE(SUM(Orders[Amount]), REMOVEFILTERS(), Orders[OredrNo] = _OrderNo && Orders[OnATP] = "Yes")
)

--This will remove all orders where SumAmt is <= 350000
--If you place it in card it will give you sum of all the orders, but if you place it in a table with Order#, it will give you sum by Order#
RETURN SUMX( FILTER(_SummTbl, [@SumAmt] > 350000), [@SumAmt])

Resolver I

This is driving me insane. I tried the above, and it isnt working. I have one table and no relationships. Let's see if this helps explain. I have created another single table with less data. Filters are same. You can see in both power bi and excel, when the filters are applied, the totals are the same. When I use the formula, I do not get the same answer.

When I add in the OR filter, nothing changes in the results.

And to show you what happens when I try the new formula you provided

It will not let me paste in my table (which is only 8500 characters) because it says I exceed the 20,0000 character limit for a post. I am going to try and post on a seperate reply.

EDIT: Maybe this will work

I also created a measure for On ATP as follows:

On ATP =
IF(Sheet1[ATP Desc] = BLANK(), "No", "Yes")

Solution Sage

If its a single table and I have used the data which you shared and the numbers match.

I have uploaded pbix file here, please let me know once you have copied.

The Left table is with filters applied with a simple SUM amount measure.

On the right is Table with measure.

Resolver I

I included the OR filter as well, and this worked. I did take out the REMOVEFILTERS () because I did have a date slicer on the page.

Thank you SO much for helping me! This will make a huge imapct for my report.

Solution Sage

You're welcome.

Resolver I

Hopefully this works. You can see the measure itself does not reflect the visual with the same filters applied

Super User

You'll have to upload your pbix file to OneDrive, GoogleDrive, WeTransfer, or Dropbox and copy the link.  Remember to give necessary permissions if required.

Resolver I

Uuuhg looks like my company blocked uploads from those sites. I used to be able to do it from one drive, but for some reason it asked you for a PW. It hasn't done that in the past.

Best I can do is just the visual

The measure results in the above total.

The filters on the visual result in this total. I just want a measure that replicates the filters on the right.

Resolver I

Not sure why it is capturing these orders

Super User

Would it help to change your variable declaration to something like this?

VAR FilteredOrders =
SELECTCOLUMNS(
FILTER(
VALUES( 'Sheet1'[Order # 2] ),
"_sales",
CALCULATE( SUM( 'Sheet1'[Ext Price-USD] ) )
),
[_sales] > 250000
),
"Order # 2",
[Order # 2]
)

Resolver I

Unfortunately, this yielded the same result as mine.

Super User

With a measure like this, you should be able to filter orders over 250K.

Filter Orders over 250K =
VAR _OrderSales =
CALCULATE(
SUM( 'Table'[Amount] ),
ALLEXCEPT(
'Table',
'Table'[Order #]
)
)
VAR _Result =
IF(
_OrderSales > 250000,
1,
0
)
RETURN
_Result

I hope I understood correctly.

Group order lines then apply filters.pbix

Resolver I

Unfortunately that does not work. I need a measure that fulfills these filters.

Where I am struggling is grouping the data by the order # so that the measure applies the filters to order #s over 250000. Right now, it is calculating row by row, and the order #'s are broken down by line #'s. I need the order # to be grouped into one distinct order # THEN apply the remaining filters.

Super User

Is there any way you could come up with a pbix with sample data that covers this issue including the columns to be used as filters ?

Announcements

#### 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

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors