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
Anonymous
Not applicable

Return count of customer number and status based on date

I have gone around again and again and cannot solve this problem. I am trying to determine at a specific point in time what the status of a "Customer Number" is. For example, referencing the below table, on 1/1/2011 5835 would be "OPEN". If I move the date to 3/10/2011, it would be "CLOSED".

 

Customer NumberTransaction DateDescriptionNumber
58359/9/2010OPEN

1

58351/20/2011CLOSED2
58354/28/2011OPEN3
58355/26/2011CLOSED4
58356/24/2011

OPEN

5

58358/11/2011

CLOSED

6

58359/1/2011

OPEN

7

58359/19/2011

CLOSED

8

 

I have thousands of these, and ultimately want to know that on X date, the count of open is Y and the count of closed is Z for all "Customer Numbers". 

 

I referenced this thread which is similar, but isn't getting me the results I want primarily because it's using MAX Date for all rows when I want to specify a specific point in time.

 

Any help is appreciated, I have people doing a bunch of work but they don't know how much they're doing or have been doing.

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

HI, @Anonymous 

After my research, you could try this way as below:

Step1:

Create a separate date table to specify a specific point in time. 

Step2:

Create the two measure as below:

count of OPEN =
VAR _table =
    ADDCOLUMNS (
        'Table',
        "_lastdate", CALCULATE (
            MAX ( 'Table'[Transaction Date] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[Customer Number] ),
                'Table'[Transaction Date] <= SELECTEDVALUE ( 'Date'[Date] )
            )
        )
    )
RETURN
    VAR _table2 =
        ADDCOLUMNS (
            _table,
            "Tag", IF ( [_lastdate] = [Transaction Date] && [Description] = "OPEN", 1, 0 )
        )
    RETURN
        SUMX ( _table2, [Tag] )
count of CLOSED = 
VAR _table =
    ADDCOLUMNS (
        'Table',
        "_lastdate", CALCULATE (
            MAX ( 'Table'[Transaction Date] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[Customer Number] ),
                'Table'[Transaction Date] <= SELECTEDVALUE ( 'Date'[Date] )
            )
        )
    )
RETURN
    VAR _table2 =
        ADDCOLUMNS (
            _table,
            "Tag", IF ( [_lastdate] = [Transaction Date] && [Description] = "CLOSED", 1, 0 )
        )
    RETURN
        SUMX ( _table2, [Tag] )

Result:

4.JPG5.JPG

 

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Sorry for the delay, I did not receive a notification.

 

This is very, very close.

For whatever reason, when I select the date it only shows open/closed for that date only. 

 

I've triple checked my math and formulas, but it's not aggregating all the customer numbers that are open and closed status for the given date.

hi, @Anonymous 

I have tested on my sample pbix file, it works well.

If possible, please share your simple sample pbix file with your expected output for us have a test.

You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

 

Best Regards,

Lin

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

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.