Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Number Active between two dates

I have data that comes in similiar to this: 

 

Customer IDCustomer TypeWeekActive
AType 111
AType 121
BType 111
CType 221
DType 111
DType 121
EType 111
EType 121
FType 111
FType 121

 

The active column is calculated at the ETL level and either has a 1 or a 0.  I am specifically wanting to know the number of customers who were active in Week 1 AND Week 2. Please note that the dates could change so I do not want to hardcode the dates.  I have gotten close but can’t quite get it to function for me.  

 

If I pivot the data, you can see that four customers ( A, D, E, F) were active in those two weeks.  

 

Sum of ActiveColumn Labels  
Weeks12Grand Total
A112
B1 1
C 11
D112
E112
F112
Grand Total5510

 

I can't use where the sum is two because you can have decimal values come in.  So I am looking for counts.. Would love help on this. 

11 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      I should clarify that I am trying to solve this in Power BI.  I know how to do this in Excel and SQL But not PBI.

  • Anonymous ofcourse, this is a power bi forum. my question again, is that the output you are looking for?

    • Anonymous's avatar
      Anonymous
      Not applicable

      The ultimate output would result in just the number 4.  I have a measure that calculates the total number of customers in both weeks (6).  I will be using that measure to show number active (4) / total customers (6) = 67%

  • Anonymous to add further that screen shot is from Power BI

  • Anonymous here is the measure that will get you the count of active customers:

     

    Total Active Customers = 
    VAR __totalWeeks = CALCULATE ( COUNTROWS ( VALUES ( Active[Week] ) ), ALLSELECTED () )
    RETURN 
    SUMX ( 
        VALUES ( Active[Customer ID] ), 
        VAR __active = CALCULATE ( COUNTROWS ( Active ), Active[Active] = 1, Active[Week] )
        RETURN IF ( __active >= __totalWeeks, 1 ) 
    )
    

     

    Follow us on LinkedIn

     

    Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Seems close but didn't quite get me to what I was expecting with my dataset.  I was expecting a value in the 20 range and got 800,000.

       

      This gives me 2, which is the correct number of weeks I have selected: 

      CALCULATE ( COUNTROWS ( VALUES ( Active[Week] ) ), ALLSELECTED () )

       

      If I add my detail back in, the measure gives me 33 which is the number of customer ID's displaying.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I got it to work with just a flat Excel file.  Still trying to get it to work in my data model.  

  • Anonymous Good luck Do share your findings once it works. Cheers!!

  • v-luwang-msft's avatar
    v-luwang-msft
    Community Support

    Hi Anonymous ,

    Could you pls show me what output you want ,not very clear.

     

    Best Regards

    Lucien