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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
mihzuk
Frequent Visitor

Value on last date

Hi, 

 

I need a measure that calculates the sum of quantities on the latest available date. This is my example table:

Item1Location1QTY1Date1
AX12.2.2023
CX12.2.2023
CY12.2.2023
B

Z

131.1.2023
AY231.1.2023
AX231.1.2023
CZ130.1.2023
CZ130.1.2023
AX330.1.2023
AY329.1.2023
BY129.1.2023
BZ129.1.2023
CX229.1.2023

 

So the desired output should be:

For example, if I want to see quantities per item for the entire year:

 2023
A1
B0
C2

 

Expected output for all items per date:

 29.1.202330.1.202331.1.20231.2.20232.2.2023
A33401
B20100
C22002

 

Or if only X location is in the filters per date:

 29.1.202330.1.202331.1.20231.2.20232.2.2023
A03201
B00000
C20001

 

Or if I only look at Z location per Month:

 JANFEB
Z10

 

I have tried using LASTNONBLANK() but it gives me the wrong values since my raw table doesn't include rows where the value is 0.
this was my try: 

CALCULATE (
SUM ( QTY1 ),
LASTNONBLANK (
'Table'[Date1],
CALCULATE (
COUNTROWS (  'QTY1' ),
ALLEXCEPT ( ' QTY1', 'Table'[Date1] )
)
)
)
 
Thank you for your help!
5 REPLIES 5
v-weiyan1-msft
Community Support
Community Support

Hi @mihzuk ,

 

Based on the sample and description you provided, You may also consider try the following steps:

1. Please try code as below to Create Calculated column.

Index = RANKX('Table','Table'[Date1],,DESC,Dense)
MonthNumber = MONTH('Table'[Date1])

2. Use the following code to create measures.

Latest QTY =
VAR _Item =
    CALCULATE ( MAX ( 'Table'[Item1] ), FILTER ( 'Table', 'Table'[Index] = 1 ) )
RETURN
    IF (
        _Item IN { "A", "B", "C" },
        CALCULATE ( SUM ( 'Table'[QTY1] ), FILTER ( 'Table', 'Table'[Index] = 1 ) ),
        0
    )
QTY by Item = CALCULATE(SUM('Table'[QTY1]),FILTER('Table','Table'[Date1]))
QTY by Month = CALCULATE(SUM('Table'[QTY1]),FILTER('Table','Table'[MonthNumber]))

Result is as below.

vweiyan1msft_0-1704275165560.png

 

Best Regards,
Yulia Yan

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

Ahmedx
Super User
Super User

you need to create an unrelated table
Screenshot_2.png

you also need to create such a calendar Min and MAX

Screenshot_3.pngScreenshot_4.png

 

Fowmy
Super User
Super User

@mihzuk 

Check the attached PBI file for the meaure and the data model:

Fowmy_0-1703421016872.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

mihzuk
Frequent Visitor

That works great until I put Item as a filter. Then it brings me back to latest QTY that I have in my table. 

 

Example

 

mihzuk_0-1703445609389.png

Latest value should be 0 since there is no QTY on 02.02.2023.
Could you look into that?

 

Thank you!

 

you checked my solution

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors