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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
rclay78
Frequent Visitor

How to determine 90 day total based on a column

I am trying to calculate and identify a total for 90 day intervals based on SN and date. I would like to create a new column within this table. The "Total value 90 days" is the column I am attempting to create. Any suggestions would be very much appreciated. Thanks. 

 

 

 

SNDateValueTotal value 90 days
12341/1/20201.5 
12341/30/20202.22.7
12347/5/20202.52.5
123411/1/20202.22.2
11221/2/20201 
11222/14/20203.4 
11223/1/20202.26.6
33454/2/20202.1 
33455/1/20200.52.6
334511/23/20202.52.5
23451/6/20201 
23452/28/28281.52.5
23456/30/20202.5 
23458/4/20200.53
1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

 Hi, @rclay78 

According to your description, it will be a little difficult to complete this requirement.

I finally achieved the result you want by creating 2 auxiliary columns.

Measure1:

_Flag =
VAR _mindate =
    MINX ( FILTER ( ALL ( 'Table' ), [SN] = EARLIER ( [SN] ) ), [Date] )
VAR _datediff =
    DATEDIFF ( _mindate, [Date], DAY )
VAR _lastday =
    CALCULATE (
        MAX ( [Date] ),
        FILTER ( 'Table', [Index] = EARLIER ( [Index] ) - 1 && [SN] = EARLIER ( [SN] ) )
    )
VAR _lastdatediff =
    DATEDIFF ( _lastday, [Date], DAY )
RETURN
    SWITCH (
        TRUE (),
        [Date] = _mindate, 1,
        _datediff > 90, IF ( _lastdatediff > 90, 1, 0 ),
        0
    )

Measure2:

_Group =
CALCULATE (
    SUM ( 'Table'[_Flag] ),
    FILTER ( ALLSELECTED ( 'Table' ), [Index] <= EARLIER ( [Index] ) )
)

Measure3:

_Total value 90 days1 =
VAR _value =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Index] <= EARLIER ( [Index] )
                && [_Group] = EARLIER ( [_Group] )
        )
    )
VAR _maxindex =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER ( 'Table', [_Group] = EARLIER ( [_Group] ) )
    )
RETURN
    IF ( [Index] = _maxindex, _value, BLANK () )

Result:

v-angzheng-msft_0-1619085654547.png

Please refer to the attachment below for details

 

Is this the result you want? Hope this is useful to you

Please feel free to let me know If you have further questions

 

 

Best Regards,
Community Support Team _ Zeon Zheng
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

4 REPLIES 4
v-angzheng-msft
Community Support
Community Support

 Hi, @rclay78 

According to your description, it will be a little difficult to complete this requirement.

I finally achieved the result you want by creating 2 auxiliary columns.

Measure1:

_Flag =
VAR _mindate =
    MINX ( FILTER ( ALL ( 'Table' ), [SN] = EARLIER ( [SN] ) ), [Date] )
VAR _datediff =
    DATEDIFF ( _mindate, [Date], DAY )
VAR _lastday =
    CALCULATE (
        MAX ( [Date] ),
        FILTER ( 'Table', [Index] = EARLIER ( [Index] ) - 1 && [SN] = EARLIER ( [SN] ) )
    )
VAR _lastdatediff =
    DATEDIFF ( _lastday, [Date], DAY )
RETURN
    SWITCH (
        TRUE (),
        [Date] = _mindate, 1,
        _datediff > 90, IF ( _lastdatediff > 90, 1, 0 ),
        0
    )

Measure2:

_Group =
CALCULATE (
    SUM ( 'Table'[_Flag] ),
    FILTER ( ALLSELECTED ( 'Table' ), [Index] <= EARLIER ( [Index] ) )
)

Measure3:

_Total value 90 days1 =
VAR _value =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Index] <= EARLIER ( [Index] )
                && [_Group] = EARLIER ( [_Group] )
        )
    )
VAR _maxindex =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER ( 'Table', [_Group] = EARLIER ( [_Group] ) )
    )
RETURN
    IF ( [Index] = _maxindex, _value, BLANK () )

Result:

v-angzheng-msft_0-1619085654547.png

Please refer to the attachment below for details

 

Is this the result you want? Hope this is useful to you

Please feel free to let me know If you have further questions

 

 

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

HotChilli
Community Champion
Community Champion

The provided data is a bit confusing.  I take it you want the 90 days previous to get the value (including the current value).

1st value should be 1.5

2nd value should be 3.7 and so on

So there are missing and wrong values (also a 2828 year in there).

Do you want to correct and confirm your desired output?

yes, the second value should be 3.7. Sorry for the typos

No, the first value should be blank. I am looking to return the total value of each SN within 90 days. I dont know why that 2828 is there. I doublechecked by spreadsheet, where I copied and pasted, and its 2020 there. Weird. Anyway, that number should be 2020. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.