Best way eliminate rows with multiple status from a count?

macfuller

Active Member
Joined
Apr 30, 2014
Messages
319
Office Version
  1. 365
Platform
  1. Windows
I receive data from our ERP system on vouchers that create errors. I want to have a measure that tells me how many voucher lines were closed within the last week. But... a voucher can create multiple errors - one might be closed during that week, but if the same line has an open error I don't want to count that toward the closed line total.

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Voucher Key[/TD]
[TD]First Date[/TD]
[TD]Last Date[/TD]
[TD]Status[/TD]
[TD]Error[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]POG_0556221_1[/TD]
[TD]11/7/19[/TD]
[TD]11/9/19[/TD]
[TD]Closed[/TD]
[TD]P400[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]POG_0556221_1[/TD]
[TD]11/7/19[/TD]
[TD]11/11/19[/TD]
[TD]Open[/TD]
[TD]R500[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]POG_0558442_2[/TD]
[TD]11/8/19[/TD]
[TD]11/10/19[/TD]
[TD]Closed[/TD]
[TD]E110[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]




As of 11/12/19 these 3 lines would be part of a closed voucher line report.

In this example voucher 0556221 line 1 spun two errors, one of which is closed. All 3 records, 2 voucher lines, have a closed status within the last week, but because 0556221 line 1 still has an open error I don't want to count it as closed for the weekly status. The total of closed lines = 1 for voucher 0558442.

What is the best way to create this measure? I have little experience with UNION and INTERSECT. Perhaps SUMMARIZE based on the voucher key and status for the prior week, getting all voucher line counts then subtracting the count where status = Open?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi
Try this

Test :=
COUNTROWS (
FILTER (
ADDCOLUMNS (
VALUES ( Table1[Voucher Key] ),
"Open", COUNTROWS (
SUMMARIZE (
FILTER ( Table1, Table1[Status] = "OPEN" ),
Table1[Voucher Key],
Table1[First Date]
)
)
),
[Open] = 0
)
)
 
Upvote 0
Sorry for the delay in responding, had to rebuild my date table.

The measure returns blanks for me.

VBA Code:
Test Closed Lines:=COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            VALUES ( 'Match Exception'[ME_Key] ),
            "Open", COUNTROWS (
                SUMMARIZE (
                    FILTER (
                        'Match Exception',
                        'Match Exception'[ME Match Status] = "Open"
                    ),
                    'Match Exception'[ME_Key],
                    'Match Exception'[First Date]
                )
            )
        ),
        [Open] = 0
    )
)

I'll have to parse this in DAX Studio to see what's going on, but it looks worth the effort.
 
Upvote 0
The ADDCOLUMNS "Open" column is returning the total of all Open items in the file rather than the # of open lines for that particular key combination. I've played around a bit but am not sure how to get it to return just a yes/no for whether there are any open lines for that combination. I suppose then I could add another column to get the number of closed lines along the same logic, and finally highlight vouchers that only have a value in the closed column?
 
Upvote 0
OK, I played around with this and got some truly ugly code that returns the right number of rows in DAX Studio based on the number of rows returned. I am creating a table of 3 columns: voucher line, Open , Closed. If there is only a value in the Closed column then I know that no errors remain open against that line and I want to count that.

Code:
=
FILTER (
    ADDCOLUMNS (
        VALUES ( 'Match Exception'[ME_Key] ),
        "Open", COUNTROWS (
            SUMMARIZE (
                VAR MyKey = 'Match Exception'[ME_Key]
                RETURN
                    FILTER (
                        'Match Exception',
                        'Match Exception'[ME Match Status] = "Open"
                            && 'Match Exception'[ME_Key] = MyKey
                            && DATEDIFF (
                                'Match Exception'[Last Date],
                                [Last Match Date],
                                DAY
                            ) <= 7
                    ),
                'Match Exception'[ME_Key]
            )
        ),
        "Closed", COUNTROWS (
            SUMMARIZE (
                VAR MyKey = 'Match Exception'[ME_Key]
                RETURN
                    FILTER (
                        'Match Exception',
                        'Match Exception'[ME Match Status] = "Closed"
                            && 'Match Exception'[ME_Key] = MyKey
                            && DATEDIFF (
                                'Match Exception'[Last Date],
                                [Last Match Date],
                                DAY
                            ) <= 7
                    ),
                'Match Exception'[ME_Key]
            )
        )
    ),
    NOT (
        ISBLANK ( [Closed] )
    )
        && ISBLANK ( [Open] )
)

But... when I wrap a COUNTROWS around it, the measure crashes Excel 2016 64-bit... I mean, total reboot. Is there a way to make this cleaner so that I can get the result I want without dimming the lights in the Midwest?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,847
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top