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

First and last dates and values

Greetings,

 

I need to help to identify the first and last date and values in a table.  Min and Max won't work because the values are a combination of increasing and decreasing amounts.

 

Here is a sample of the table:

CUSTOMER CODEDATEDISCOUNT
A0511/1/20220.2
A0516/1/20220.1
A25112/1/20210.2
B10012/1/20210.05
B1006/1/20220.1
B10111/1/20210.03
B1019/1/20220.08
B10612/1/20210.25
B1065/1/20220.3
B11110/1/20210.1
B1113/1/20220.05
C2133/1/20220.15
C51612/1/20210.25
C5165/1/20220.15

 

Here is the result I looking for:

CUSTOMER CODELAST DATEFIRST DISCOUNTLAST DISCOUNT
A0516/1/20220.20.1
A25112/1/20210.20.2
B1006/1/20220.050.1
B1019/1/20220.030.08
B1065/1/20220.250.3
B1113/1/20220.10.05
C2133/1/20220.150.15
C5165/1/20220.250.15

 

Note: Some of the customers have only one entry, therefore, the first/last discount will be the same value.

 

Thank you in advance!

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try measures as below to create a table visual.

First Discount =
VAR _STARTDATE =
    CALCULATE (
        MIN ( 'Table'[DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[DISCOUNT] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] ),
            'Table'[DATE] = _STARTDATE
        )
    )
Last Discount =
VAR _EndDATE =
    CALCULATE (
        MAX ( 'Table'[DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[DISCOUNT] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] ),
            'Table'[DATE] = _EndDATE
        )
    )

Result is as below.

RicoZhou_0-1661329645047.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try measures as below to create a table visual.

First Discount =
VAR _STARTDATE =
    CALCULATE (
        MIN ( 'Table'[DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[DISCOUNT] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] ),
            'Table'[DATE] = _STARTDATE
        )
    )
Last Discount =
VAR _EndDATE =
    CALCULATE (
        MAX ( 'Table'[DATE] ),
        ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[DISCOUNT] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[CUSTOMER CODE] ),
            'Table'[DATE] = _EndDATE
        )
    )

Result is as below.

RicoZhou_0-1661329645047.png

 

Best Regards,
Rico Zhou

 

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

ddpl
Solution Sage
Solution Sage

@Anonymous 

Hey, Create a new calculated table as per below...

 

Your Need = 
SUMMARIZE(
'Table','Table'[CUSTOMER CODE],
"Last Date", MAX('Table'[DATE]),
"1st Disc", CALCULATE(MAX('Table'[DISCOUNT]),'Table'[DATE]=MIN('Table'[DATE])),
"Last Disc", CALCULATE(MAX('Table'[DISCOUNT]),'Table'[DATE]=MAX('Table'[DATE])))

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.