Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
VedranR
Frequent Visitor

Counting by clients and by other condition

Hi everyone 🙂

 

I will be happy if someone could solve my problem.

 

I have tabel with historical data:
Date                 ID_clients        Service_active      Service_purchased        Active_days (this I want to calculate!)
1.1.2022                 A                          0                             0                              0
2.1.2022                 A                          1                             1                              1
3.1.2022                 A                          1                             0                              2
4.1.2022                 A                          1                             0                              3
5.1.2022                 A                          1                             1                              1
6.1.2022                 A                          1                             0                              2 
7.1.2022                 A                          1                             0                              3
1.1.2022                 B                          0                             0                              0
2.1.2022                 B                          0                             0                              0
3.1.2022                 B                          1                             1                              1
4.1.2022                 B                          1                             0                              2
5.1.2022                 B                          1                             0                              3
6.1.2022                 B                          1                             0                              4
7.1.2022                 B                          0                             0                              0

Service_active is showing are the service was active in specific date. 1 if is, 0 if is not.
Service_purchased is showing are the service was active in specific date. 1 if is, 0 if is not.
Every client have one row for each day in table.

I want to get calculated columne with data in each row who will representing how many days was services active starting from day when was purchased by clients. The column Active_days representing what I need to. Each time when clients purchase services we start counting active days from 1.

 

If you are missing some information, be free to write me.

 

Thanks in advanced!

Vedran

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @VedranR 

first create this calculated column 

Qty_Purchased =
VAR CurrentDate = Data[Date]
RETURN
    SUMX (
        CALCULATETABLE (
            Data,
            ALLEXCEPT ( Data, Data[ID_clients] ),
            Data[Date] <= CurrentDate
        ),
        Data[Service_purchased]
    )

 

 Then create a second calculated column 

Active_days =
VAR CurrentDate = Data[Date]
RETURN
    SUMX (
        CALCULATETABLE (
            Data,
            ALLEXCEPT ( Data, Data[ID_clients], Data[Qty_Purchased] ),
            Data[Date] <= CurrentDate
        ),
        Data[Service_active]
    )

 

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @VedranR 

first create this calculated column 

Qty_Purchased =
VAR CurrentDate = Data[Date]
RETURN
    SUMX (
        CALCULATETABLE (
            Data,
            ALLEXCEPT ( Data, Data[ID_clients] ),
            Data[Date] <= CurrentDate
        ),
        Data[Service_purchased]
    )

 

 Then create a second calculated column 

Active_days =
VAR CurrentDate = Data[Date]
RETURN
    SUMX (
        CALCULATETABLE (
            Data,
            ALLEXCEPT ( Data, Data[ID_clients], Data[Qty_Purchased] ),
            Data[Date] <= CurrentDate
        ),
        Data[Service_active]
    )

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.