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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors