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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculate column average 30 days after min date (not aggregate)

Hi. I have a data table that looks like this where a new row is created every time the user updated their happiness level:

UserIDHappiness LevelDateUpdated
1512/17/19
2612/17/19
3312/17/19
4412/18/19
5812/18/19
112/20/19
171/16/20
221/16/20
331/16/20
39 1/18/20
47

1/17/20

591/17/20

I want to average the happiness level of a cohort on the 30th day AFTER their first(MIN) report (so, cohort of USER IDs 1, 2, and 3 average  on 1/16/20 and user ID 4 and 5 on 1/17/20.) Only the 30th day after each cohort so I wind up with a table like this:

 

start datefirst happiness avg30 days later happiness acg
1/17/19##
1/18/19##

 

I used this to get the initial (MIN) avg happiness level, but cannot figure out how to calculate the same thing 30 days after the MIN. Can you please help? 

OTP2 =
SUMX (
    DISTINCT ( DelOrder[OrderLineID] );
    VAR firstArrivalDate =
        CALCULATE ( MIN ( DelOrder[Orderline Arrival Date] ) )
    RETURN
        CALCULATE (
            SUM ( DelOrder[On Time] );
            FILTER ( DelOrder; DelOrder[Orderline Arrival Date] = firstArrivalDate )
        )
)
    / DISTINCTCOUNT ( DelOrder[OrderLineID] )

 

3 REPLIES 3
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

Could you tell me if your problem has been solved? If it is, kindly mark the helpful answer as a solution if you feel that makes sense. Welcome to share your own solution. More people will benefit from here.

 

Best Regards,

Xue Ding

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

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

This problem has not been solved 

v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

I create two formulas based on your description and formula. Please try and check if it is what you want. If it is not, please share your expected results. Then we will understand clearly and solve it quickly.

Start date = CALCULATE(MIN('Table'[DateUpdated]),ALLEXCEPT('Table','Table'[UserID]))

Happiness Avg = 
VAR total_level =
    CALCULATE (
        SUM ( 'Table'[Happiness Level] ),
        FILTER ( 'Table', 'Table'[DateUpdated] = [Start date] )
    )
VAR count_id =
    DISTINCTCOUNT ( 'Table'[UserID] )
RETURN
    DIVIDE ( total_level, count_id )

30 days later Happiness Avg = 
VAR total_level =
    CALCULATE (
        SUM ( 'Table'[Happiness Level] ),
        FILTER (
            'Table',
            'Table'[DateUpdated] >= [Start date]
                && 'Table'[DateUpdated] <= [Start date] + 30
        )
    )
VAR count_id =
    DISTINCTCOUNT ( 'Table'[UserID] )
RETURN
    DIVIDE ( total_level, count_id )

3.PNG

Please see the attachment below.

 

Best Regards,

Xue Ding

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

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.