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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Fetch First and Last Date Value based on Date Slicer Selection


Hi ,

 

  For each GL_Account field (100,101 etc) i need to take first and last Posting_Date Row  and copy Opening and Closing value to new columns Opening_New and Closing_New . These Posting_Date values will vary as per Date Slicer Selection.

Example- > For GL_Account  - 100
         First Posting_Date is 10-Apr-2018  so i need to Copy Opening value(1000) to Opening_New column
         Last Posting_Date is 11-Apr-2018  so i need to Copy Closing value(4000) to Closing_New column
         
         For GL_Account  - 101
         First Posting_Date is 10-Apr-2018  so i need to Copy Opening value(6000) to Opening_New column
         Last Posting_Date is 12-Apr-2018  so i need to Copy Closing value(3000) to Closing_New column
        
Capture1.JPG
Capture2.JPG

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

There are many approaches. Since something isn't clear about the data, I created a solid solution. Please download the demo from the attachment.

1. Add an index in the Query Editor.

2. Create two measures.

Opening_New =
VAR minIndex =
    CALCULATE (
        MIN ( Table1[Index] ),
        ALLSELECTED ( Table1[Posting_Date] ),
        ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
    )
RETURN
    IF (
        MIN ( Table1[Index] ) = minIndex,
        CALCULATE ( SUM ( Table1[Opening] ), Table1[Index] = minIndex ),
        0
    )
Closing_New =
VAR maxIndex =
    CALCULATE (
        MAX ( Table1[Index] ),
        ALLSELECTED ( Table1[Posting_Date] ),
        ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
    )
RETURN
    IF (
        MIN ( Table1[Index] ) = maxIndex,
        CALCULATE ( SUM ( Table1[Closing] ), Table1[Index] = maxIndex ),
        0
    )

Fetch-First-and-Last-Date-Value-based-on-Date-Slicer-Selection

 

Best Regards,

Community Support Team _ Dale
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

3 REPLIES 3
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

There are many approaches. Since something isn't clear about the data, I created a solid solution. Please download the demo from the attachment.

1. Add an index in the Query Editor.

2. Create two measures.

Opening_New =
VAR minIndex =
    CALCULATE (
        MIN ( Table1[Index] ),
        ALLSELECTED ( Table1[Posting_Date] ),
        ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
    )
RETURN
    IF (
        MIN ( Table1[Index] ) = minIndex,
        CALCULATE ( SUM ( Table1[Opening] ), Table1[Index] = minIndex ),
        0
    )
Closing_New =
VAR maxIndex =
    CALCULATE (
        MAX ( Table1[Index] ),
        ALLSELECTED ( Table1[Posting_Date] ),
        ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
    )
RETURN
    IF (
        MIN ( Table1[Index] ) = maxIndex,
        CALCULATE ( SUM ( Table1[Closing] ), Table1[Index] = maxIndex ),
        0
    )

Fetch-First-and-Last-Date-Value-based-on-Date-Slicer-Selection

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi,

How to show the actual sum of the last 2 columns  
i.e , Opening_New = 1000 + 6000  = 7000
       Closing_New  =  4000 +3000  = 7000

tempsnip.png

Hi @Anonymous ,

 

Try these two new measures, please.

Opening_New_1 =
VAR minOuterIndex =
    CALCULATE (
        MIN ( Table1[Index] ),
        ALLSELECTED ( Table1[Posting_Date] ),
        ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
    )
RETURN
    IF (
        HASONEVALUE ( Table1[Posting_Date] ),
        IF (
            MIN ( Table1[Index] ) = minOuterIndex,
            CALCULATE ( SUM ( Table1[Opening] ), Table1[Index] = minOuterIndex ),
            0
        ),
        SUMX (
            'Table1',
            VAR minIndex =
                CALCULATE (
                    MIN ( Table1[Index] ),
                    ALLSELECTED ( Table1[Posting_Date] ),
                    ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
                )
            RETURN
                IF (
                    Table1[Index] = minIndex,
                    CALCULATE ( SUM ( Table1[Opening] ), Table1[Index] = minIndex ),
                    0
                )
        )
    )
Closing_New_1 =
VAR maxOuterIndex =
    CALCULATE (
        MAX ( Table1[Index] ),
        ALLSELECTED ( Table1[Posting_Date] ),
        ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
    )
RETURN
    IF (
        HASONEVALUE ( Table1[Posting_Date] ),
        IF (
            MIN ( Table1[Index] ) = maxOuterIndex,
            CALCULATE ( SUM ( Table1[Closing] ), Table1[Index] = maxOuterIndex ),
            0
        ),
        SUMX (
            'Table1',
            VAR maxIndex =
                CALCULATE (
                    MAX ( Table1[Index] ),
                    ALLSELECTED ( Table1[Posting_Date] ),
                    ALLEXCEPT ( Table1, Table1[GL_Account], Table1[Posting_Date] )
                )
            RETURN
                IF (
                    Table1[Index] = maxIndex,
                    CALCULATE ( SUM ( Table1[Closing] ), Table1[Index] = maxIndex ),
                    0
                )
        )
    )

Fetch-First-and-Last-Date-Value-based-on-Date-Slicer-Selection2

 

Best Regards,

 

 

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors