Search code examples
powershellpowerbidax

Creating table based on minute intervals and linking table to Original table


I have successfully loaded a table into Power BI. This table has 52,608 rows and in the index is a value called 'Transaction Date' (table called 'originalDataSet') which represents a 30 Minute interval (format is 2001-03-14 13:30:55 (yyyy-mm-dd hh:nn:ss)) for which I have the dataset built around. This is three years worth of data.

I want to build a Dim_calendar table which mirrors this table and creates different attributes to quickly filter the data i.e. quarters, fiscalYear etc. I believe I have done that but when trying to filter the data, I only get the first 6 months of the data and creates a blank period for the rest of my dated data.

I have created a relationship from 'originalDataSet'[TransactionDate] One to One with 'Dim_calendar'[Value] with cross-filter direction set to Both.

My code is below but I cannot see anything horribly wrong with it - any advice?

Dim_Calendar = 
VAR MinDate = MIN ( 'originalDataSet'[TransactionDate] ) // you can change this to the end date of the data
VAR MaxDate = MAX (  'originalDataSet'[TransactionDate] )+30/24/60// you can change this to the last date of the data
VAR minuteIntervals = 30 // you can change this to what ever interval you want - you could change this to 1440 to be daily.
RETURN
ADDCOLUMNS (
    GENERATESERIES(MinDate,MaxDate, TIME(0,minuteIntervals,0)),
    "Year", YEAR ([Value]),
    "QtrNo",QUARTER([Value]),
    "Quarter",FORMAT([Value], "\QQ"),
    "MonthNo", MONTH ([Value]),
    "Month", FORMAT ( [Value], "MMM" ),
    "Period", FORMAT ( [Value], "MMM" ) & "-" & YEAR ( [Value] ),
    "Interval", (MINUTE([value])+hour([Value])*60)/minuteIntervals+1,
    "PeriodSort", FORMAT ( [Value], "yyyyMM" ),
    "FiscalYear", IF(MONTH ( [Value] ) >= 7, YEAR ( [Value] ) +1, YEAR ( [Value] )))```

Solution

  • I suspect your issue is that your seconds don't line up and the relationship will be done to that grain. I would suggest via Power Query that you transform your Transaction Date to zero the seconds. For example:

    DateTime.From( DateTime.ToText([Transaction Date], "yyyy-MM-dd hh:mm") )
    

    What I would highly recommend is that you split your Transaction Date to a Date Column and a Time Column. Then have a Date Table and a separate Time Table and use these two dimension tables to relate to your Fact table. This will drastically reduce your data model size.