Forum Discussion
Comparing a value across different snapshot weeks in a single table.
- 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 | LinkedInIf this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
- 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 - 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.
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.
- KHSK1 year ago
Advocate I
Thanks, it worked.
- KHSK11 months ago
Advocate I
Appreciate if you could please let me know how we could achieve the same result in Power Query as the DAX is taking too much time to compare and load the waterfall visual I'm trying to display. I have 3 measures using the same logic and the time taken to display a waterfall visual is about 90 secs. I want to reduce it to below 10secs.
- Ashish_Mathur11 months ago
Super User
Hi,
The result of Power Query does not respond to a change in slicers, if at all that is needed.