Your data model first!

Your data model first!

At this end of the year, I thought it’s time for me to bring you a gift!!
It’s a very important subject that I mention to my coworkers and it’s 80% of a success power bi story!

All the focus is on the tech part.

All developers (yes, you are!!), spend a huge amount of time to understand their sources, their transformation, and the magic that happens in their DAX measures!
And, to be honest, that’s normal!

So why this article?

After 1 week, 2 months, or more time, we are very proud of our dataset! (Yes, I’m not talking about reports, but dataset which can be used in many reports)
Our model contains a lot of data, all the information needed is there! But is it easy for an external person to use it? (a User, a colleague, your kids, ..)
Sometimes yes, sometimes no.

Some complexity exists:

  • Too many tables
  • Too many relationships and the difficulty to know the interaction between tables.
  • The model keeps the complexity of the source systems.

But ok! We did a huge work to clean and provide this model! Everything work!! Our users can take 2 or 3 hours and try to understand the logic behind it!

I like to mention it. I love cars!! But I know nothing about it!! Do I need to understand how an engine work to drive a car? It’s a real plus, but not mandatory.

So what do I suggest?

It doesn’t take much time, and it can help you to keep an eye on your goal. (Yes!! Provide a very shiny dataset)
Before every model, I recommend you to draw your model on a sheet of paper.
You already know the information you have to present and how your user group this information. If not, it’s the perfect time to ask your users and write their buzzwords on paper.

Before each project, ask them to present you their job and the different tools they use. It would help you to have a clear view of their logic behind, their needs, and also what’s missing now.
At this point, I only write huge keywords on paper.

When I’m back on my desk, I’m looking at this brainstorming paper, and try to group the different keywords into a logic.
That’s how tables bring to life, and because I’m a Kimball huge fan let’s call them Dimensions!

So now, with these tables you have the user point of view of their data, all the magic (and fun) is to prepare the data to fit in it!
But hey, with Power Query, SQL, it’s just a piece of cake! Isn’t?

In conclusion

Do not jump directly into the source’s data, keep an eye on your expectation first. Ask your users, talk to your colleagues and try to build the model of your dream.
It’s possible! During your development, you may change some tables, and that’s completely normal! But at least, if you keep your original model, everybody will win in the end.

I wish you all the best in your data journey!
What a fun job!!

Power BI Create a Calendar table automatically

Power BI Create a Calendar table automatically

In our models, the best way to deals with dates and DAX intelligence functions is to use a Calendar Table (Dimension). Good news, this table can be created in 2 clicks with Power Query (Transform Data) in Power BI!

Go transform data and right click on Queries to create a new Blank Query

Copy / Paste the following code

let CreateDateTable = (StartDate as date, EndDate as date, optional Culture as nullable text) as table =>
  let
    DayCount = Duration.Days(Duration.From(EndDate - StartDate)),
    Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),
    TableFromList = Table.FromList(Source, Splitter.SplitByNothing()),
    ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}),
    RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}),
    InsertYear = Table.AddColumn(RenamedColumns, "Year", each Date.Year([Date])),
    InsertQuarter = Table.AddColumn(InsertYear, "QuarterOfYear", each Date.QuarterOfYear([Date])),
    InsertMonth = Table.AddColumn(InsertQuarter, "MonthOfYear", each Date.Month([Date])),
    InsertDay = Table.AddColumn(InsertMonth, "DayOfMonth", each Date.Day([Date])),
    InsertDayInt = Table.AddColumn(InsertDay, "DateInt", each [Year] * 10000 + [MonthOfYear] * 100 + [DayOfMonth]),
    InsertMonthName = Table.AddColumn(InsertDayInt, "MonthName", each Date.ToText([Date], "MMMM", Culture), type text),
    InsertCalendarMonth = Table.AddColumn(InsertMonthName, "MonthInCalendar", each (try(Text.Range([MonthName],0,3)) otherwise [MonthName]) & " " & Number.ToText([Year])),
    InsertCalendarQtr = Table.AddColumn(InsertCalendarMonth, "QuarterInCalendar", each "Q" & Number.ToText([QuarterOfYear]) & " " & Number.ToText([Year])),
    InsertDayWeek = Table.AddColumn(InsertCalendarQtr, "DayInWeek", each Date.DayOfWeek([Date])),
    InsertDayName = Table.AddColumn(InsertDayWeek, "DayOfWeekName", each Date.ToText([Date], "dddd", Culture), type text),
    InsertWeekEnding = Table.AddColumn(InsertDayName, "WeekEnding", each Date.EndOfWeek([Date]), type date)
  in
    InsertWeekEnding
in
  CreateDateTable

Choose a start date and an EndDate, click Invoke
That’s it! You have a beautiful calendar table.
Do not forget to mark this table as a data table

Credit: I found this code on internet many years ago and used it in the LazyDAX file. I think I changed it, but I can’t redirect and credit the one who created it. I think it can help you a lot, that’s why I’m sharing it with you 🙂