Forum Discussion

KHSK's avatar
KHSK
Icon for Advocate I rankAdvocate I
1 year ago
Solved

Comparing a value across different snapshot weeks in a single table.

I have a snapshot table and I need to compare whether an Oppty ID in the current week is available in the previous week and derive the Oppty amount if it is unavailable in the previous week. Basicall...
  • pankajnamekar25's avatar
    1 year ago

    Hello KHSK 

    try this measure

     

    Newly Added Amount =

    VAR PrevWeek =

        SELECTEDVALUE('SnapshotTable'[Snapshot Week], 0) -- From Previous Week slicer

     

    VAR CurrWeek =

        SELECTEDVALUE('SnapshotTable (2)'[Snapshot Week], 0) -- From Current Week slicer

     

    VAR PrevIDs =

        CALCULATETABLE (

            VALUES('SnapshotTable'[Oppty ID]),

            'SnapshotTable'[Snapshot Week] = PrevWeek

        )

     

    VAR CurrTable =

        FILTER (

            'SnapshotTable',

            'SnapshotTable'[Snapshot Week] = CurrWeek &&

            NOT 'SnapshotTable'[Oppty ID] IN PrevIDs

        )

     

    RETURN

        SUMX(CurrTable, 'SnapshotTable'[Oppty Amt])

    Thanks,
     Pankaj Namekar | LinkedIn

    If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

  • johnt75's avatar
    1 year ago

    You'll need 2 tables to use in the slicers. You can create them like

    Current Week = DISTINCT( Ops[Snapshot Week] )
    
    Prev Week = DISTINCT( Ops[Snapshot Week] )

    Make sure that these tables are not connected to the main table.

    Create a measure like

    New Amount =
    VAR PrevOps = CALCULATETABLE(
        VALUES(Ops[Oppty ID]),
        TREATAS(
            VALUES('Prev Week'[Snapshot Week]),
            Ops[Snapshot Week]
        )
    )
    VAR CurrentOps = CALCULATETABLE(
        VALUES(Ops[Oppty ID]),
        TREATAS(
            VALUES('Current Week'[Snapshot Week]),
            Ops[Snapshot Week]
        )
    )
    VAR NewOps = EXCEPT(
        CurrentOps,
        PrevOps
    )
    VAR Result = CALCULATE(
        SUM(Ops[Oppty Amt]),
        NewOps,
        TREATAS(
            VALUES('Current Week'[Snapshot Week]),
            Ops[Snapshot Week]
        )
    )
    RETURN
        Result
  • ChiragGarg2512's avatar
    1 year ago
    NewOpptyAmount = 
    VAR CurrentWeek = 10 # Insert SelectedValue(Current Week Slicer)
    VAR PreviousWeek = 8 # Insert SelectedValue(Previous Week Slicer)
    
    VAR CurrentOppties = CALCULATETABLE(
            VALUES(Snapshot[Oppty ID]),
            Snapshot[Snapshot Week] = CurrentWeek
        )
    
    VAR PreviousOppties = CALCULATETABLE(
            VALUES(Snapshot[Oppty ID]),
            Snapshot[Snapshot Week] = PreviousWeek
        )
    
    VAR NewOpptiesOnly = EXCEPT(CurrentOppties, PreviousOppties)
    
    RETURN
    CALCULATE(
        SUM(Snapshot[Oppty Amt])
        , Snapshot[Oppty ID] in NewOpptiesOnly
    )

    Change the column and variable names accordingly.