# Can complex (Variance) analysis be done in Einstein Analytics?

## Background

Every month we copy revenue data in our from their original objects (complex normalized tree of related objects) into something we call a snapshot. A denormalized flat table (Custom object) that makes reporting easier.

We then do something quite complex on it - a custom form of Variance Analysis (https://www.accountingtools.com/articles/what-is-variance-analysis.html).

We now think of moving this into Einstein Analytics (EA). Not only because storing all the denormalized data in custom objects is expensive, but also because Apex and Force.com seems a bad reporting platform compared to Wave/Einstein Analytics.

## Question

The idea is to store those snapshot directly as datasets inside of EA. And then

to do ALL of the Variance Analytics. Have you build something complex like this in EA? Or can you point me to more elaborate examples of SAQL usage?

We build unique versions of these calculations regularly. Custom Dataflow Snapshots, and some saql to calculated variance over the periods can be implemented.

These would not be considered complex use cases, but I believe quite standard.

Here is a query example.

``````q = load "Opportunity_Snapshot";
result = group q by ('Snapshot_Date_Year', 'Snapshot_Date_Month');
result = foreach result generate q.'Snapshot_Date_Year' + "~~~" + q.'Snapshot_Date_Month' as 'Snapshot_Date_Year~~~Snapshot_Date_Month', sum(q.'Amount') as 'A';
result = group result by 'Snapshot_Date_Year~~~Snapshot_Date_Month';
result = foreach result generate 'Snapshot_Date_Year~~~Snapshot_Date_Month', sum(A) as 'A', sum(A) - sum(sum(A)) over ([-1..-1] partition by all order by ('Snapshot_Date_Year~~~Snapshot_Date_Month')) as 'B';
result = order result by ('Snapshot_Date_Year~~~Snapshot_Date_Month' asc);
result = limit result 2000;
``````

yeah true, by implementing with EA you can get this snapshot of data everyday, allowing you to improve business. Big advantage is you can schedule the Dataflow run and get the results next min you walk into office.

there are many functions which you can use to calculate the variance and project the data in different trends or groupings.