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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
nshindel
Frequent Visitor

Rolling 7 day average from calculated field

Hi

 

My data looks like this

 

ID          Date             Eliglble

ABC        9/1/2018      1

DEF        9/1/2018       0

HIJ         9/1/2018       1

LMN       9/2/2018       0

OPQ       9/2/2018       0

RST        9/2/2018       1

 

 

All the IDs are distinct. I am looking for a percentage of IDs that are eligible, over time. That has been solved simply with a new calculated measure 

 

PercentEligible = SUM(DIADOSCE[Eligible]) / COUNT(DIADOSCE[ID])

 

 

From there, I am trying to get a rolling 7 day average, but PBI doesnt seem to handle how to do that on a calculated field. I tried this

7DayAverage = 
CALCULATE(
SUM(DIADOSCE[Eligible]) / COUNT(DIADOSCE[ID]),
DATESINPERIOD(DIADOSCE[Date], LASTDATE(DIADOSCE[Date]),7,DAY)
) 
/
CALCULATE(
DISTINCTCOUNT(DIADOSCE[Date]),
DATESINPERIOD(DIADOSCE[Date], LASTDATE(DIADOSCE[Date]),7,DAY)
)

 

 

and 

 

 

7Day2 = 
AVERAGEX(
DATESINPERIOD(DIADOSCE[Date],LASTDATE(DIADOSCE[Date]),7,DAY),
(SUM(DIADOSCE[Eligible]) / COUNT(DIADOSCE[ID])))

 

Graph looks like this, but i cannot figure out the rolling 7 day eligible percentage.

1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

try adding a Dimension date table and link it to your data table on 1 to many relationships

 

then try this measure

 

 

=
AVERAGEX (
    DATESINPERIOD (
        Dates[Date],
        MAX ( Dates[Date] ),
        -7,
        DAY
    ),
    CALCULATE (
        DIVIDE (
            SUM ( DIADOSCE[ Eliglble] ),
            COUNTROWS ( DIADOSCE )
        )
    )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

4 REPLIES 4
nshindel
Frequent Visitor

Hi

 

My data looks like this

 

ID          Date             Eliglble

ABC        9/1/2018      1

DEF        9/1/2018       0

HIJ         9/1/2018       1

LMN       9/2/2018       0

OPQ       9/2/2018       0

RST        9/2/2018       1

 

 

All the IDs are distinct. I am looking for a percentage of IDs that are eligible, over time. That has been solved simply with a new calculated measure 

 

PercentEligible = SUM(DIADOSCE[Eligible]) / COUNT(DIADOSCE[ID])

 

 

From there, I am trying to get a rolling 7 day average, but PBI doesnt seem to handle how to do that on a calculated field. I tried this

7DayAverage =
CALCULATE(
SUM(DIADOSCE[Eligible]) / COUNT(DIADOSCE[ID]),
DATESINPERIOD(DIADOSCE[Date], LASTDATE(DIADOSCE[Date]),7,DAY)
)
/
CALCULATE(
DISTINCTCOUNT(DIADOSCE[Date]),
DATESINPERIOD(DIADOSCE[Date], LASTDATE(DIADOSCE[Date]),7,DAY)
)

 

 

and 

 

 

7Day2 =
AVERAGEX(
DATESINPERIOD(DIADOSCE[Date],LASTDATE(DIADOSCE[Date]),7,DAY),
(SUM(DIADOSCE[Eligible]) / COUNT(DIADOSCE[ID])))

 

Graph looks like this, but i cannot figure out the rolling 7 day eligible percentage.


Hi @nshindel,

 

Please check the sample as below. If it doesn't meet your requirement, kindly share your excepted result to me,

 

Measure = 
CALCULATE (
    SUM ( Table1[Eliglble] ),
    DATESINPERIOD ( Table1[Date ], MAX ( Table1[Date ] ), -7, DAY )
)
    / CALCULATE (
        COUNTROWS ( Table1 ),
        DATESINPERIOD ( Table1[Date ], MAX ( Table1[Date ] ), -7, DAY )
    )

Capture.PNG

 

For more details, please check the pbix as attached.

 

Regards,

Frank

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

Hi @nshindel,

 

Does that make sense? If so, kindly mark the answer as solution to close the case.


Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
LivioLanzo
Solution Sage
Solution Sage

try adding a Dimension date table and link it to your data table on 1 to many relationships

 

then try this measure

 

 

=
AVERAGEX (
    DATESINPERIOD (
        Dates[Date],
        MAX ( Dates[Date] ),
        -7,
        DAY
    ),
    CALCULATE (
        DIVIDE (
            SUM ( DIADOSCE[ Eliglble] ),
            COUNTROWS ( DIADOSCE )
        )
    )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.