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
mykolasg
New Member

Max date in selected week

Hello

 

i have the following data. Final purpose is to select week and get Balance of that weeks max date. Looking forward to suggestions.

 

DateWeek NumberVendorBalance
2022-01-031Amazon1000
2022-01-041Amazon95
2022-01-051Amazon400
2022-01-061Amazon900
2022-01-071Amazon1500
2022-01-081Amazon1999
2022-01-091Amazon10000
2022-01-102Amazon1000
2022-01-112Amazon95
2022-01-122Amazon400
2022-01-132Amazon900
2022-01-142Amazon1500
2022-01-152Amazon1999
2022-01-162Amazon10000
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @mykolasg ,

 

I think you want to calculate the date of max balance in select week. You can try this code.

Max Date select week =
VAR _SELECT_WEEK =
    SELECTEDVALUE ( 'Dim Week Number'[Week Number] )
VAR _MAX_Balance =
    CALCULATE (
        MAX ( 'Table'[Balance] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Week Number] = _SELECT_WEEK )
    )
VAR _MAX_Date =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Week Number] = _SELECT_WEEK
                && 'Table'[Balance] = _MAX_Balance
        )
    )
RETURN
    _MAX_Date

Result is as below.

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

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @mykolasg ,

 

I think you want to calculate the date of max balance in select week. You can try this code.

Max Date select week =
VAR _SELECT_WEEK =
    SELECTEDVALUE ( 'Dim Week Number'[Week Number] )
VAR _MAX_Balance =
    CALCULATE (
        MAX ( 'Table'[Balance] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Week Number] = _SELECT_WEEK )
    )
VAR _MAX_Date =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Week Number] = _SELECT_WEEK
                && 'Table'[Balance] = _MAX_Balance
        )
    )
RETURN
    _MAX_Date

Result is as below.

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

truptis
Community Champion
Community Champion

Hi @mykolasg ,

Try this:

Result = CALCULATE(LASTNONBLANKVALUE(Tablename[Date], sum(Tablename[Balance])))

 

 @mykolasg please mark this as a solution & hit the thumbs up if it helps you. Thanks.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your desired outcome visualization looks like, but please check the below picture and the attached pbix file.

 

Picture1.png

 

Max date balance: = 
LASTNONBLANKVALUE ( Data[Date], SUM ( Data[Balance] ) )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@mykolasg , Try like

calculate(lastnonblankvalue(Table[Date], sum(Table[Balance])))

 

Use allexcept if needed

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.