diff --git a/src/main/java/com/application/DB/DB.java b/src/main/java/com/application/DB/DB.java
index 7e81652b1e392a09bf0160d0daffc9a9d9dbe32c..a2fbb8f3dbb704a512cf8a9bb13eae76a0273d42 100644
--- a/src/main/java/com/application/DB/DB.java
+++ b/src/main/java/com/application/DB/DB.java
@@ -22,7 +22,7 @@ public class DB {
 
     private static Job queryJob;
 
-    private static SimpleDateFormat getDateFormat(){
+    private static SimpleDateFormat getDateFormat() {
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
         return dateFormat;
@@ -100,68 +100,91 @@ public class DB {
 
 
     /**
-     * Retrieves information about kwh and the corresponding date
+     * Retrieves information about kWh and the corresponding date
      *
      * @return the results
      * @throws Exception returns potential error
      */
-    public static Map<String, Number> getKwh() throws Exception {
-
-        /*
-        for (Map.Entry<String, String> entry : getZeroPointDate().entrySet()) {
-            //System.out.printf("Intid: \t%s\t\t\tOuttid: \t%s\n",entry.getKey(),entry.getValue());
-
-            // Preparing a query statement
-            final String sqlStatement = "SELECT TimeStamp, VariantValue " +
-                    "FROM sf-drying-optimization.124.int_sd_winccsensordata " +
-                    "WHERE TimeStamp BETWEEN " + entry.getKey() + " AND " + entry.getValue() +
-                    "ORDER BY TimeStamp ASC";// Preparing a query statement
-
-        }
-
-         */
+    public static Map<Integer, Map> getKwh() throws Exception {
 
         // Initializing the data map to store the results
-        Map<String, Number> data = new HashMap<>();
-
+        Map<Integer, Map> finalResults = new HashMap<>();
 
+        int index = 0;
 
+        /*
         final String sqlStatement = "SELECT TimeStamp, VariantValue " +
                 "FROM sf-drying-optimization.124.int_sd_winccsensordata " +
                 "WHERE TimeStamp BETWEEN \"2021-01-30 08:51:03\" " +
                 "AND \"2021-02-15 11:10:09\" ORDER BY TimeStamp ASC";
+         */
 
+        for (Map.Entry<String, String> entry : getZeroPointDate().entrySet()) {
+            //System.out.printf("Intid: \t%s\t\t\tOuttid: \t%s\n",entry.getKey(),entry.getValue());
 
+            // Initializing the data map to store the results
+            Map<String, Number> data = new HashMap<>();
 
-        // Creates a job configuration
-        queryJob = getJob(QueryJobConfiguration.newBuilder(sqlStatement).build());
+            // Preparing a query statement
+            final String sqlStatement = "SELECT DISTINCT TimeStamp, VariantValue " +
+                    "FROM sf-drying-optimization.124.int_sd_winccsensordata " +
+                    "WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
+                    " AND " + '"' + entry.getValue() + '"' +
+                    " ORDER BY TimeStamp ASC";// Preparing a query statement
 
-        // Iterating through the results
-        TableResult result = queryJob.getQueryResults();
-        System.out.println("Timestamp \t KWh");
-        for (FieldValueList row : result.iterateAll()) {
+            //System.out.println(sqlStatement);
 
-            // Kwh
-            int variantValue = row.get("VariantValue").getNumericValue().intValue();
+            // Creates a job configuration
+            queryJob = getJob(QueryJobConfiguration.newBuilder(sqlStatement).build());
 
-            // Retrieving the wanted data
-            long timeStamp = row.get("TimeStamp").getTimestampValue()/1000;
-            // Riktig format, men i string
-            String formatedTimeStamp = getDateFormat().format(timeStamp);
+            // Iterating through the results
+            TableResult result = queryJob.getQueryResults();
+            //System.out.println("Timestamp \t kWh");
 
-            // Adding the data to a list in order to sort through later
-            data.put(formatedTimeStamp, variantValue);
-        }
+            int baseline = 0;
+            for (FieldValueList row : result.iterateAll()) {
+
+                // Sets the baseline in order to reset the kWh counter
+                if (baseline == 0){
+                    baseline = row.get("VariantValue").getNumericValue().intValue();
+                }
+                //System.out.println("baseline: "+baseline);
+
+                // kWh value
+                int variantValue = row.get("VariantValue").getNumericValue().intValue()-baseline;
 
-        for (Map.Entry<String, Number> entry : data.entrySet()) {
-            System.out.printf("Timestamp: \t%s\t\t\tKWh: \t%s\n",entry.getKey(),entry.getValue());
+                // Retrieving the wanted data
+                long timeStamp = row.get("TimeStamp").getTimestampValue() / 1000;
+                // Riktig format, men i string
+                String formatedTimeStamp = getDateFormat().format(timeStamp);
+
+                // Checks for negative values,
+                if(variantValue > 0){
+                    // Adding the data to a list in order to sort through later
+                    data.put(formatedTimeStamp, variantValue);
+                }
+                //System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\t\t\tBaseline: %s\n",formatedTimeStamp,variantValue,baseline);
+                // Checks if the data is empty
+                }
+            if(!data.isEmpty()) {
+                finalResults.put(index,data);
+                index += 1;
+            }
         }
+        // Defining a treemap to sort through the data
+        NavigableMap<Integer, Map> sortedFinalResults = new TreeMap<>(finalResults);
 
-        return data;
+/*
+        for (Map.Entry<Integer, Map> entry : sortedFinalResults.entrySet()) {
+            System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue());
+        }
+ */
+        return sortedFinalResults;
     }
 
+
     /**
-     * Retrieves information about kwh and the corresponding date
+     * Retrieves information about kWh and the corresponding date
      *
      * @throws Exception returns potential error
      */
@@ -207,7 +230,7 @@ public class DB {
      * This function retrieves the intidtork and uttidtork dates from the database.
      * This variables are not sorted and thus this function iterates through the data in order to
      * find the last intidtork date and the corresponding uttidtork data.
-     * These values will be used to reset the kwh.
+     * These values will be used to reset the kWh.
      *
      * A possible extention of this function could be to limit the number of dring periodes.
      * This could be done with counting the number of entries in
@@ -297,9 +320,9 @@ public class DB {
 
                 // Checks if the next date is longer than 1 day,
                 // if so the current date is the last intidtork date and
-                // is the one we will use in order to reset the kwh.
+                // is the one we will use in order to reset the kWh.
                 if(next.compareTo(formatedDateNowPlus) > 0){
-                    // Storing the dates that will be used for resetting kwh.
+                    // Storing the dates that will be used for resetting kWh.
                     sortedDates.put(inTid,utTid);
                 }
             } catch (NullPointerException e){
@@ -307,6 +330,7 @@ public class DB {
                 break;
             }
         }
-        return sortedDates;
+        // Defining a treemap to sort through the data
+        return new TreeMap<>(sortedDates);
     }
 }
\ No newline at end of file
diff --git a/src/main/java/com/application/Main.java b/src/main/java/com/application/Main.java
index 1413fe7390eb12f506e689565e7767658bbc9e8f..ae1c2ea0eb32cda8b92ad95a8ddacd5e498d615d 100644
--- a/src/main/java/com/application/Main.java
+++ b/src/main/java/com/application/Main.java
@@ -271,7 +271,7 @@ public class Main extends Application {
 
         lineChart.setTitle("Drying Process");
 
-        Map<String, Number> kwh = DB.getKwh();
+        Map<String, Number> kwh  = null;// = DB.getKwh();
         Map<String, Number> sortedKwh = new TreeMap<>(kwh);
 
         XYChart.Series series1 = new XYChart.Series();
diff --git a/target/classes/com/application/DB/DB.class b/target/classes/com/application/DB/DB.class
index ec31148fa1f578a2ce3c089cb84d90f4678287d5..b744148f8c96704565f96a5c617d656f3f84964e 100644
Binary files a/target/classes/com/application/DB/DB.class and b/target/classes/com/application/DB/DB.class differ
diff --git a/target/classes/com/application/Main.class b/target/classes/com/application/Main.class
index fd2fd756630461a11db07cc7f98d510688c791c2..176a777b3e7297135d46851c11538e0bf6703743 100644
Binary files a/target/classes/com/application/Main.class and b/target/classes/com/application/Main.class differ