0

In one table I have data collected from each Sunday of a month. In another table, I have a different set of data for the same objects, but only collected once a month. Names match up, but I cannot create a relationship because neither column has unique values.

I've managed to have Power BI summarise the data on the same table by cloning each query, creating a unique key from two columns in each, then running the summary on those tables.

I'm wondering if it's possible to aggregate the data from the weekly table into months, then use those monthly values to run operations against the monthly data from the second table.

Additional details:

The weekly table has a list of pumps and the amount of water they've pumped, taken each week. So the first few rows might be:

Date        | Location | Pump    | Pumped Total
-----------------------------------------------
6/11/16     | Here     | Pump A  | 20
13/11/16    | Here     | Pump A  | 35
6/11/16     | There    | Pump B  | 200

No singular column is unique. Date and Pump forms a unique pair, but Power BI doesn't happily work in pairs. Date and Location is not unique, though my example reads that way.

The monthly table contains pumps and the electricity they've used that month. For example:

Location | Pump    | Month | Power Total
----------------------------------------
Here     | Pump A  | Oct   | 3.5
Here     | Pump A  | Nov   | 4
There    | Pump B  | Nov   | 120

Again, Pump and Month is the unique key here.

My wanted end result is a table with headings a bit like

Location | Pump | Month | Pumped Total | Power Total | Power Efficiency

I can rig the dates to line up to the same format, and Power BI will summarise so that I can get Pumped Total and Power Total to show properly, but because Power Efficiency is Pumped / Power, I can't get it to calculate because it needs to summarise the Pumped to use it against the Power.

2
  • 1
    It sounds like you would just need a date table, and an object table (dimension). However, it'd be helpful to have examples of your tables / data, plus desired results, to give a better answer
    – Leonard
    Nov 29, 2016 at 16:26
  • Fair enough. I've added some examples to the OP.
    – Azphreal
    Nov 29, 2016 at 22:16

1 Answer 1

0

Create additional dimension tables

In addition to the weekly & monthly table above, you need 2 (or possibly 3) dimension tables.

  1. A date dimension table, which has a row for each date, and also a column to reflect the month (Oct, Nov).
  2. A Pump dimension table, which has a row for each pump, and also its location (unless a pump can be in more than one location, then you need a separate location table)

The Pump dimension table might look like this (note how Pump A only appears once):

Pump     | Location
---------|---------
Pump A   | Here
Pump B   | There

Add an actual date to the monthly table

Next, you will need a way to relate the Monthly table to the date table. You say you've been able to relate the dates. If not, it might be a simple as converting Nov into the first of the month (1/11/2016) in the monthly table. (Be sure the data type is a type of date though, to match the date table.)

Relate everything together

In your data model, relate the Weekly and Monthly fact tables to the Date and Pump dimension tables. Do not relate the fact tables to each other.

Final Result

Then, you should be able to create a table in Power BI that brings in the Pump information from the Pump table, the Month from the date table, and the Power/Pumped totals from the 2 fact tables which will look like your desired result. (The weekly table will automatically roll up to month because it knows that 6/11 and 13/11 are both Nov).

Caveats

It's important the pump/date information in your final table come from the new dimension tables, not the individual weekly/monthly tables. The weekly pump column knows nothing about monthly pumps. The pump table knows about both weekly & monthly pumps. (I recommend hiding the pump/location/date columns from the weekly/monthly tables so you can't accidentally do this.)

Be aware that if you have multiple years, you'd want to also reflect or filter to the year in your final result (otherwise, it will sum up all the Novembers together).

More reading

This article has more information about the kind of problem you're trying to solve (handling different granularities): http://www.daxpatterns.com/handling-different-granularities/ - there's quite a few other good resources you can find via search too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.