Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Delta Calculation strange results

Hi there,   I have two tables in my SQL Server 2017 The CurrentMemberYr produce the expected results but The CurrentMemberBr with the slicer did not as you can see in the attachment How do I fix ...
  • DanielV91's avatar
    8 years ago

    Hello Anonymous

     

    Can you please try the following query and let me know if it works?

     

    SELECT 
    Branch,
    Years,
    CurrentMembers, CASE
    WHEN Branch != LAG(Branch, 1) OVER (ORDER BY Branch, Years) THEN NULL ELSE CurrentMembers - LAG(CurrentMembers,1) OVER (ORDER BY Branch, Years)
    END AS Delta FROM CurrentMemberBr ORDER BY Branch, Years