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
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
Super User
Super User

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
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.