Best way eliminate rows with multiple status from a count?

macfuller

Board Regular
Joined
Apr 30, 2014
Messages
247
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.

Voucher KeyFirst DateLast DateStatusError
POG_0556221_111/7/1911/9/19ClosedP400
POG_0556221_111/7/1911/11/19OpenR500
POG_0558442_211/8/1911/10/19ClosedE110

<tbody>
</tbody>




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?
 

sadath

Board Regular
Joined
Oct 10, 2004
Messages
241
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
)
)
 

macfuller

Board Regular
Joined
Apr 30, 2014
Messages
247
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.
 

macfuller

Board Regular
Joined
Apr 30, 2014
Messages
247
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?
 

macfuller

Board Regular
Joined
Apr 30, 2014
Messages
247
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?
 

Forum statistics

Threads
1,078,525
Messages
5,340,974
Members
399,401
Latest member
poiter54

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top