Best way eliminate rows with multiple status from a count?

macfuller

Active Member
Joined
Apr 30, 2014
Messages
251
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
244
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

Active Member
Joined
Apr 30, 2014
Messages
251
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

Active Member
Joined
Apr 30, 2014
Messages
251
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

Active Member
Joined
Apr 30, 2014
Messages
251
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,082,139
Messages
5,363,364
Members
400,731
Latest member
Jackserver

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top