Forum Discussion

ChristianDGreat's avatar
ChristianDGreat
Resolver I
3 years ago
Solved

Last QTY based on selected date

Hello would it be okay if you can help me on this? I got stucked   So I have this table Product Timestamp Qty A 1-Jan 23 A 2-Jan 123 A 3-Jan 123 A 4-Jan 213 B 1-Jan 1...
  • johnt75's avatar
    johnt75
    3 years ago

    Try

    Qty as at date =
    VAR MaxDate =
        MAX ( 'Date'[Date] )
    VAR SummaryTable =
        ADDCOLUMNS (
            SUMMARIZE ( 'Table', 'Table'[Product], 'Table'[Subtype] ),
            "@qty",
                SELECTCOLUMNS (
                    CALCULATETABLE (
                        TOPN ( 1, 'Table', 'Table'[Timestamp], DESC ),
                        'Date'[Date] <= MaxDate
                    ),
                    "@qty", 'Table'[Qty]
                )
        )
    RETURN
        SUMX ( SummaryTable, [@qty] )