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

Previous month value sum based on current month criteria

Hi!

 

I got problem with previous month value count based on current month criteria. I need to count how many of these month ACTIVE clients, was marked as N (New clients) in previous month.

 

Formulas what I used:

New Clients = calculate([Count OF new];PREVIOUSMONTH(COD_DW_MART_AGENT_SCORECARD[FIRST_DAY_OF_MONTH]))

 

Count OF new = CALCULATE(DISTINCTCOUNT(Client_database[Client_ID]);Client_database[CLASSIFICATION2]=N)

 

Problem with these formulas are, that DAX counts not only active clients in these month, but inactive too who was marked as N In previous month. (For example: in previous month there was 12 clients who was market as N, but in these month there has left only 11 of them( I need that DAX calculates only these 11)( Active client means, that on current month client has new record row)

 

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please create measures:

previous status =
CALCULATE (
    MAX ( 'ClientStatus Table'[CLASSIFICATION2] ),
    FILTER (
        ALLSELECTED ( 'ClientStatus Table' ),
        'ClientStatus Table'[Client_ID] = MAX ( 'ClientStatus Table'[Client_ID] )
            && 'ClientStatus Table'[FIRST_DAY_OF_MONTH].[MonthNo]
                = MONTH ( MAX ( 'ClientStatus Table'[FIRST_DAY_OF_MONTH] ) ) - 1
    )
)

Count OF new2 =
CALCULATE (
    DISTINCTCOUNT ( 'ClientStatus Table'[Client_ID] ),
    FILTER (
        ALLSELECTED ( 'ClientStatus Table' ),
        [previous status] = "N"
            && 'ClientStatus Table'[FIRST_DAY_OF_MONTH]
                = SELECTEDVALUE ( 'ClientStatus Table'[FIRST_DAY_OF_MONTH] )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

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

View solution in original post

8 REPLIES 8
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please create measures:

previous status =
CALCULATE (
    MAX ( 'ClientStatus Table'[CLASSIFICATION2] ),
    FILTER (
        ALLSELECTED ( 'ClientStatus Table' ),
        'ClientStatus Table'[Client_ID] = MAX ( 'ClientStatus Table'[Client_ID] )
            && 'ClientStatus Table'[FIRST_DAY_OF_MONTH].[MonthNo]
                = MONTH ( MAX ( 'ClientStatus Table'[FIRST_DAY_OF_MONTH] ) ) - 1
    )
)

Count OF new2 =
CALCULATE (
    DISTINCTCOUNT ( 'ClientStatus Table'[Client_ID] ),
    FILTER (
        ALLSELECTED ( 'ClientStatus Table' ),
        [previous status] = "N"
            && 'ClientStatus Table'[FIRST_DAY_OF_MONTH]
                = SELECTEDVALUE ( 'ClientStatus Table'[FIRST_DAY_OF_MONTH] )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

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

@Anonymous

Can you explain a bit more what an active client is? An example based on your sample data would help

Anonymous
Not applicable

@AlB

 

Data in table is documented on monthly bases. If client in current month has made any purchases than new table row has been created including exact montlhy period information( Year & Month, FIRST_DAY_OF_MONTH) , Client ID, Clasification2 and other column data ( purchase amount etc.(not related to the task))

If in current month client has made purchases and that means that he has current month row, that means clients is ACTIVE in current month. 

If it doesnt have exact month row information it means is wasnt active ( for example, Client 10, in October was active, but not in November)

 

Each client has been clasiffied as "NEW" or "Old" client. Client has statuss "NEW" first 6 months from first purchase ( from first time when client row appeared) after than client clasiffication is changed to "OLD" ( example, client 6, In october was classified as "NEW" But in November it has changed statuss to "OLD")

@Anonymous

 

so an inactive client in a specific month won't have a row? That is the case for client 10 in November that you provide as example but you talk about  "If it doesnt have exact month row information it means is wasnt active" What does that mean exactly? Are there cases where an inactive client in a month WILL have a row in the data?  

Anonymous
Not applicable

 

@AlB

yes, inactive client in a specific month wont have a row.

As about question:"Are there cases where an inactive client in a month WILL have a row in the data?" No, its not possible.

 

Result what I recieve right now :

Untitled123n.png 

As you see only 11 clients in november has been marked as "New clients"  in previous period, but in total is 12 (because there was 12 clients in previous period with statuss "New")

Client 10 isnt in list, because he was inactive in november

AlB
Super User
Super User

Hi @Anonymous

 

Can you share your pbix, with dummy data if necessary? Or at least show the structure of your tables (in table/text format so that they can be readily copied)

Anonymous
Not applicable

Hi @AlB

 

Data structure looks like that:

 

Client_IDYear & MonthFIRST_DAY_OF_MONTHCLASSIFICATION2
12018-102018.10.01. 0:00:00O
22018-102018.10.01. 0:00:00N
32018-102018.10.01. 0:00:00N
42018-102018.10.01. 0:00:00N
52018-102018.10.01. 0:00:00N
62018-102018.10.01. 0:00:00N
72018-102018.10.01. 0:00:00N
82018-102018.10.01. 0:00:00N
92018-102018.10.01. 0:00:00N
102018-102018.10.01. 0:00:00N
112018-102018.10.01. 0:00:00N
122018-102018.10.01. 0:00:00N
132018-102018.10.01. 0:00:00N
12018-112018.11.01. 0:00:00O
62018-112018.11.01. 0:00:00O
82018-112018.11.01. 0:00:00N
42018-112018.11.01. 0:00:00N
32018-112018.11.01. 0:00:00N
22018-112018.11.01. 0:00:00N
52018-112018.11.01. 0:00:00N
72018-112018.11.01. 0:00:00N
92018-112018.11.01. 0:00:00N
112018-112018.11.01. 0:00:00N
132018-112018.11.01. 0:00:00N
122018-112018.11.01. 0:00:00N

 

 

Model consist only from one table

Anonymous
Not applicable

 

HI AIB,

 

PBIX data is in one table, and its structure is similar like that:

 

Client_IDYear & MonthFIRST_DAY_OF_MONTHCLASSIFICATION2
12018-102018.10.01. 0:00:00O
22018-102018.10.01. 0:00:00N
32018-102018.10.01. 0:00:00N
42018-102018.10.01. 0:00:00N
52018-102018.10.01. 0:00:00N
62018-102018.10.01. 0:00:00N
72018-102018.10.01. 0:00:00N
82018-102018.10.01. 0:00:00N
92018-102018.10.01. 0:00:00N
102018-102018.10.01. 0:00:00N
112018-102018.10.01. 0:00:00N
122018-102018.10.01. 0:00:00N
132018-102018.10.01. 0:00:00N
12018-112018.11.01. 0:00:00O
62018-112018.11.01. 0:00:00O
82018-112018.11.01. 0:00:00N
42018-112018.11.01. 0:00:00N
32018-112018.11.01. 0:00:00N
22018-112018.11.01. 0:00:00N
52018-112018.11.01. 0:00:00N
72018-112018.11.01. 0:00:00N
92018-112018.11.01. 0:00:00N
112018-112018.11.01. 0:00:00N
132018-112018.11.01. 0:00:00N
122018-112018.11.01. 0:00:00N

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.