YouTube2Text

Data Modeling in Power BI Full Course for Beginners (5 Hours) – From Zero to Hero — Transcript

by Data with Baraa · 67,962 words · 9,104 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hey friends, so now we're going to speak
  2. 0:01about the most important chapter in the
  3. 0:03whole PowerBI, the data moduling.
  4. 0:05Because if data moduling is weak in your
  5. 0:07project, everything else going to suffer
  6. 0:09and fail. So in this chapter, we're
  7. 0:11going to do a full deep dive into data
  8. 0:13moduling in PowerBI, but the right way.
  9. 0:16>> There's a right way to do this.
  10. 0:18>> So I'm going to do it with you carefully
  11. 0:20step by step as usual with the
  12. 0:21fundamentals using sketches and then we
  13. 0:23deep dive as we progress. So now let's
  14. 0:26get started. All right. Right. So now
  15. 0:27let's have a look to the main faces the
  16. 0:29main components in PowerBI. So we start
  17. 0:32by connecting the data from the sources
  18. 0:34and after that we transform it using
  19. 0:36power query and then we build the data
  20. 0:39model and on top of it we write DAX
  21. 0:41calculations. Then the next step we
  22. 0:43start building visuals report and
  23. 0:45dashboard and share it with the others.
  24. 0:47So now by looking to this we have like
  25. 0:49clear separation between like backend
  26. 0:51work and front-end work. But now what
  27. 0:54happened in real PowerBI projects in
  28. 0:56many companies is that people try to
  29. 0:58skip things in the back end and jump
  30. 1:00immediately to the front- end things
  31. 1:02because building visuals are more fun
  32. 1:04right colors, charts, dashboards and it
  33. 1:07is the thing that the end users can see
  34. 1:09from you. So they try to speed up the
  35. 1:11backend process and especially one thing
  36. 1:13they skip the data moduling. So they
  37. 1:16might do some transformations in Power
  38. 1:18Query, build some DAX but the data model
  39. 1:20step it is totally skipped and this is
  40. 1:22my friends where many PowerBI projects
  41. 1:25start to fail over the time. So
  42. 1:27everything in the projects going to
  43. 1:28start be heavy, expensive, slow and hard
  44. 1:30to maintain and I can tell you many
  45. 1:32stories about this at work. I got
  46. 1:34invited many times to save PowerBI
  47. 1:36projects that are suffering and failing.
  48. 1:39So they ask me to review the project and
  49. 1:41suggest fixes in order to save it. And I
  50. 1:43can tell you after reviewing and
  51. 1:45auditing the whole project almost all of
  52. 1:47them are doing the same mistake. They
  53. 1:49are skipping the data moduling. They are
  54. 1:51really huge projects but they rush it.
  55. 1:53So they go immediately from the sources
  56. 1:55and start building visualizations and
  57. 1:57dashboard and over the time they start
  58. 1:59failing. So in many cases we just build
  59. 2:01the data model and save the project. But
  60. 2:03there were some projects where it was
  61. 2:05too late and they died over the time. So
  62. 2:07data modeling is very important and I
  63. 2:09understand why this happens because data
  64. 2:11modeling can feel hard and many courses
  65. 2:13out there they just show you simple star
  66. 2:16schema and they move on to the next
  67. 2:17steps but with me we will not do that
  68. 2:20>> I will not be beat
  69. 2:22up
  70. 2:23>> so now let's start with the mindset and
  71. 2:25understand why data modeling is so
  72. 2:27important and if you skip it everything
  73. 2:28going to fail let's go
  74. 2:30>> let's get the party started
  75. 2:31>> let's get the party started
  76. 2:32>> okay so it start like this someone going
  77. 2:34to ask you for a new report and you
  78. 2:36going to Start connecting the data and
  79. 2:38create one big flat table with all
  80. 2:41columns that are needed. Then you start
  81. 2:43adding some DAX calculations. Build the
  82. 2:45report and then share it with the user.
  83. 2:48So that's it. And this might takes like
  84. 2:50maybe one or to two weeks. At the start
  85. 2:52you're going to feel that everything
  86. 2:53looks fine and you're going to feel that
  87. 2:54you are fast and flexible. But PowerBI
  88. 2:57projects don't stay small. The data
  89. 2:59going to grow. You're going to get more
  90. 3:00requests to extend their report. You're
  91. 3:02going to get more users are using it.
  92. 3:04and you're going to start feeling things
  93. 3:06are getting like out of control because
  94. 3:08this one table my friend it is not a
  95. 3:11data model and it going to cause a lot
  96. 3:13of issues. So now the first issue is all
  97. 3:15about the size. Things might work if you
  98. 3:17have like 10,000 rows you won't feel the
  99. 3:19problem but if the sources are like
  100. 3:21providing 100k or million 10 million
  101. 3:25rows you're going to feel the issue.
  102. 3:26This one table going to get bigger very
  103. 3:29fast because the same information like
  104. 3:31the product name, customer name is
  105. 3:33repeated over and over which going to
  106. 3:35make the whole PowerBI heavy for no good
  107. 3:38reason. Instead of storing the product
  108. 3:40name only once, you are storing it
  109. 3:42thousands or millions of times. So the
  110. 3:45size of your one table going to grow
  111. 3:47very fast. And this going to lead my
  112. 3:49friend to many other issues like the
  113. 3:51performance. And here two things going
  114. 3:53to get slow. First performance issue is
  115. 3:55the load process from the source to
  116. 3:57powerbi. So refreshing the model going
  117. 4:00to move quickly from few minutes into
  118. 4:02half hour or hour. So it's going to be
  119. 4:04painful to bring a new data to the
  120. 4:05powerbi. And the other performance issue
  121. 4:07is the report performance. PowerBI going
  122. 4:10to need more time to scan the one big
  123. 4:12table to build the visualizations, the
  124. 4:14filters and to react to the interaction
  125. 4:17from the end user. So your report going
  126. 4:19to be slow your users going to suffer
  127. 4:21and I can tell you in real projects if
  128. 4:23the report doesn't open in like two or 3
  129. 4:25seconds your users going to say you know
  130. 4:27what the whole project is slow and
  131. 4:29they're going to start complain about
  132. 4:31it. So performance issue going to be
  133. 4:32everywhere. Now we come to another big
  134. 4:34issue the ducks. I met a lot of people
  135. 4:36in projects that think ducks is
  136. 4:38complicated or they are bad at ducks but
  137. 4:40actually this is not the problem. The
  138. 4:42one big table forcing them to write
  139. 4:44complicated formulas and calculations in
  140. 4:46DAX. The rule is very simple. Bad data
  141. 4:48model going to lead to bad complicated
  142. 4:51ducks because of not having a data model
  143. 4:53and having one table. A simple measure
  144. 4:55that should take only one line becomes
  145. 4:5710 lines because you have to twist
  146. 4:59things in order to get the right
  147. 5:01results. So having no model going to be
  148. 5:03the issue for the size, the performance
  149. 5:05and ducks. Now what is the solution is
  150. 5:07of course to build a data model. So that
  151. 5:09means we stop putting everything in one
  152. 5:11big table. We split the data into
  153. 5:14meaningful tables and connect them with
  154. 5:16the relationships. This going to solve
  155. 5:18all those issues because it going to
  156. 5:20make the model smaller. So the same
  157. 5:22product information or the customer
  158. 5:24information will not keep repeating
  159. 5:26because of the sales. So the text is not
  160. 5:28repeated for no reason million of times.
  161. 5:30The size going to stay small and this of
  162. 5:33course means you're going to have good
  163. 5:34performance. So you can load a new data
  164. 5:36to PowerBI. you can refresh faster and
  165. 5:39as well the performance of your reports
  166. 5:41going to be faster. Like for example, if
  167. 5:43you have a slicer in the report, PowerBI
  168. 5:45doesn't have to go and scan one big
  169. 5:47table. Instead, it's going to go and
  170. 5:49read one small dimension table which can
  171. 5:51be way faster to build the visual for
  172. 5:54your users and as well because of having
  173. 5:56relationships between those tables,
  174. 5:58ducks can become easy. So the data model
  175. 6:01and the relationships going to do big
  176. 6:02part of the work and your calculations
  177. 6:04on ducks can become smaller and easier.
  178. 6:07So those are the big wins and the first
  179. 6:09reasons why we need a data model. But
  180. 6:11there is another problem. Now the thing
  181. 6:13is if you skip building solid data
  182. 6:15models and you go with the one table
  183. 6:17this going to lead over the time to very
  184. 6:19bad habit or let's say bad system design
  185. 6:22that going to be the main reason of why
  186. 6:24your project is meant to fail. And by
  187. 6:27the way I saw this in many projects at
  188. 6:29companies. Now the thing is you will not
  189. 6:31build like only one report and that's it
  190. 6:33at companies. You will get requirements
  191. 6:35to build another report, another
  192. 6:37dashboard. And now since you don't have
  193. 6:39a data model and you just build one
  194. 6:41tailored table. This going to lead you
  195. 6:44to build another one table for the new
  196. 6:46requirements for the new reports. So
  197. 6:48you're going to do the whole process
  198. 6:49from the scratch. Connecting data,
  199. 6:51building one table, building one
  200. 6:52dashboard, and then sharing it with a
  201. 6:54user. And this what this design going to
  202. 6:56continue. So you're going to get a new
  203. 6:58requirement for new reports. And you're
  204. 6:59going to do the same thing over and
  205. 7:01over. One table for one report. And my
  206. 7:04friends if your project start looking
  207. 7:06like this one table one report then I
  208. 7:08can tell you this going to be the
  209. 7:10beginning of the end of your project.
  210. 7:12Now let me tell you why. Now for you the
  211. 7:14one that is building the project this
  212. 7:16going to be a nightmare to maintain. So
  213. 7:18let's say that you found an issue in the
  214. 7:20transformations or you want to change
  215. 7:22something because you got a new
  216. 7:23requirement. Now what going to happen?
  217. 7:25You're going to go to all PowerBI files
  218. 7:27and start editing this one table one by
  219. 7:30one. And you're going to try your best,
  220. 7:32of course, to do the same thing over and
  221. 7:34over to have the sync between those
  222. 7:37transformations. But I can tell you this
  223. 7:38is a lost battle because one day you're
  224. 7:41going to forget to update one of them.
  225. 7:43So one small change going to be a lot of
  226. 7:45work for you. It's going to become days
  227. 7:47or weeks until you finish. So really
  228. 7:49hard to maintain. And this going to lead
  229. 7:51as well to another issue. your
  230. 7:53calculations and transformations going
  231. 7:55to start be different from one report to
  232. 7:57another. And this is a big issue not
  233. 7:59only for you but as well for the
  234. 8:01business for the users because now your
  235. 8:03reports are showing different numbers.
  236. 8:05In one report you show the sales as 1.2
  237. 8:07million and another report could show
  238. 8:09the sales 1.4 million. At the end it is
  239. 8:12the same thing. It is a sales but you're
  240. 8:14going to calculate it differently in all
  241. 8:16those files. And I can tell you when
  242. 8:18your users going to start seeing that
  243. 8:20the numbers are not matching, they will
  244. 8:22stop trusting the whole PowerBI project.
  245. 8:24They will not see that the data model is
  246. 8:26wrong. They're going to see okay the
  247. 8:28whole PowerBI tool or let's say the
  248. 8:30whole project is wrong. And this is
  249. 8:32exactly the turning point. This is how
  250. 8:34projects starts to fail to die where
  251. 8:37people stop using the dashboard and they
  252. 8:39go back to their old tools using Excel.
  253. 8:42Now of course the question is what is
  254. 8:43the solution? Of course, building a
  255. 8:45solid data model. Now, the thing is one
  256. 8:48big table is usually built and tailored
  257. 8:50around one reports. But once you start
  258. 8:52thinking in models, you go and start
  259. 8:54building things around the business. So
  260. 8:57you got to say, okay, we need a sales,
  261. 8:59we need products, customers, dates and
  262. 9:01connect them together. You are not
  263. 9:03tailoring anything for a report. You are
  264. 9:05actually building a solid model for the
  265. 9:07business that can answer analytical
  266. 9:09questions. So naturally you're going to
  267. 9:11start reusing this model for multiple
  268. 9:14reports because usually the next reports
  269. 9:17are for the same business. So what I'm
  270. 9:19trying to say here is once you start
  271. 9:20building data models you start thinking
  272. 9:23how this model can serve multiple
  273. 9:26reports and this is a big win if your
  274. 9:28project start looking like this. First
  275. 9:30of all it is easier to maintain. You're
  276. 9:32going to be very fast. So if you found
  277. 9:34any issue or you want to change the
  278. 9:36logic of something you go to one place
  279. 9:38and do that and your change or your fix
  280. 9:41going to affect all the reports so it is
  281. 9:43easy to maintain and not only that this
  282. 9:45going to automatically force standards
  283. 9:47and consistency. So you're going to have
  284. 9:49less chance of having different numbers
  285. 9:52in different reports. So that means your
  286. 9:54projects going to have better chance to
  287. 9:56survive and be solid for many other use
  288. 9:59cases. So this is I'm going to say a
  289. 10:02bigger reason why we need data moduling
  290. 10:04in PowerBI projects. And now we come to
  291. 10:06some reality check or let's say some
  292. 10:08people going to push back on this and
  293. 10:10going to say hey this going to looks
  294. 10:11really good on paper but in real
  295. 10:13projects it will never work because
  296. 10:15different reports have different
  297. 10:17requirements and if everything depends
  298. 10:19on one shared model then changes one
  299. 10:21thing going to become really scary. So
  300. 10:23you're going to feel like I might break
  301. 10:25something if I change the calculation
  302. 10:27because all reports are using it at
  303. 10:29once. Well, I'm going to be honest. This
  304. 10:31is totally fair. This is what's going to
  305. 10:33happen. If you build one giant shared
  306. 10:36data model for everything, we will not
  307. 10:38do that. Of course, you will not build
  308. 10:40for one company, one model. You will be
  309. 10:42creating shared model by subject area,
  310. 10:45by domain. One model for the sales
  311. 10:47reports, one model for the finance,
  312. 10:49another one for the HR report. So,
  313. 10:51you're going to get like a group of
  314. 10:52reports that are using one model. Things
  315. 10:55going to looks like this. For each
  316. 10:56domain, you're going to have multiple
  317. 10:58reports and one model. And if your
  318. 11:00project is getting bigger and bigger,
  319. 11:01you're going to have multiple models. So
  320. 11:03that means we will be in the middle. So
  321. 11:05we will not go and create like one table
  322. 11:07for each report. And at the same time,
  323. 11:09we will not try to force one model for
  324. 11:12the whole company. Now let's have a
  325. 11:14recap why data modeling is important
  326. 11:16because bad modules going to create
  327. 11:18technical problems, very big PowerBI
  328. 11:20files, slow reports, hard to refresh and
  329. 11:24complex ducks. and as well bad moduling
  330. 11:26going to also create project problems,
  331. 11:29repeated work, hard maintenance,
  332. 11:31different KBI numbers and users losing
  333. 11:34trust. So I hope with this you have now
  334. 11:36enough arguments why you have to take
  335. 11:38time to do data moduling. Maybe you have
  336. 11:40to go and now convince one of your
  337. 11:41managers or your project. If you skip
  338. 11:43it, your report might work for now, but
  339. 11:45over the time you have high risks of
  340. 11:47failing. [music]
  341. 11:51So now what is data modeling in PowerBI?
  342. 11:55Now first of all the data model it is a
  343. 11:57structure that describes the business
  344. 11:59data and how the pieces are actually
  345. 12:01related to each others. What this
  346. 12:03exactly means? Now data modeling it is a
  347. 12:06process that looks like this. You're
  348. 12:07going to have a look to your data. It
  349. 12:09could be chaotic inside files, inside
  350. 12:11databases or in one big file. And inside
  351. 12:14it you're going to have like mix of
  352. 12:15business objects, sales, products,
  353. 12:18customers, dates. Now you're going to
  354. 12:19look at it and then decide what is the
  355. 12:22best structure for it. And here you
  356. 12:24decide for two reasons. First for the
  357. 12:26business. So you're going to go and
  358. 12:28start organizing the data into clear
  359. 12:30business objects. Like you're going to
  360. 12:32say okay all the sales data going to go
  361. 12:34in one place. Then you split and take
  362. 12:37all the products in another table. Same
  363. 12:39things for customers and dates. So you
  364. 12:42start splitting your data and put it in
  365. 12:44places based on the business itself. Now
  366. 12:47the second reason why you want to bring
  367. 12:49a structure for it, it is for the tool
  368. 12:51that you are using like for example
  369. 12:53PowerBI. We want to shape the data in a
  370. 12:55way that PowerBI can work efficiently
  371. 12:58and correctly so that you get nice
  372. 13:00response and fast performance. That
  373. 13:02means our goal is to look to the
  374. 13:04original data and think about how to
  375. 13:07reshape it for those two goals. Split it
  376. 13:09into tables based on the business and
  377. 13:12split it in order to get good
  378. 13:14performance for the tool that you are
  379. 13:15using. We are not splitting things
  380. 13:17randomly. We have a plan.
  381. 13:19>> My plan a man pan.
  382. 13:22>> Now the next step in data modeling is to
  383. 13:25decide how to connect those tables with
  384. 13:27relationships. Relationship it is as
  385. 13:29well a description that can explain how
  386. 13:32those tables relate to each others. And
  387. 13:34the final third component in data
  388. 13:36modeling we define the calculation on
  389. 13:39top of the model like the total sales
  390. 13:41the average profits the total number of
  391. 13:43orders number of customers all those
  392. 13:45calculations and in PowerBI we do those
  393. 13:48calculations using DAX. So that means
  394. 13:50the model is not just like one table or
  395. 13:52one object. It is three parts that work
  396. 13:55together. Tables to store the data
  397. 13:57relationships in order to connect those
  398. 14:00tables and calculations in order to
  399. 14:02answer business questions. All right. So
  400. 14:04this is the data moduling and now let's
  401. 14:06go and focus on tables because in data
  402. 14:09modeling tables can have different
  403. 14:11shapes different roles depend on the
  404. 14:13moduling technique. In techniques like
  405. 14:15for example the data vault the tables
  406. 14:17can have the role of hubs links
  407. 14:19satellites bridge. So different like
  408. 14:22let's say styling and in operational
  409. 14:24systems the tables might take the shape
  410. 14:26of an object or let's say play the role
  411. 14:29of relationships and link but in PowerBI
  412. 14:32things a little bit easier because we
  413. 14:34are building for analytical reports and
  414. 14:36the most important moduling style or
  415. 14:39technique it is the dimensional
  416. 14:41moduling. So in this technique the
  417. 14:43tables might take one of those two
  418. 14:44shapes fact tables and the dimension
  419. 14:47tables. And now let's deep dive into
  420. 14:49those two and start with the first one
  421. 14:51the fact table. So what is that? A fact
  422. 14:53table stores business events,
  423. 14:56transactions or activity that we can use
  424. 14:59in order to calculate something. So now
  425. 15:01what this exactly means? Let's have this
  426. 15:03example. So now here we have a sales
  427. 15:05table. Now what we do? We have a deep
  428. 15:07look to the data in order to understand
  429. 15:09the behavior or what this table is
  430. 15:11trying to tell us. Now first of all we
  431. 15:13can see the table is recording something
  432. 15:15that happened to the business and what
  433. 15:17happened here a sale did happen. So
  434. 15:20there is like an event. The second thing
  435. 15:22that you're going to see it might
  436. 15:23include a lot of ids those going to be
  437. 15:26like a link to another thing another
  438. 15:28table. Now another pattern you're going
  439. 15:31to find informations about the date and
  440. 15:33time like an order date an invoice date
  441. 15:36transaction date. So you're going to
  442. 15:37find informations about when this event
  443. 15:40did happen. And the last pattern that
  444. 15:42you're going to find here, we have
  445. 15:44numbers like quantity, sales, discount,
  446. 15:47cost or profit. All those numbers going
  447. 15:49to help us to calculate something. So if
  448. 15:52you see all those together, so an event,
  449. 15:55ids to something else, information about
  450. 15:57the date and time and a lot of numbers,
  451. 16:00then my friend you are looking at a fact
  452. 16:03table. This table is just recording the
  453. 16:05business activity. So this is the first
  454. 16:07type, the fact tables. Now let's talk
  455. 16:09about the second type. We have the
  456. 16:11dimensions. A dimension table stores
  457. 16:14descriptive informations that gives the
  458. 16:16context to the facts. Of course, we have
  459. 16:18to understand what this means. Look at
  460. 16:20this table. It is storing the products
  461. 16:22informations. And you can see each one
  462. 16:24row is actually representing one
  463. 16:27product. So that means the row here is
  464. 16:29not like an event or like we are
  465. 16:31recording something happened. It is just
  466. 16:34describing a business object like the
  467. 16:36product. Now the second thing that
  468. 16:38you're going to notice that we have a
  469. 16:40lot of attributes informations that is
  470. 16:42describing this product like the product
  471. 16:44name, the category, the brand, the
  472. 16:47color, the status. So they are just
  473. 16:49adding more context to the product. And
  474. 16:52now by looking to this you can
  475. 16:53understand those columns are really
  476. 16:55important in reports. So we could use
  477. 16:57one of those columns in order to do data
  478. 17:00filtering in order to focus only on
  479. 17:01small subset or we could use one of
  480. 17:03those informations to make a group of
  481. 17:06numbers in our reports. Like for
  482. 17:08example, we can take the categories and
  483. 17:10we can build something like the sales by
  484. 17:12category. So that means this information
  485. 17:14the category going to help us to group
  486. 17:17up the sales number and this is of
  487. 17:19course the core thing in building
  488. 17:21visualizations and reports. So if you
  489. 17:23have a table like this where we are
  490. 17:25describing one business object like the
  491. 17:28products or maybe the customers and we
  492. 17:31have a lot of columns that are adding
  493. 17:33more and more context and they look
  494. 17:35amazing in order to build a filter or to
  495. 17:37use it in order to group the numbers
  496. 17:39then my friends you are looking at a
  497. 17:41dimension table. So this is exactly what
  498. 17:43we mean with the second type the
  499. 17:45dimensions. All right so now let's
  500. 17:46compare those two quickly side by side.
  501. 17:49The fact tables record what happens.
  502. 17:52Dimension tables describe what happened.
  503. 17:55The core of the facts are usually dates
  504. 17:58and numbers in order to do calculations.
  505. 18:00The core of the dimensions, they are
  506. 18:02usually the labels that we use to
  507. 18:05analyze those numbers. Like for example,
  508. 18:08sales by category. The sales are numbers
  509. 18:10that comes from the fact. But the
  510. 18:12category, it is the label, the context,
  511. 18:15it comes from the dimension. So the fact
  512. 18:18answers what happened. It is like an
  513. 18:20event and transaction. A dimension
  514. 18:23answers who, what, where and when. So it
  515. 18:26is the description, it is the context.
  516. 18:29So actually that's it. Once you
  517. 18:30understand those two then data modeling
  518. 18:32become much easier to understand and as
  519. 18:35well to build. Okay. So now by looking
  520. 18:36back to our data model with that we have
  521. 18:39the two main tables facts and
  522. 18:40dimensions. And now of course the
  523. 18:42question is how to connect them. This of
  524. 18:44course going to lead us to a very famous
  525. 18:47shape called the star schema. A star
  526. 18:49schema means we have a fact table that
  527. 18:52sits in the middle and we have all those
  528. 18:54dimension tables that connect around it.
  529. 18:57So the fact sales is in the middle and
  530. 19:00around it we have a products, customers,
  531. 19:02date, store and look at this, it is
  532. 19:05forming the shape of the star, right?
  533. 19:07That's why we call it star schema. And
  534. 19:10this is our target in data modeling. We
  535. 19:12want to get this shape. And my friends,
  536. 19:14PowerBI just love star schema. It works
  537. 19:17very well with this shape and of course
  538. 19:19you might ask why. Well, there are many
  539. 19:22reasons like for example it gives
  540. 19:24PowerBI a clean way to filter the data.
  541. 19:26So all those dimensions around the fact
  542. 19:29they're going to go and filter the
  543. 19:31central table the fact that holds the
  544. 19:33numbers and of course all those
  545. 19:34relationships going to help PowerBI to
  546. 19:36understand how the filter should move.
  547. 19:39So for example if you are filtering the
  548. 19:41products this has an effect on the
  549. 19:44numbers like for example the sales. Same
  550. 19:46thing if you filter the customers this
  551. 19:48going to automatically filter the sales
  552. 19:50and for all other dimensions. And now
  553. 19:52because of filter logic is so simple DAX
  554. 19:55going to become as well much easier to
  555. 19:57write. So all what you have to write now
  556. 19:59is just like for example the total sales
  557. 20:01is equal to sum of sales. We don't have
  558. 20:04to write any complex DAX calculations
  559. 20:06because we have a clean data model that
  560. 20:08is supporting it. The model already know
  561. 20:11how products customers and dates are
  562. 20:13connected to the sales. So you don't
  563. 20:15have to repeat it in the calculation.
  564. 20:17And not only that as well, it's going to
  565. 20:19make building the visuals much easier
  566. 20:21for you and as well for PowerBI. So
  567. 20:23you're going to have this mental mode in
  568. 20:25your head to say, okay, if I'm building
  569. 20:27the visuals, I need numbers and you go
  570. 20:29immediately to the middle to the fact
  571. 20:31and if you want to group it up by
  572. 20:33something, then you look at the
  573. 20:35dimensions to get a label. Same thing if
  574. 20:37you want to build a slicer, you usually
  575. 20:39go and look to the dimensions. So that
  576. 20:41means star schema gonna gives you a
  577. 20:43clean starting point to build any
  578. 20:45visual. So actually that's it. This is
  579. 20:47the star schema.
  580. 20:48>> So shoot for the stars. Okay. All right.
  581. 20:51>> Fact in the middle dimensions around it.
  582. 20:53Relationships from the dimensions to the
  583. 20:55facts. The facts going to hold the
  584. 20:57activities the numbers the dimension
  585. 21:00going to give the context and the
  586. 21:01filters. So this is exactly why star
  587. 21:03schema is amazing not only for PowerBI
  588. 21:06but as well for other BI tools like for
  589. 21:08example Tableau. And now the thing is we
  590. 21:10don't have only one methods on how to
  591. 21:12module the data for PowerBI but as well
  592. 21:14we have another thing that you might
  593. 21:16hear snowflake schema and the galaxy
  594. 21:19schema. So what are those stuff in real
  595. 21:21projects what might happen that one of
  596. 21:24your dimensions in the star schema start
  597. 21:26getting bigger and bigger over the time.
  598. 21:29Not only you are getting more data and
  599. 21:31rows but as well you are adding more
  600. 21:33columns over the time. So your dimension
  601. 21:35gets really big and here you decide to
  602. 21:37go and split it into two dimensions. So
  603. 21:40now for example instead of having one
  604. 21:42dimension for the products you're going
  605. 21:44to go and split it into two dimensions
  606. 21:46one for the products and one for the
  607. 21:48category. And now what you do after
  608. 21:50splitting usually you go and connect
  609. 21:52them and build relationship between
  610. 21:53them. So that means the relationship is
  611. 21:56not only between the dimension and fact
  612. 21:59but as well you can have it between one
  613. 22:01dimension and another dimension. And
  614. 22:03this might happen to another dimension
  615. 22:05and so on and you start splitting and
  616. 22:07over the time this star schema going to
  617. 22:10looks like a snowflake schema. So it
  618. 22:13looks like snowflake. Now if you work
  619. 22:14with those two and compare them side by
  620. 22:16side you're going to understand that the
  621. 22:18snowflake schema it is more complex. You
  622. 22:20have more relationships to manage. You
  623. 22:23have to write a ducks that is suitable
  624. 22:25for the snowflake. And now PowerBI might
  625. 22:28get a little bit slower because it's
  626. 22:30going to go and connect a lot of tables
  627. 22:32until it reach the fact table. But of
  628. 22:35course on the other hand the snowflake
  629. 22:36going to help you reducing the size of
  630. 22:39the model. So if your PowerBI file is
  631. 22:42really big one, you can go and split it
  632. 22:44and use the snowflake in order to reduce
  633. 22:46the size of it. So I worked with those
  634. 22:48two and I can tell you I try most of the
  635. 22:50time to avoid using the snowflake and
  636. 22:52try as a default to use the star schema
  637. 22:55because it is just simple and only in
  638. 22:58extreme cases I go and split a dimension
  639. 23:00into two and okay we call it now
  640. 23:03snowflake. So snowflake is the second
  641. 23:05type of data modeling but actually we
  642. 23:07have a third one that called galaxy.
  643. 23:09Sounds fancy right?
  644. 23:10>> I say chiao cuz I'm fancy from
  645. 23:13Tallahassee. So what this means now this
  646. 23:15time the dimension is not a problem but
  647. 23:17the fact in many scenarios in real
  648. 23:20projects you will not have like only one
  649. 23:22perfect fact that's going to serve all
  650. 23:24the reports you might end up having more
  651. 23:27than one fact like for example you have
  652. 23:29one for the sales and another one for
  653. 23:31the budget. Now the thing is you need
  654. 23:33both in order to build one big dashboard
  655. 23:35and those two facts are sharing the same
  656. 23:38dimensions like for example fact sales
  657. 23:41is using the dimension product and same
  658. 23:43thing going to happen the fact budget
  659. 23:45going to need as well the dimension
  660. 23:47products. So with this we have the
  661. 23:49product as a shared dimension between
  662. 23:51two facts. So actually that's it. If
  663. 23:53your model going to look like this then
  664. 23:55my friends you have a galaxy. But here
  665. 23:58be very careful. This is very common
  666. 24:00mistake that done in data moduling. We
  667. 24:03never connect the fact tables together.
  668. 24:05They going to get connected through a
  669. 24:07shared dimension. Of course, this is
  670. 24:09very important topic and at the same
  671. 24:11time very advanced. We're going to leave
  672. 24:12it later in the chapters. But now for
  673. 24:14you just have the sounding that we have
  674. 24:16star schema. This is the most common and
  675. 24:19default data modeling that we do in PI
  676. 24:22and analytics. Then we have a snowflake.
  677. 24:24If you have an issue with big dimensions
  678. 24:26and you want to split and normalize, by
  679. 24:29the way, if I say normalize, that means
  680. 24:30we are just splitting big tables into
  681. 24:32smaller tables. And the third one, the
  682. 24:34galaxy, if you have multiple facts that
  683. 24:37are sharing the same dimensions. Now,
  684. 24:39just quick clarification about the terms
  685. 24:41that you might hear in PowerBI projects
  686. 24:43at work. You're going to hear people
  687. 24:44saying data set, semantic model, data
  688. 24:47model. At the end, it is all the same
  689. 24:49data set. It is just an old terminology
  690. 24:52used by Microsoft PowerBI and now they
  691. 24:54are calling it semantic model. The data
  692. 24:56model it's like people like me I use it
  693. 24:58as official term. It is the process not
  694. 25:01only in PowerBI but as well in any like
  695. 25:03platform that you are building that has
  696. 25:05to do with data. So if you hear all
  697. 25:07those terms don't worry about it. Just
  698. 25:09keep this in your head. The report is
  699. 25:11the visual layer and the model is what
  700. 25:14sits behind the report and they can call
  701. 25:16it whatever they want. Okay. So now
  702. 25:18let's do a quick recap for everything
  703. 25:20that we have learned today. A data model
  704. 25:22it is the way that we structure our data
  705. 25:24for two reasons. In order to build
  706. 25:26business objects and as well to make a
  707. 25:28clear structure for the tool that we are
  708. 25:30using like PowerBI it is made of three
  709. 25:33components tables relationships and
  710. 25:36calculations on top of those tables. And
  711. 25:38now since PowerBI is a BI tool
  712. 25:41analytical tool then the tables usually
  713. 25:43have two important roles. Either it's
  714. 25:46going to be a fact table or a dimension.
  715. 25:48Fact table going to record what happens.
  716. 25:50So they are events. Dimensions they
  717. 25:53going to describe what happened. So it
  718. 25:55is the context and it going to help us
  719. 25:57to filter and group the numbers. And
  720. 25:59when we connect the dimensions around
  721. 26:02the fact then we're going to get the
  722. 26:03shape of the star schema. This is the
  723. 26:06foundations of building PowerBI models.
  724. 26:08So everything going to be easy for
  725. 26:10PowerBI in order to filter data and as
  726. 26:12well to write a DAX calculations and if
  727. 26:15one of your dimensions are getting
  728. 26:17bigger we split it into two dimensions
  729. 26:20then we connect them together and with
  730. 26:21that you're going to get the snowflake
  731. 26:23schema or in other scenario if you have
  732. 26:25more than one fact that are sharing the
  733. 26:28same dimension then you have a galaxy.
  734. 26:30All right, my friends. So, with this,
  735. 26:31I'm really happy that now you have a
  736. 26:34solid foundations about data modeling in
  737. 26:36PowerBI in order to start really
  738. 26:38practicing. And this is exactly what
  739. 26:40we're going to do in the next video.
  740. 26:41We're going to take a row table build
  741. 26:43full star schema end to end in order to
  742. 26:45practice all those concepts.
  743. 26:51Hey friends, [music] so now we're going
  744. 26:52to speak about the technical part of
  745. 26:54data modeling in PowerBI. It will not be
  746. 26:56easy. So, I need your full focus. Now
  747. 26:58the thing is PowerBI is very advanced in
  748. 27:00data moduling and as well very
  749. 27:02sensitive. That means not only making a
  750. 27:05bad decision in big topic like how to
  751. 27:07module the data in star schema,
  752. 27:09snowflake and so on could lead to bad
  753. 27:11performance and bad results as well a
  754. 27:14tiny small mistake that you decide in
  755. 27:16the data model like for example the
  756. 27:18cardinality on a relationship between
  757. 27:20two tables could lead to bad numbers and
  758. 27:23bad results. So that's why it is not an
  759. 27:25easy topic to learn and to be honest to
  760. 27:27teach. You have to do a lot of projects
  761. 27:28in order to understand the different
  762. 27:30scenarios and why we do those decisions.
  763. 27:32Now I'm going to do my best to bring all
  764. 27:34the scenarios that I had in my projects
  765. 27:36as a scenarios in this course. So now
  766. 27:38let's get started.
  767. 27:40>> Going speed. Here we go.
  768. 27:43>> All right. So now let's start with the
  769. 27:44foundations in PowerBI. We have all
  770. 27:46those different layers. And we're going
  771. 27:47to focus now into two layers together.
  772. 27:49The module and the visual layer. So
  773. 27:52let's zoom in. The visual layer it is
  774. 27:54the place where you're going to go and
  775. 27:55build your report. So usually you have
  776. 27:57like maybe two tables and you pick one
  777. 27:59of them and start drag and drop to the
  778. 28:01visual to build maybe a table or a
  779. 28:03charts a card and PowerBI going to just
  780. 28:05show the visual. But now what going to
  781. 28:07happen if you go to another table and
  782. 28:10drag and drop inside the same visual.
  783. 28:13Now PowerBI going to say okay but wait
  784. 28:14how I'm going to go and combine those
  785. 28:16two different data from two different
  786. 28:18tables in one visual. So PowerBI need
  787. 28:21from you more infos in order to combine
  788. 28:23the data and we cannot define the logic
  789. 28:26in the visual layer. We have to do it in
  790. 28:28the engine in the previous layer the
  791. 28:31module layer. There we're going to
  792. 28:32define everything the shape of the
  793. 28:34tables how the tables are related to
  794. 28:36each others using relationships the
  795. 28:38cardinality the filtering the
  796. 28:40calculations how the data going to move
  797. 28:42from one table to another define the
  798. 28:45security rules. So PowerBI going to find
  799. 28:47all the rules, all the description about
  800. 28:50how everything is related to each others
  801. 28:53and how PowerBI going to go and deal
  802. 28:55with those two informations in the
  803. 28:56visual. And based of all those
  804. 28:58informations in the module layer,
  805. 29:00PowerBI going to have all the knowledge
  806. 29:02in order to calculate the numbers and
  807. 29:04plot charts in the visual layer. And
  808. 29:07here is the most important thing to
  809. 29:09understand. If the numbers are wrong in
  810. 29:11the visual layer, it is highly likely
  811. 29:13because the rules, the shapes, the
  812. 29:16relationships on the module layers are
  813. 29:18wrong. So bad model going to define bad
  814. 29:21rules that going to lead to bad numbers.
  815. 29:24And of course, my friends, don't expect
  816. 29:25if you make mistakes on the module layer
  817. 29:27that you're going to find big error
  818. 29:29message in the visual in the reports.
  819. 29:31No, mostly the report going to function.
  820. 29:34You're going to see numbers, your
  821. 29:35visuals are working, everything is okay.
  822. 29:37Only if you or your users make zoom in
  823. 29:40and start really checking the numbers,
  824. 29:42they might start seeing those wrong
  825. 29:44numbers. So mostly the mistakes going to
  826. 29:47lead to silent errors that it is really
  827. 29:49hard to find. But don't worry about it.
  828. 29:51We're going to start with the
  829. 29:52foundations. Now it always start like
  830. 29:54this. In my data I have two tables left
  831. 29:56and right. And I'm going to need both of
  832. 29:58them in my reports. And here my friends,
  833. 30:01you have two options, not only one.
  834. 30:02Either you're going to go and combine
  835. 30:04those two tables together into one
  836. 30:07single table like we have done in power
  837. 30:09query by merging the tables into one.
  838. 30:12They are physically now one table. Or
  839. 30:14the other option that you say you know
  840. 30:16what let's just leave them as it is. So
  841. 30:18we will not go to power query and do
  842. 30:19anything. We will just like put a line a
  843. 30:22relationship between those two
  844. 30:24physically they're going to start
  845. 30:25separated from each others but they have
  846. 30:27a relationship between them. So this is
  847. 30:29the first decision that you have to make
  848. 30:30either in barquery you are merging or
  849. 30:33building relationships in the module
  850. 30:35layer. Now of course we are focusing on
  851. 30:37the relationships. So what are they? A
  852. 30:39relationship it is like a contract
  853. 30:41between two tables in order for you to
  854. 30:43define the rules that going to tell
  855. 30:45PowerBI how to filter and how to combine
  856. 30:48the data from those two tables into one
  857. 30:51visual in the front end. And now you
  858. 30:52might say wait you said relationships we
  859. 30:55don't combine data only merging in power
  860. 30:57query we combine. So now we are
  861. 30:59combining actually in relationships. So
  862. 31:01what is going on? What is going on? Now
  863. 31:04let's zoom out again the three layers
  864. 31:06power query module layer and visual
  865. 31:09layer. Now if you merge two tables it's
  866. 31:11going to happen at the beginning in the
  867. 31:13start in the power query. So everything
  868. 31:15going to be merged together the columns
  869. 31:17the rows into one single table. And of
  870. 31:19course in the next layers the module the
  871. 31:21visual you're going to see only one
  872. 31:22single table. So that means combining
  873. 31:25the data happens in very early stage in
  874. 31:28the power query. But now in the other
  875. 31:29side if you go to the module layer and
  876. 31:31build a relationship between those two
  877. 31:33tables they will not get combined. They
  878. 31:35going to stay separated. So that means
  879. 31:38in module and as well in visual layer
  880. 31:40you're going to see the original two
  881. 31:41tables. But only if you go and build a
  882. 31:44chart a visual in the visual layer and
  883. 31:46you start picking data from left and
  884. 31:48right only there the data going to get
  885. 31:50combined and of course not all columns
  886. 31:52not all rows this depends on what you
  887. 31:55picked and what filters you are using.
  888. 31:56Now of course you're going to say okay
  889. 31:58when we combine in power query and when
  890. 32:00we build relationships the rule is very
  891. 32:02simple. If two tables are describing the
  892. 32:04same row like for example you have
  893. 32:06customer info and customer emails
  894. 32:08separated in two different tables then
  895. 32:10no need to build a relationships just go
  896. 32:12and combine them at early stage in the
  897. 32:15power query. But if you have two
  898. 32:16different tables like for example the
  899. 32:18sales and the customers it would be bad
  900. 32:21idea to go and combine them together
  901. 32:23instead build a relationship between
  902. 32:24them. Those are the two options and the
  903. 32:26first decision that you have to make.
  904. 32:27But now we have more things. Now in
  905. 32:29order to build a relationship between
  906. 32:30two tables, you have to define for
  907. 32:32PowerBI three things. First you have to
  908. 32:34define the keys. They are common columns
  909. 32:37between two tables like ids, keys or
  910. 32:40whatever. So that PowerBI know how to
  911. 32:42match the rows between those two tables.
  912. 32:45Without it, PowerBI has no idea how to
  913. 32:47combine the rows. Another thing you have
  914. 32:48to define the cardality. Yes, a fancy
  915. 32:51name. So you have to describe the values
  916. 32:53inside those keys. And here we have two
  917. 32:55options that we have to define for each
  918. 32:57side. It is very simple. One means the
  919. 33:00values are unique. There is no
  920. 33:02repetitions. And other value many means
  921. 33:05the values are repeating. They are not
  922. 33:07unique. And one value can appear
  923. 33:09multiple times. So that means we have
  924. 33:10two options, two sides. That means we
  925. 33:12have four cardinality options. Yes, I
  926. 33:14can do math.
  927. 33:15>> Hey Michael, what's 394
  928. 33:18* 5,912?
  929. 33:21>> Let's see. We have one to one, one to
  930. 33:24many, many to one and the evil and the
  931. 33:26one, the only many to many relationship.
  932. 33:29This is going to be the real sufferer.
  933. 33:31Okay. So let's have very simple example.
  934. 33:33We start with the onetoone relationship.
  935. 33:35So here we have two tables about the
  936. 33:36customers. One has the names, the other
  937. 33:38has the tiers and they are connected
  938. 33:40using the customer ID. Now let's go and
  939. 33:42check the values inside the keys. We can
  940. 33:43see on the left side the keys are
  941. 33:45unique. For each customer we have
  942. 33:47exactly one row. That's why the
  943. 33:49relationship on the left side is one.
  944. 33:51Now let's go and check the right side.
  945. 33:53We have the exact same thing. Values of
  946. 33:55the customer ID is unique. There are no
  947. 33:57duplicates. And as well on the right
  948. 33:59side is going to be one. So that's it.
  949. 34:00This is the one to one relationship. Now
  950. 34:02let's have an example about the one to
  951. 34:04many relationship. So on the left side
  952. 34:06we have the customers again. And on the
  953. 34:08right sides we have the orders. Now same
  954. 34:10thing. We're going to check the values
  955. 34:11inside the keys. On the customers we
  956. 34:13don't have duplicates. So they are all
  957. 34:15unique. But on the right side we have
  958. 34:17duplicates. So for the first customer,
  959. 34:19Maria did place two orders. So on the
  960. 34:22left side it is one. On the right side
  961. 34:24it is many. It exist more than once.
  962. 34:27Let's try out Joan. Same thing. On the
  963. 34:29left side one. On the right side many.
  964. 34:32But of course this is not must. Like for
  965. 34:33example Anna she ordered only once. But
  966. 34:36since we have duplicates from other
  967. 34:37customers this relationship going to be
  968. 34:39one to many. Now the many to one it's
  969. 34:42exactly the same but we just like flip.
  970. 34:44So if the dimension now on the right
  971. 34:45side we say it is many to one
  972. 34:47relationship. So the same thing we are
  973. 34:49just like flipping the sides nothing
  974. 34:50new. Okay. Now we come to the many to
  975. 34:52many relationship and here we have two
  976. 34:54tables. On the left side we have the
  977. 34:55customer segments and on the right side
  978. 34:57we have the orders the sales. Same thing
  979. 34:59they are connected using the customer
  980. 35:01ID. But now if you have a look to this
  981. 35:03you can see the customer ID is not
  982. 35:06anymore unique on the left side. So a
  983. 35:08customer could belong to multiple
  984. 35:10segments and on the right side the fact
  985. 35:12it was normal because a customer could
  986. 35:14order multiple things. So that means if
  987. 35:16I click to one of those customers same
  988. 35:18effect they go and like order multiple
  989. 35:20things but now here is the issue one
  990. 35:22order belongs now to two rows on the
  991. 35:25left side because the customer belong to
  992. 35:27two segments. So that means the left
  993. 35:29side is not anymore one it is many and
  994. 35:32with that we have many to many
  995. 35:35relationship. So we have to define the
  996. 35:37rules on that cardality. Another thing
  997. 35:39that you have to define is the filter
  998. 35:41direction. Now in reporting we filter
  999. 35:43data like crazy and we have to define
  1000. 35:46the direction of how the filter going to
  1001. 35:48move from one table to another and
  1002. 35:50whether it is allowed and in order to
  1003. 35:53control the traffic of the filters we
  1004. 35:55have as well some options. So now again
  1005. 35:57we have this simple example where we
  1006. 35:58have two tables the sales and the
  1007. 36:00segments and for each table we have like
  1008. 36:02an aggregation for the segments we have
  1009. 36:04the total number of segments and here we
  1010. 36:05have the total number of sales. Now one
  1011. 36:07option to define the direction of the
  1012. 36:09filters to say it is single filter from
  1013. 36:12the left to the right. So for example if
  1014. 36:14I go and filter the data for the
  1015. 36:15customer ID you can see the sales is
  1016. 36:18already filtered with the total but as
  1017. 36:20well the right side is filtered. So we
  1018. 36:22have here only two segments. Same thing
  1019. 36:24if I go and filter the data by another
  1020. 36:26customer you can see it always has an
  1021. 36:28effect on the right side. So whatever
  1022. 36:30I'm filtering on the left the filter is
  1023. 36:33going to the right side. But now if I go
  1024. 36:35and start filtering from the right side,
  1025. 36:37you can see okay the table is filtered.
  1026. 36:39We have only two segments. But this
  1027. 36:41filter has no effect on the sales. I'm
  1028. 36:44still seeing the total number of sales.
  1029. 36:46So the filter is not traveling from the
  1030. 36:49right side to the left side. Same thing
  1031. 36:51if I go and select the other customers.
  1032. 36:54You can see the sales table is not
  1033. 36:55affected. Now of course we can do the
  1034. 36:57opposite where we can say single filter
  1035. 36:59from segments to the sales. So this time
  1036. 37:02if I filter on the segments it's going
  1037. 37:04to filter the sales. But now of course
  1038. 37:05if I filter the sales there's no effect
  1039. 37:08on the right side. Now if you say you
  1040. 37:09know what let's have it free for all
  1041. 37:11everything filter everything. For that
  1042. 37:13we're going to use the both. So that
  1043. 37:15means if I'm filtering on the left side
  1044. 37:17the data going to get filtered on the
  1045. 37:19right side. And the same thing if I'm
  1046. 37:20filtering on the right side the data are
  1047. 37:23getting filtered on the left side. So
  1048. 37:25wherever I'm filtering it going to go
  1049. 37:27everywhere. So as you can see my friends
  1050. 37:29with this we can control the behavior of
  1051. 37:31the whole data model how the data is
  1052. 37:33filtered and this has a great effect on
  1053. 37:35the reports. So those are the three
  1054. 37:37rules that we have to define on the
  1055. 37:39relationships the keys cardalities and
  1056. 37:42the filter direction. And guess what we
  1057. 37:44will not do this only between two
  1058. 37:46tables. We have to do it for the whole
  1059. 37:48data model. Each time you connect two
  1060. 37:50tables you have to define those. And if
  1061. 37:52you do it wrong you're going to get
  1062. 37:54wrong results. All right my friends. So
  1063. 37:56now enough with the sketches and the
  1064. 37:58theory. Let's go back to PowerBI and
  1065. 38:00practice. [music]
  1066. 38:04All right, new [music] start blank
  1067. 38:06report and we are on the model view. Of
  1068. 38:08course, what do we need? We need data.
  1069. 38:10So we're going to go and connect a CSV
  1070. 38:12files. Here I have prepared some facts
  1071. 38:14and dimensions. We're going to start
  1072. 38:15with the fact sales. So let's go and
  1073. 38:17load it. As usual, we're going to get a
  1074. 38:19preview. Okay, load. Now you can see we
  1075. 38:22have something new. We have a card
  1076. 38:23inside the model. This is the fact sales
  1077. 38:26and inside it we have a lot of columns.
  1078. 38:28You can go and expand it if you want but
  1079. 38:30if you want to hide all those details
  1080. 38:32you can go and minimize it. So this is
  1081. 38:33our fact. Now if you click on it you're
  1082. 38:35going to find here on the right side
  1083. 38:36some options like for example in the
  1084. 38:38properties you can go and rename your
  1085. 38:40fact. You can go and add a description.
  1086. 38:42We have some synonyms. So we can call it
  1087. 38:44fact sales sales facts and so on. This
  1088. 38:47is important for the PowerBI Q&A. If the
  1089. 38:49user like ask okay give me the sales.
  1090. 38:51PowerBI knows okay the sales means the
  1091. 38:54fact table. Same thing for the row label
  1092. 38:56as well for the Q&A and the last one you
  1093. 38:59can go and define the key column but for
  1094. 39:00now we will not define anything. So as
  1095. 39:02you can see some few metadata about our
  1096. 39:05new table. Now if you go to the advanced
  1097. 39:07this is all about the load modes since
  1098. 39:09it is a file it is an import. Now on the
  1099. 39:11right side in the data pane we have here
  1100. 39:13two tabs the tables. It is a nice way to
  1101. 39:16see the tables and the columns inside
  1102. 39:17it. And if you go to the model, this is
  1103. 39:19another way on how to present the data
  1104. 39:21model for us. Like for example, we can
  1105. 39:23go to the tables over here and we're
  1106. 39:24going to see like a list of all our
  1107. 39:26tables. In our model, we have a lot of
  1108. 39:28things. So we have tables,
  1109. 39:29relationships, we have measures. So here
  1110. 39:31PowerBI tried to group the different
  1111. 39:33things inside our model by topics. With
  1112. 39:36that, you get a nice overview of the
  1113. 39:38whole data model. So this is the
  1114. 39:40interface about modeling in PowerBI. It
  1115. 39:42is really advanced compared to other
  1116. 39:43tools. Now we don't have yet a data
  1117. 39:45model. We have only the fact sales.
  1118. 39:47That's why we're going to go and connect
  1119. 39:49for it another table. Usually, we go and
  1120. 39:51connect a dimension. So, let's go and do
  1121. 39:53that. I'm going to go and pick the
  1122. 39:55dimension customers. All right, let's go
  1123. 39:57and load it. Okay, once it's done, we
  1124. 39:59have a new card inside our data model
  1125. 40:02for the dimension customer and we can
  1126. 40:04move it around, but we keep the fact
  1127. 40:06table in the center. So, we have a new
  1128. 40:08dimension and you can see we have
  1129. 40:10already a relationship between those two
  1130. 40:12tables. So this nice line means those
  1131. 40:15two tables are connected and PowerBI yes
  1132. 40:17do it automatically. Now as a default if
  1133. 40:19you add new table inside the model
  1134. 40:21PowerBI going to go and investigate all
  1135. 40:24the data inside this new table
  1136. 40:26everything the values the uniqueness and
  1137. 40:28as well the column names and once it
  1138. 40:30finds a possibility to connect this new
  1139. 40:33table to the whole model it going to go
  1140. 40:35and do that. So it is a suggestion from
  1141. 40:37PowerBI that is based on the data. It's
  1142. 40:39not like a random guess from PowerBI. Uh
  1143. 40:42this is of course a nice thing if you
  1144. 40:43have small data model but once the model
  1145. 40:46gets bigger and bigger this might be
  1146. 40:48annoying because PowerBI always try to
  1147. 40:50connected to all other tables and what's
  1148. 40:53happen you're going to end up like
  1149. 40:54cleaning up all those relationships and
  1150. 40:56start over from the scratch. So if you
  1151. 40:58have a small model leave it as it is but
  1152. 41:01if you have a big data model you can go
  1153. 41:03to the options and deactivate it. So now
  1154. 41:05in order to learn how to create a
  1155. 41:06relationship, we're going to go and
  1156. 41:07delete this one over here. So if you
  1157. 41:09just select it and hit delete, you can
  1158. 41:11go and remove it. Now in order to
  1159. 41:13recreate it, you have like multiple
  1160. 41:14options. Either you're going to go to
  1161. 41:16the manage relationships over here in
  1162. 41:18the ribon. So if you click on it, you
  1163. 41:20can go over here and start relationship
  1164. 41:21between two tables or what I find like
  1165. 41:24cooler if I go and let me close this.
  1166. 41:26For example, here customer ID, drag and
  1167. 41:28drop it on top of the other column, the
  1168. 41:30customer ID on the fact then release.
  1169. 41:33With that you're going to create a
  1170. 41:34relationship. So now what do we have in
  1171. 41:35this window? You're going to read it
  1172. 41:37from top to bottom. It's very simple. It
  1173. 41:39says okay from table dimension customer.
  1174. 41:41And then you have a nice preview of the
  1175. 41:43data to understand uh the values inside
  1176. 41:45the columns to the table fact sales.
  1177. 41:48Same thing we have a preview. So now
  1178. 41:50what we are doing over here is we are
  1179. 41:51just connecting the tables using the
  1180. 41:53keys. So you can see here it's
  1181. 41:54highlighted customer ID and customer ID.
  1182. 41:57This is of course correct because I
  1183. 41:58dragged and dropped on the correct
  1184. 42:00columns. But if it was wrong, you can go
  1185. 42:01and select another column by just like
  1186. 42:03clicking on the column name. So this I'm
  1187. 42:05saying the key is the customer number
  1188. 42:07from the dimension and the customer ID
  1189. 42:09from the fact. But of course this is not
  1190. 42:11correct. So I'm going to go and switch
  1191. 42:12it back. So this is the first thing that
  1192. 42:14we define. Another thing we define the
  1193. 42:15cardality and here we have four options.
  1194. 42:17Now PowerBI going to target one to many
  1195. 42:20relationship and this is because PowerBI
  1196. 42:22knows the data and it selects the
  1197. 42:24correct one. So this selection is based
  1198. 42:27on the data. But PowerBI has no idea
  1199. 42:29whether this is correct for the business
  1200. 42:31or not. Only you and the business users
  1201. 42:34know the relationship between business
  1202. 42:36objects in the model. So this is not a
  1203. 42:38suggestion about how to connect tables.
  1204. 42:41This is something based on the data that
  1205. 42:43we have inside PowerBI and PowerBI here
  1206. 42:46says okay based on all the values that
  1207. 42:48we see inside the customers this is
  1208. 42:50unique that's why it is one. But the
  1209. 42:52customer ID inside the fact you can see
  1210. 42:54here we have one one it is not unique
  1211. 42:56that's why we have the money. Now of
  1212. 42:58course you can go and force another
  1213. 42:59cardality if you want but PowerBI will
  1214. 43:02not allow it can say no no we have here
  1215. 43:04many so you cannot do that. So we're
  1216. 43:06going to go to the one to many. Now of
  1217. 43:08course if we start from the table fact
  1218. 43:10and then dimension is going to be many
  1219. 43:12to one. It's the same thing of course.
  1220. 43:14So this is about the cardity. Now the
  1221. 43:16last one the filter direction. We can
  1222. 43:18see here we have two options both and
  1223. 43:20single. So if you leave it as both and
  1224. 43:22then let's go and check. So let me save
  1225. 43:24it. So now look at this. We have like an
  1226. 43:26icon on the relationship. It says both
  1227. 43:28direction. And here comes something
  1228. 43:29really important to understand. The best
  1229. 43:31practices in the star schema is like
  1230. 43:34this. The filter should move from the
  1231. 43:36dimension to the fact and not both
  1232. 43:39directions because this going to create
  1233. 43:41something called ambiguity in filtering.
  1234. 43:44That means it going to has like a
  1235. 43:45different effect on another table. We're
  1236. 43:47going to have an example. Don't worry
  1237. 43:48about it for now. Keep it in mind the
  1238. 43:51filter direction is always from
  1239. 43:53dimensions to the center to the facts.
  1240. 43:55So now in order to make this more
  1241. 43:57healthy and to follow the best practices
  1242. 43:58we're going to go to the relationship
  1243. 43:59over here. So either double click on it
  1244. 44:01or actually we can find it on the right
  1245. 44:03side. In the properties we see now
  1246. 44:05informations about the relationship.
  1247. 44:06Same thing but is like more compacted.
  1248. 44:08Now the cross filter going to be single
  1249. 44:11and then apply changes. Now this looks
  1250. 44:13perfect. The filter direction is from
  1251. 44:15the dimension to the fact. And I can
  1252. 44:18tell you if your model looks like this
  1253. 44:20then you are following the best
  1254. 44:21practices. On the dimension side we have
  1255. 44:23the cardality one. On the fact side we
  1256. 44:26have the star. So it is one to many. And
  1257. 44:28the direction is from dimension to
  1258. 44:30facts. Once I see this then I'm going to
  1259. 44:32be happy in the model. So this is how
  1260. 44:34you create a relationship between those
  1261. 44:35two tables. And of course you can see
  1262. 44:37the relationship on the right side over
  1263. 44:39here under the group relationships. We
  1264. 44:42have the new one or you go to manage
  1265. 44:44relationships over here. and you're
  1266. 44:45going to have like a nice overview of
  1267. 44:47all relations in your data model. All
  1268. 44:49right. Now, before we continue, another
  1269. 44:51thing that I usually do once I import a
  1270. 44:53new data, I check whether the ids has
  1271. 44:55this icon. Like for example, here the
  1272. 44:57order ID has like an aggregation sign.
  1273. 45:00Same thing for the product ID, the store
  1274. 45:02ID. Now this icons means PowerBI can go
  1275. 45:05and summarize aggregate this column. And
  1276. 45:08usually we aggregate numbers, right? But
  1277. 45:10there is only one case where it doesn't
  1278. 45:11make sense and that is for the ids. We
  1279. 45:14don't go and find the average of ids or
  1280. 45:16go and summarize all the values or
  1281. 45:18something like that. Let me just show
  1282. 45:20you what I mean. If you go to the report
  1283. 45:22view and let's go to the fact sales then
  1284. 45:24grab the order ID over here. So what
  1285. 45:27this tells us the sum of order ID 10k
  1286. 45:30but this is not useful information. The
  1287. 45:32only thing that we want to do with the
  1288. 45:33order ID is to count it. How many orders
  1289. 45:36do we have? But we don't need the sum or
  1290. 45:38the average. And this auto aggregation
  1291. 45:40is really annoying thing because
  1292. 45:41sometimes I would like to see the row
  1293. 45:43data in the front end and always Barbie
  1294. 45:45I go and aggregate it. That's why what I
  1295. 45:47do I go to those ids on the facts or in
  1296. 45:50the dimensions. I click on it and then
  1297. 45:52go over here and say don't summarize. So
  1298. 45:55don't do that. And with that PowerBI
  1299. 45:57will not do that anymore. So let's go
  1300. 45:59and try. I'm going to go and drag the
  1301. 46:01order ID in the middle. Look at this.
  1302. 46:02Now I see the IDs and this is perfect.
  1303. 46:05So usually I go and do this for all ids
  1304. 46:08in the facts so that I don't have this
  1305. 46:10issue. It is again luxury thing that we
  1306. 46:12do but it is important because usually
  1307. 46:14as we are building the data model we
  1308. 46:16have always to go to the report view and
  1309. 46:18verify whether everything is correct.
  1310. 46:20All right. So now what we're going to do
  1311. 46:21next is that as we do data modeling we
  1312. 46:24would like always to understand the
  1313. 46:25behavior on the reports. So we test
  1314. 46:27things in order to understand whether
  1315. 46:29this is exactly what we expect. And I
  1316. 46:31usually do it like this. After doing few
  1317. 46:33things in the model, I go back to the
  1318. 46:35report view and start testing. Like for
  1319. 46:37example, I'm going to go and add one
  1320. 46:38visual only for the facts and another
  1321. 46:41one only for the customers. So here for
  1322. 46:43example, I go usually with the table and
  1323. 46:45I'm going to go and add an order ID,
  1324. 46:47maybe a customer ID, line total. So only
  1325. 46:50few columns and then I add a card for
  1326. 46:53the fact table. So the total sales and
  1327. 46:55after that for each table I make like an
  1328. 46:57aggregation in order to see how things
  1329. 46:59change like the total sales. So same
  1330. 47:02thing I'm going to go and duplicate it
  1331. 47:03but this time it's going to be only from
  1332. 47:06the customer dimension. So the customer
  1333. 47:08ID first name last name. So that's it.
  1334. 47:11And as well a card this time it's going
  1335. 47:13to be the total number of customers. As
  1336. 47:15you can see it's like I'm building the
  1337. 47:16model again but on the front end. Now
  1338. 47:19let's go and test the filtering. Right.
  1339. 47:21So now if you just click one of those
  1340. 47:22values you're going to see the table
  1341. 47:24customer is filtering actually the fact
  1342. 47:27table. Now it's all about the customer
  1343. 47:29ID one. Same thing if I click on Anna,
  1344. 47:32I'm filtering the whole fact table. So
  1345. 47:34that means anything that I'm filtering
  1346. 47:36on the right side, it has a direct
  1347. 47:38effect on the facts. Now let's deselect
  1348. 47:40and do the opposite. We start selecting
  1349. 47:42things from the facts and see whether it
  1350. 47:44has an effect on the customers. Like for
  1351. 47:46example, the first order. If I click on
  1352. 47:48it, look at this. Nothing happened to
  1353. 47:50the right side. I still have five
  1354. 47:52customers. So it doesn't matter what I'm
  1355. 47:54like filtering from the fact it has no
  1356. 47:56effect on the right side. So that's
  1357. 47:58because it is in one direction. Now
  1358. 48:00let's go and test the both. If I go over
  1359. 48:02here and select the relationship say
  1360. 48:05both apply. Now let's test the report.
  1361. 48:09It is already filtering the customers.
  1362. 48:11So now since I'm filtering on the order
  1363. 48:13ID 8 has the customer three. This has an
  1364. 48:16effect on the total number of customers
  1365. 48:18and the visual. And same thing if I go
  1366. 48:20and start like clicking around it has a
  1367. 48:23full the filter is moving from the fact
  1368. 48:26back to the dimension. And of course
  1369. 48:27this is not a good thing. Now of course
  1370. 48:29you might say why it's not good. It is
  1371. 48:31correct. Like here we are just selecting
  1372. 48:33or filtering one order. It is good
  1373. 48:35information that we have only one
  1374. 48:37customer for this one order. Well this
  1375. 48:39is okay if you have one fact one
  1376. 48:40dimension. But once you start getting a
  1377. 48:43lot of dimensions they going to start
  1378. 48:45filtering each others and it's going to
  1379. 48:47be full cows. Of course to understand
  1380. 48:48this effect we have to go and add
  1381. 48:50another dimension. And this is exactly
  1382. 48:53what we're going to do now. We're going
  1383. 48:54to go and extend the data model with a
  1384. 48:56new dimension. So let's go and get my
  1385. 48:58friends the dimension products. So let's
  1386. 49:01go and load it. Then say load. Now we
  1387. 49:04got a new dimension. It is here the
  1388. 49:06dimension product. So I will just make
  1389. 49:08the fact in the middle surrounded with
  1390. 49:10the dimensions. But now why PowerBI
  1391. 49:13didn't create a relationship between
  1392. 49:15those two tables. Now let's go and
  1393. 49:17create the relationship by drag and drop
  1394. 49:19the product ID on the product ID. And
  1395. 49:21now we can see here we have an issue.
  1396. 49:23This relationship has cardinality many
  1397. 49:25to many. So here PowerBI is saying there
  1398. 49:27is something issue with the product ID.
  1399. 49:29Now by looking to the examples you can
  1400. 49:31see one two three like we cannot see any
  1401. 49:33issue here. At the end it is just a
  1402. 49:35preview like only few rows. But our goal
  1403. 49:38is of course to connect it with the
  1404. 49:39product ID. Now let's go and try to
  1405. 49:41force it to be one to many like we have
  1406. 49:44done for the customer. So one from the
  1407. 49:46product and many to the facts. It says
  1408. 49:49no. It even doesn't allow us to save it.
  1409. 49:51It says the product ID in the dimension
  1410. 49:53product contain duplicates the value
  1411. 49:56six. So this is not really unique my
  1412. 49:58friends. So what we're going to do we're
  1413. 50:00going to switch it back to menu to many
  1414. 50:01in order for PowerBI to allow us to save
  1415. 50:03it. And then we have to dig into this
  1416. 50:06issue. Now let's go and save this. Look
  1417. 50:08at this. Between the products and the
  1418. 50:10facts we have many to many. And again
  1419. 50:13this is not healthy. We would like it to
  1420. 50:15be like the customers one to many. So
  1421. 50:17now let's go and check the issue with
  1422. 50:19the products. And we can do that by
  1423. 50:21going to the table view. So here we have
  1424. 50:23the customers. Let's go to the products.
  1425. 50:25It says the product ID6. And yes, we
  1426. 50:27have duplicates. The same row exists
  1427. 50:30twice. And this makes of course no
  1428. 50:32sense. And that's why PowerBI was not
  1429. 50:34happy about this because it breaks the
  1430. 50:37rule. So my friends PowerBI was good
  1431. 50:40enough to detect the issues and it
  1432. 50:42doesn't go and connect things randomly.
  1433. 50:45If it sees something wrong, it will not
  1434. 50:46go and create a relationship. Now, how
  1435. 50:49we going to fix this? It is very simple.
  1436. 50:51We're going to go to the Power Query and
  1437. 50:52clean the data before moduling it. So,
  1438. 50:54we're going to go to transform data.
  1439. 50:56Then go inside and make sure to check
  1440. 50:58the dimension products. And what we have
  1441. 51:00to do is to just remove duplicates over
  1442. 51:03here on the repon. Remove duplicates.
  1443. 51:05And now look at this. The product ID 6
  1444. 51:07is only once inside our data. And all
  1445. 51:10the values are now unique. Actually,
  1446. 51:12that's it. It should fix the issue. So,
  1447. 51:14let's go and save it. Now let's go and
  1448. 51:16try to change the cardality again. So
  1449. 51:19let's try the one to many. And yes, we
  1450. 51:22are not getting now any more issues.
  1451. 51:23PowerBI is happy. The product ID is
  1452. 51:26clean, unique, pointing of course to
  1453. 51:28many in the fact. Let's go and save it.
  1454. 51:30So now things looks way better. The
  1455. 51:32dimension has one, the fact has many.
  1456. 51:34Same things for the customers. Now of
  1457. 51:36course the filter direction, both of
  1458. 51:38them are not that good. Just going to go
  1459. 51:40and switch it to single. Same thing for
  1460. 51:42the customer. Now look at this. This is
  1461. 51:44a perfect data model. It's very
  1462. 51:46satisfying. All the filters are pointing
  1463. 51:48from the dimensions to the middle and we
  1464. 51:51start seeing the stars around the facts
  1465. 51:53and everything else with a one
  1466. 51:55cardality. So we have to keep pushing to
  1467. 51:57get exactly this picture. And of course
  1468. 51:59the next step is just the luxury things.
  1469. 52:01You might go and add some maybe metadata
  1470. 52:04by defining the key. So here it is the
  1471. 52:06product ID in order to have this small
  1472. 52:08icon. And now since we have multiple
  1473. 52:10dimensions, I can show you exactly why
  1474. 52:13it is bad to have both directions as a
  1475. 52:15filter between the dimensions and facts.
  1476. 52:17So again, I'm going to go and switch
  1477. 52:19them quickly. So here both as well. And
  1478. 52:21as usual, in order to understand it,
  1479. 52:23we're going to go to the report level.
  1480. 52:24And now since we have a third table, I'm
  1481. 52:26going to go and just add it quickly. So
  1482. 52:28let me just make those things small in
  1483. 52:31order to test and fit the products. So
  1484. 52:34this is our fact, this is the customer
  1485. 52:36and we can go and add now the products
  1486. 52:38over here. So I'm going to go and get
  1487. 52:40rid of those columns and only pick
  1488. 52:42things from the products. So the product
  1489. 52:44ID, name, and I'm going to say that's
  1490. 52:46it. And the last thing I'm going to go
  1491. 52:48and add card for it. So this time we're
  1492. 52:50going to go and count the total number
  1493. 52:52of products. So now those are the
  1494. 52:54totals. Six products, five customers,
  1495. 52:57and around 6K of sales. All right. So
  1496. 52:59now let's start filtering. And we're
  1497. 53:01going to do that by filtering the
  1498. 53:03products. Like for example, I would like
  1499. 53:05to see the total sales for the product
  1500. 53:07number one. So I can see here we have
  1501. 53:082K. But look at this. The customers get
  1502. 53:12filtered as well. Now I can see only two
  1503. 53:15customers. And here of course comes the
  1504. 53:16big question. Should we as well filter
  1505. 53:19the customers based on the products?
  1506. 53:22Well, I can tell you most of the cases
  1507. 53:24we don't need this effect. It is too
  1508. 53:26extreme to filter as well another
  1509. 53:28dimension like the customers because
  1510. 53:30usually this is how the users works on
  1511. 53:32dashboard. They have the dimensions in
  1512. 53:34order to filter the major event, the
  1513. 53:37major measure that we have in the report
  1514. 53:40which is the total sales. And now if the
  1515. 53:42filter is filtering another filter, they
  1516. 53:45going to lose immediately the big
  1517. 53:47picture. They're going to lose
  1518. 53:48immediately the other possibilities that
  1519. 53:50we have in the dashboards. So they're
  1520. 53:51going to look to the right side and say,
  1521. 53:52"Oh, we have only two customers." But
  1522. 53:55they will not think about yeah I'm
  1523. 53:56seeing two customers because I'm
  1524. 53:58filtering using the products. This is
  1525. 54:01too deep and too much. Same thing if
  1526. 54:03they go to another products they're
  1527. 54:04going to see wa we have only one
  1528. 54:06customer in our business. So they will
  1529. 54:08not as well think inside your data model
  1530. 54:10and they know ah everything is connected
  1531. 54:12and so on. They usually use the
  1532. 54:14dimensions to filter one thing and
  1533. 54:17imagine you have a lot of dimensions
  1534. 54:19this going to be catastrophic. filtering
  1535. 54:21only one small thing going to filter
  1536. 54:23deeply the whole dashboard and of course
  1537. 54:25you're going to get the same effect if
  1538. 54:26you go to the customers over here we go
  1539. 54:28and use for example Anna they're going
  1540. 54:30to see okay this is the total sales of
  1541. 54:32Anna but it is filtering as well the
  1542. 54:35products now what is way better than
  1543. 54:37this what we're going to do we're going
  1544. 54:38to go back to the model and yeah we're
  1545. 54:40going to go and change things back to
  1546. 54:42single same thing over here now let's go
  1547. 54:44back to our reports so now let's try
  1548. 54:47again we're going to go and select the
  1549. 54:49product one And now yes I see the total
  1550. 54:52sales for this product but look at this
  1551. 54:54the customers going to stay as it is. So
  1552. 54:56the effect it is not that overwhelming
  1553. 54:58for the users. Now if they go to the
  1554. 55:01customers and they say okay let's go and
  1555. 55:03filter Anna only the fact table going to
  1556. 55:05change. We still see the six products on
  1557. 55:08the left side. So the effect is not that
  1558. 55:10big. So my friends as a default if
  1559. 55:12you're using star schema don't go and
  1560. 55:13use the both directions for everything.
  1561. 55:16This going to be very overwhelming and
  1562. 55:18very deep for users. Usually all what
  1563. 55:20they do they want to do analyzes on one
  1564. 55:23main measure like for example the total
  1565. 55:25sales and they need your dimensions for
  1566. 55:27filtering. But if the dimensions starts
  1567. 55:29filtering each others they going to lose
  1568. 55:31quickly the big picture of the dashboard
  1569. 55:33and it's going to make filtering one
  1570. 55:35thing like an overreaction in the report
  1571. 55:37by wiping out all other data. That's why
  1572. 55:40as a default use one single direction
  1573. 55:43but in extreme cases or if the users
  1574. 55:45really want to see this effect in some
  1575. 55:47reports then go and use both directions
  1576. 55:50but limit it between maybe two tables
  1577. 55:52only. So this is the best practices for
  1578. 55:54filter directions in PowerBI. And now
  1579. 55:56you know why.
  1580. 55:57>> Thank you. I got it. Now I know. [music]
  1581. 56:05>> Okay. So now let's go and add another
  1582. 56:07dimension to our data model. This time
  1583. 56:09we're going to go and pick the store.
  1584. 56:11So, dimension store. All right. It is
  1585. 56:13very cute, very small data model. Let's
  1586. 56:15go and load it. All right. So, we got it
  1587. 56:17over here. Let's go and grab it near to
  1588. 56:19the fact and bring the customers above
  1589. 56:22something like this. First of all, we
  1590. 56:24have something good. So, the
  1591. 56:25relationship between the store and the
  1592. 56:27fact is one to many. And the filter is
  1593. 56:30pointing to the right direction. So, if
  1594. 56:32I go over here, I'm going to say okay,
  1595. 56:34it is using the store ID as well in the
  1596. 56:36dimension. So everything looks nice but
  1597. 56:39now we have this weird thing. We have
  1598. 56:41like a relationship between the
  1599. 56:42dimension store and the dimension
  1600. 56:44customer and it is using this dotted
  1601. 56:47relationship. It's not the straight line
  1602. 56:49that we used to see between the fact and
  1603. 56:51the dimension. So what is going on here?
  1604. 56:53Let's go and open it. Aha. PowerBI is
  1605. 56:55able to build a relationship between the
  1606. 56:57store and the customers using the city.
  1607. 57:00Well, this is very usual thing that you
  1608. 57:01have the same information in multiple
  1609. 57:03dimensions and probably I thought yeah
  1610. 57:05why not to go and connect them using the
  1611. 57:07city. This looks nice but it is not a
  1612. 57:10normal relationship right it was dotted
  1613. 57:12and you can see over here it says make
  1614. 57:14this relationship active and it is
  1615. 57:16deactivated that means we have in
  1616. 57:18powerbi two type of relationships active
  1617. 57:21relationship and inactive relationship
  1618. 57:23so here it is inactive let's go and
  1619. 57:25activate it and see what can happen say
  1620. 57:27no there are ambiguous path between fact
  1621. 57:30sales dimension store fact sales
  1622. 57:32dimension customers dimension store and
  1623. 57:35fact sales dimension store I know a lot
  1624. 57:38things here but simply PowerBI is just
  1625. 57:40whining about saying we have a loop
  1626. 57:43relationship so the path is like cycling
  1627. 57:45between the tables and I cannot go and
  1628. 57:48activate it otherwise it's going to be
  1629. 57:50for me unclear how I'm going to answer
  1630. 57:52your questions and you can see it over
  1631. 57:54here the loop the cycle so customers and
  1632. 57:57fact then we have fact and I mission
  1633. 57:59store and then back so we have a
  1634. 58:01relationship between the customers and
  1635. 58:03the fact another one between the store
  1636. 58:05and the fact and a third one which is
  1637. 58:07closing the cycle between the store and
  1638. 58:10the customer and this is exactly the
  1639. 58:12cycle. Now of course the big question is
  1640. 58:14why PowerBI doesn't allow that. So what
  1641. 58:17is the big issue? All right let's have
  1642. 58:19this very simple example. We have
  1643. 58:20exactly the same setup here. We have the
  1644. 58:22customers the stores and they are both
  1645. 58:24connected to the sales but at the same
  1646. 58:26time they are connected to each others
  1647. 58:28using the city. Now let's say that I
  1648. 58:29would like to see the total sales for
  1649. 58:31one of our customers. So if I go and
  1650. 58:33filter for example Maria, I expect that
  1651. 58:36the filter going to go to the fact sales
  1652. 58:37like this and the total of sales going
  1653. 58:39to be 1,500. So this is our
  1654. 58:41expectations. But the thing is PowerBI
  1655. 58:43has another path to the sales. So it can
  1656. 58:45go to the store and then from the store
  1657. 58:47it can go to the sales. Now because of
  1658. 58:49this path, PowerBI going to filter the
  1659. 58:51sales differently and get 2K for this
  1660. 58:54customer. Now, of course, this is going
  1661. 58:55to be a big issue for PowerBI because it
  1662. 58:58has two different results for the same
  1663. 59:00action and PowerBI cannot decide for us
  1664. 59:03which one is the correct one and this is
  1665. 59:05exactly what we mean with ambiguous.
  1666. 59:07PowerBI don't know the correct path
  1667. 59:10between two tables. That's why it
  1668. 59:12prevent us from having this scenario and
  1669. 59:15PowerBI force us to decide only on one
  1670. 59:17direction, one path between two tables.
  1671. 59:20Now, of course, we have the same
  1672. 59:21scenario if you look to the stores. If
  1673. 59:23you say, you know what, let's go and
  1674. 59:24filter by the downtown. It's going to go
  1675. 59:26to the sales over here and get 2K. But
  1676. 59:28as well, it has another path through the
  1677. 59:31customers. So, it can go to the
  1678. 59:32customers and from customers go to the
  1679. 59:34sales. Same scenario, same issue. So,
  1680. 59:36this is ambiguous and PowerBI will not
  1681. 59:38allow that. Instead, PowerBI says, okay,
  1682. 59:40I'm going to leave for you the
  1683. 59:42relationship between those two tables,
  1684. 59:43but it is inactive. I will not go and
  1685. 59:46use it. I'm going to go and use only the
  1686. 59:48active relationships. So if you go for
  1687. 59:50example and filter Maria PowerBI has one
  1688. 59:53clear active path between those two
  1689. 59:55tables and it going to get only one
  1690. 59:57results. Same thing if you go to the
  1691. 59:58downtown over here it has as well one
  1692. 1:00:01clear path. This is the loop and why
  1693. 1:00:03PowerBI was not allowing us to have
  1694. 1:00:05ambiguous path different options for the
  1695. 1:00:08same action. Okay. So with this now we
  1696. 1:00:10have understanded why PowerBI did make
  1697. 1:00:13this inactive between the customers and
  1698. 1:00:15store and now let's say that okay you
  1699. 1:00:17decided that this is the correct path
  1700. 1:00:19between those two tables and you want to
  1701. 1:00:21activate it. Now what you can do you can
  1702. 1:00:23go for example yeah it's wrong but you
  1703. 1:00:25can go between the customers and sales
  1704. 1:00:27open the relationship and make it
  1705. 1:00:29inactive. So now it is dotted and then
  1706. 1:00:32go back to the link between customers
  1707. 1:00:34and stores and make it active which is
  1708. 1:00:37of course again not correct but this is
  1709. 1:00:39the way on how to switch between active
  1710. 1:00:42and inactive relationships. Now of
  1711. 1:00:43course I'm going to get it back because
  1712. 1:00:45this is not correct. So now what we're
  1713. 1:00:47going to do with this inactive
  1714. 1:00:49relationship you have here my friend two
  1715. 1:00:51options. Either you're going to say you
  1716. 1:00:52know what I would never use this
  1717. 1:00:54relationship between those two tables.
  1718. 1:00:56It is totally wrong. So that means you
  1719. 1:00:58go and just delete this relationship.
  1720. 1:01:01But the other option is that we still
  1721. 1:01:03actually my friends could use this
  1722. 1:01:05relationship inside our reports. Now the
  1723. 1:01:07big question is how you going to use the
  1724. 1:01:09inactive and at the same time active
  1725. 1:01:11relationship in your projects. Now the
  1726. 1:01:13thing is the active relationship going
  1727. 1:01:15to be always used automatically from
  1728. 1:01:17PowerBI. So if you are using any
  1729. 1:01:19calculations and filtering in the
  1730. 1:01:21charts, PowerBI always going to use the
  1731. 1:01:23active relationship. But if you have
  1732. 1:01:26special cases where you say, you know
  1733. 1:01:27what, I need this inactive relationship.
  1734. 1:01:30You can go and use ducks. There is a du
  1735. 1:01:33function called use relationship. It's
  1736. 1:01:35going to turns on an inactive
  1737. 1:01:37relationship specifically for one
  1738. 1:01:39calculation. So that the measure the
  1739. 1:01:42calculation going to go through an
  1740. 1:01:44inactive relationship instead of the
  1741. 1:01:46active one. So that means in one report
  1742. 1:01:48you can let PowerBI use all time the
  1743. 1:01:51active relationship. But for specific
  1744. 1:01:53cases, you're going to create an extra
  1745. 1:01:55calculation, an extra measure that use
  1746. 1:01:58the inactive relationship. So that's why
  1747. 1:02:00my friends, if you have an inactive
  1748. 1:02:02relationship between two tables, either
  1749. 1:02:04drop it or you're going to use DAX in
  1750. 1:02:06order to use this path for specific
  1751. 1:02:08calculations. So those are our two
  1752. 1:02:10options. But now I'm going to say for
  1753. 1:02:12this scenario I don't need it. So I'm
  1754. 1:02:14going to go and delete it. So yes, now
  1755. 1:02:16again everything looks nice. All the
  1756. 1:02:19dimensions are pointing toward the
  1757. 1:02:21facts. The cardalities around the fact
  1758. 1:02:24are the many, the star and the cardality
  1759. 1:02:26on the dimensions are one. So far
  1760. 1:02:28everything is healthy like plants.
  1761. 1:02:34All right, let's [music] keep going and
  1762. 1:02:36connect more things to our data model.
  1763. 1:02:38Now this time we're going to go and
  1764. 1:02:39connect another customer dimension, the
  1765. 1:02:42loyalty. So let's go and do that. Again,
  1766. 1:02:44a very simple dimension. All right. Now
  1767. 1:02:46you can see that PowerBI did connect our
  1768. 1:02:49new dimension to another dimension to
  1769. 1:02:51the customers using a onetoone
  1770. 1:02:54relationship. So let's go and open it.
  1771. 1:02:56It says okay we are connecting using the
  1772. 1:02:58customer ID which is correct. And it
  1773. 1:03:00says as well the customer ID in the new
  1774. 1:03:03dimension is unique. So we don't have
  1775. 1:03:05here duplicates. Of course same thing in
  1776. 1:03:07our original customer dimension.
  1777. 1:03:09Everything is unique here. And that's
  1778. 1:03:11why PowerBI did decide to go with the
  1779. 1:03:13one to one relationship. So now the
  1780. 1:03:15question is should we panic? Should we
  1781. 1:03:18leave it like this? This onetoone
  1782. 1:03:20relationships are actually a harmless
  1783. 1:03:22relationship and you will not do a lot
  1784. 1:03:24of mistakes. If you leave it as it is,
  1785. 1:03:27it will not go and lead to wrong numbers
  1786. 1:03:29or any issues in the front end. The only
  1787. 1:03:32side effect that you have to think of is
  1788. 1:03:34that PowerBI has to go and join those
  1789. 1:03:36two tables in order to present the
  1790. 1:03:38results. So it is an extra effort for
  1791. 1:03:40PowerBI to travel from one table to
  1792. 1:03:43another. but it has no effect on the
  1793. 1:03:46correctness on the report. And here you
  1794. 1:03:48have actually two options on how to do
  1795. 1:03:49it. Either you're going to leave it as
  1796. 1:03:51it is and here you could say you know
  1797. 1:03:52what it makes no sense to have them like
  1798. 1:03:55splitted. I can go and join those two
  1799. 1:03:57tables together and merge them into one
  1800. 1:03:59dimension. So with that I reduce the
  1801. 1:04:02number of travels for PowerBI and maybe
  1802. 1:04:04speed up things a little bit. So very
  1803. 1:04:06famous solution is to just go and merge
  1804. 1:04:08them. Don't leave them separated. So for
  1805. 1:04:10example here the names and the tier
  1806. 1:04:12going to go together inside the
  1807. 1:04:13dimension customers. So I'm going to say
  1808. 1:04:15this is the default solution that I
  1809. 1:04:17usually do in my projects. But now in
  1810. 1:04:19projects sometimes we decide to split
  1811. 1:04:22things using the onetoone relationships
  1812. 1:04:24for some reasons like for example your
  1813. 1:04:27dimension customer over the time gets
  1814. 1:04:29bigger and bigger. you have a lot of
  1815. 1:04:30columns about the customers and in order
  1816. 1:04:32for you to manage things easily you say
  1817. 1:04:35you know what I'm going to put all the
  1818. 1:04:36descriptions about the customers in one
  1819. 1:04:38table and then group another set of
  1820. 1:04:40columns in another table maybe some date
  1821. 1:04:43informations about the last login the
  1822. 1:04:46first sign up so they are like group of
  1823. 1:04:48columns about the same topic and then
  1824. 1:04:50connect those two tables using onetoone
  1825. 1:04:52relationship or it could be for security
  1826. 1:04:55reasons where you split some sensitive
  1827. 1:04:57data into another table so that you
  1828. 1:04:59could hide this type of informations and
  1829. 1:05:02you show only the informations that are
  1830. 1:05:04allowed. So that's we have like split
  1831. 1:05:05between insensitive and sensitive
  1832. 1:05:07informations and we connect them using
  1833. 1:05:09the one to one relationships. But again
  1834. 1:05:11those are special edge cases where we
  1835. 1:05:14have to go and split things. But as a
  1836. 1:05:16default if you see one to one
  1837. 1:05:17relationship you can go and merge them
  1838. 1:05:19into one dimension. And this is exactly
  1839. 1:05:21what we're going to do now. We're going
  1840. 1:05:22to go and merge those two tables
  1841. 1:05:24together. And how we going to do it?
  1842. 1:05:26We're going to use the power query. So
  1843. 1:05:28we're going to go to transform data and
  1844. 1:05:30I'm going to go and make this bigger. So
  1845. 1:05:32let's go to the dimension customer and
  1846. 1:05:34then we're going to go and say merge
  1847. 1:05:35queries. This is the first table. We
  1848. 1:05:38need the second table the loyalty. Now
  1849. 1:05:40we have both of them. Of course we have
  1850. 1:05:42to connect them using the customer ID.
  1851. 1:05:44And here be careful. You have to decide
  1852. 1:05:47about the join. I usually always use
  1853. 1:05:49lift join. Inner join is dangerous
  1854. 1:05:51because it's going to go and filter the
  1855. 1:05:53data. And by looking to this I can say
  1856. 1:05:56the customer has more weight than the
  1857. 1:05:58customer loyalty because it has the main
  1858. 1:06:01informations about the customers and I
  1859. 1:06:03would not like to lose anything. So you
  1860. 1:06:06start with the main table and then the
  1861. 1:06:08secondary table and make sure to use the
  1862. 1:06:10lift join. So actually that's it. Let's
  1863. 1:06:12go and hit okay. Now we have it here as
  1864. 1:06:14a table. The next step we're going to go
  1865. 1:06:16and expand it. So we have to select the
  1866. 1:06:18columns that we need. Well, we need the
  1867. 1:06:19tiers. We need the points, but we don't
  1868. 1:06:21need the customer ID because we have it
  1869. 1:06:23already as primary key. So, actually,
  1870. 1:06:25that's it. Let's hit okay. Now, look at
  1871. 1:06:27this. We have the tiers and as well the
  1872. 1:06:29points. The next step, I'm going to go
  1873. 1:06:30and just rename them to be more
  1874. 1:06:32friendly. So, we're going to go over
  1875. 1:06:34here and say rename. This going to be
  1876. 1:06:36tier and the other one going to be
  1877. 1:06:38points. So, this looks really nice. Now,
  1878. 1:06:42in our model, we don't need anymore this
  1879. 1:06:44dimension because it is already merged
  1880. 1:06:46into the customers. So what we can do we
  1881. 1:06:48can right click on it and deactivate
  1882. 1:06:51enable load. Yes. Continue. So with that
  1883. 1:06:53we deactivate this table to be loaded
  1884. 1:06:55inside our model. And with that we have
  1885. 1:06:58everything inside the dimension
  1886. 1:06:59customers. So this is how we merge. It
  1887. 1:07:01is like preparation step before the data
  1888. 1:07:04modeling. So I'm going to go and close
  1889. 1:07:06it. Make sure to save it as well. Now
  1890. 1:07:08look at this. The dimension did
  1891. 1:07:10disappear but we have its informations
  1892. 1:07:13inside the customers. Again, it is not
  1893. 1:07:15that dramatic if you just leave it, but
  1894. 1:07:18it is more clean to bring everything
  1895. 1:07:20into one dimension to have the shape of
  1896. 1:07:23the star schema and you don't have to
  1897. 1:07:25deal with a lot of tables as you are
  1898. 1:07:26building your reports. So, the dimension
  1899. 1:07:29customer did absorb another dimension
  1900. 1:07:32that has the relationship one to one.
  1901. 1:07:38Now, my [music] friends, dimensions
  1902. 1:07:39don't always live in dimension tables.
  1903. 1:07:42Sometimes they sneak into fact tables as
  1904. 1:07:45descriptive informations. Our job is to
  1905. 1:07:47spot those sneaky dimensions inside the
  1906. 1:07:50facts and pull them out into real
  1907. 1:07:53dimensions. So let's go and find them.
  1908. 1:07:55>> Well, let's see.
  1909. 1:07:56>> So now what we're going to do, we're
  1910. 1:07:57going to go and inspect our fact sales
  1911. 1:08:00to see whether we have dimensions inside
  1912. 1:08:02this table. Let's go to the table view
  1913. 1:08:04in order to inspect. Now, as we learned
  1914. 1:08:06at the start, fact tables going to
  1915. 1:08:08contain a lot of ids, dates, and
  1916. 1:08:11numbers. So let's see whether this is
  1917. 1:08:13the case. Yes, we have a lot of ids at
  1918. 1:08:15the starts. We have the dates. We have
  1919. 1:08:17the numbers but as well we have a lot of
  1920. 1:08:20text over here. This is a big alarm. Now
  1921. 1:08:23usually text and string columns they
  1922. 1:08:26used in order to describe something and
  1923. 1:08:28this is exactly the job of the
  1924. 1:08:30dimensions not the fact. So that means
  1925. 1:08:33my friends all those columns are
  1926. 1:08:35actually good candidates for dimensions
  1927. 1:08:37and it makes no sense to leave them
  1928. 1:08:40inside our facts. And this happens a lot
  1929. 1:08:42in real projects where you think okay
  1930. 1:08:44this table has an event it is
  1931. 1:08:47transactions we have dates and stuff but
  1932. 1:08:49still it has as well same time a lot of
  1933. 1:08:52description so that's why it's time to
  1934. 1:08:54extract all those dimensions from the
  1935. 1:08:56facts and make our fact clean and as
  1936. 1:08:58well we got to get some useful
  1937. 1:09:00dimensions so of course the question is
  1938. 1:09:02what we going to do with all those
  1939. 1:09:03informations do we have here one
  1940. 1:09:04dimension two three well this depends on
  1941. 1:09:07the relationship between those columns
  1942. 1:09:10so now let's see What do we have over
  1943. 1:09:11here? We have promotion code. So it is a
  1944. 1:09:13code that is used maybe for some sales.
  1945. 1:09:16We have the order channel in store,
  1946. 1:09:18online, phone, the order status. We have
  1947. 1:09:21information about the payment methods,
  1948. 1:09:23credit card, PayPal and so on. The card
  1949. 1:09:25network and the card type. Now your main
  1950. 1:09:28job is to spot the columns that relate
  1951. 1:09:31to each others. And from looking at this
  1952. 1:09:33I can say the payment methods, the card
  1953. 1:09:36network and the card type. All those
  1954. 1:09:38three columns are actually related to
  1955. 1:09:40each others and they are perfect in
  1956. 1:09:42order to make a dimension and this
  1957. 1:09:44dimension of course going to be the
  1958. 1:09:46payment dimension the order status and
  1959. 1:09:48the order channel promotion code they
  1960. 1:09:50are not related to the payment methods.
  1961. 1:09:53So that's why I would not go and connect
  1962. 1:09:55those stuff to our new dimension. Now of
  1963. 1:09:58course the big question is how we going
  1964. 1:10:00to split? Well again that means we need
  1965. 1:10:02to transform the data and for that we
  1966. 1:10:04have the power query. So let's go there.
  1967. 1:10:07We don't use power query only to merge
  1968. 1:10:10things as well to split things. So now
  1969. 1:10:12there are like multiple ways on how to
  1970. 1:10:14do it. I usually do it like this. Now
  1971. 1:10:16the thing is we don't have the dimension
  1972. 1:10:18yet inside our data model. So either
  1973. 1:10:20you're going to go and get it from the
  1974. 1:10:21CSV file or you can go and duplicate the
  1975. 1:10:24fact sales which I think it is way
  1976. 1:10:26easier than just like loading the data
  1977. 1:10:29again. So I'm going to go and duplicate
  1978. 1:10:30the fact sales and then I'm going to
  1979. 1:10:32give it the name dimension. It's going
  1980. 1:10:34to be the payments. So this is duplicate
  1981. 1:10:37from our fact sales and of course I
  1982. 1:10:39don't need all those columns right for
  1983. 1:10:41the payments I just need the last three.
  1984. 1:10:43So what we do we're going to go and
  1985. 1:10:45select everything and say go and remove
  1986. 1:10:47the columns with that I got only the
  1987. 1:10:49three columns that I need for the
  1988. 1:10:51payments. Now comes something really
  1989. 1:10:53important to do those informations
  1990. 1:10:54usually going to have a lot of
  1991. 1:10:56duplicates. So look at the first two
  1992. 1:10:58rows they are just the same. So what
  1993. 1:10:59we're going to do we're going to go over
  1994. 1:11:00here and say remove the duplicates. So
  1995. 1:11:03with that each row is unique and this is
  1996. 1:11:06very important for the dimensions. In
  1997. 1:11:07order to get one to many relationship
  1998. 1:11:10with the facts. Now look at this what we
  1999. 1:11:13are missing. We need the ID for the
  2000. 1:11:15dimension in order to connect it with
  2001. 1:11:17the facts. We don't connect things using
  2002. 1:11:19text. And in order to generate an ID
  2003. 1:11:21it's going to be very simple. We're
  2004. 1:11:22going to go and add a column. And then
  2005. 1:11:24we add an index column. It's going to be
  2006. 1:11:26a sequence of number for each row. So
  2007. 1:11:28we're going to go over here and say okay
  2008. 1:11:30start from one. And with that we have a
  2009. 1:11:32nice ID. I'll just going to go bring it
  2010. 1:11:34to the start. And then what we're going
  2011. 1:11:35to do, we're going to go and rename it
  2012. 1:11:37like all others. So we're going to say
  2013. 1:11:39payment ID. Now look at this. If you go
  2014. 1:11:41and compare it to any other dimensions
  2015. 1:11:43that we have, this is exactly a nice
  2016. 1:11:45dimension that we could use in our model
  2017. 1:11:47to do filtering and all other stuff.
  2018. 1:11:49Again, very important that we have an ID
  2019. 1:11:51and the data is unique. We don't need
  2020. 1:11:54many to many relationships. So this is
  2021. 1:11:56how you build a dimension out of facts.
  2022. 1:11:59But we are not done yet. We have to
  2023. 1:12:01connect now the dimension to our facts.
  2024. 1:12:04So if you go to the fact sales and you
  2025. 1:12:06can see that in the fact we are always
  2026. 1:12:07connecting the dimensions using ids and
  2027. 1:12:10we need the same thing actually for the
  2028. 1:12:12payments. So actually we don't need all
  2029. 1:12:14those informations in the fact we just
  2030. 1:12:16need the payment ID. Now how we going to
  2031. 1:12:18do it? This is going to sounds a little
  2032. 1:12:19bit weird but we have to merge now the
  2033. 1:12:22fact sales with the dimension payments
  2034. 1:12:25just in order to get the payment ID. I
  2035. 1:12:27know this sounds strange that you are
  2036. 1:12:29splitting and then combining but only
  2037. 1:12:31with this you're going to get a clean
  2038. 1:12:33model later in the next layers so that
  2039. 1:12:35it is easy to connect and as well easy
  2040. 1:12:37to use later in the reports. So now what
  2041. 1:12:40you going to do we have to go and merge
  2042. 1:12:42things. So the first is going to be the
  2043. 1:12:43fact sales. The second is going to be
  2044. 1:12:45the new dimension the payments. Of
  2045. 1:12:48course the question is how you going to
  2046. 1:12:49go and connect those two tables. We're
  2047. 1:12:51going to use the three columns. So we
  2048. 1:12:54need the payment methods the card
  2049. 1:12:56network and the card type. Same thing
  2050. 1:12:58from the first table from the fact we're
  2051. 1:13:00going to use those three columns. So we
  2052. 1:13:02have to connect all those columns in
  2053. 1:13:03order to get the payment ID. And of
  2054. 1:13:05course it's going to work because they
  2055. 1:13:06are actually the same columns. Again
  2056. 1:13:08we're going to use only the left outer
  2057. 1:13:10join. This looks good. Let's go and hit
  2058. 1:13:12okay. Now we got the whole dimension in
  2059. 1:13:14the facts. We don't need that. We just
  2060. 1:13:16need only one thing, the payment ID. So
  2061. 1:13:18let's go and select it and say okay.
  2062. 1:13:20Look at this. We have it already here.
  2063. 1:13:22Let's go and rename it. So this going to
  2064. 1:13:24be payment ID. And what we're going to
  2065. 1:13:26do, we're going to go and put it side by
  2066. 1:13:28side by all other columns, right? It
  2067. 1:13:30deserve now its place. So I'm just going
  2068. 1:13:32to go and put it at the end. Now look at
  2069. 1:13:34this. It looks clean. We have customer
  2070. 1:13:36ID, product ID, store ID, and the
  2071. 1:13:38payment ID. The last step that we have
  2072. 1:13:40to do is to clean up. So we don't need
  2073. 1:13:43anymore those three columns. I'm going
  2074. 1:13:44to go and delete them. So right click
  2075. 1:13:47and remove. So it's going to be over
  2076. 1:13:49here. Now look at this. Our fact is
  2077. 1:13:51clean. And with that I'm going to say we
  2078. 1:13:53successfully extracted a dimension out
  2079. 1:13:56of facts. We have of course other
  2080. 1:13:57informations but we have now less
  2081. 1:13:59descriptions in the fact. Now the last
  2082. 1:14:01step. We have of course still some text
  2083. 1:14:03but we're going to do that as a second
  2084. 1:14:04step. Now let's go and save and close.
  2085. 1:14:07Then apply all the changes. All right.
  2086. 1:14:09So with this we got a new dimension our
  2087. 1:14:11dim payments and as well PowerBI did
  2088. 1:14:13connect it correctly. So things looks
  2089. 1:14:15really nice. We have one to many
  2090. 1:14:17relationship and as well the direction
  2091. 1:14:19is correct. You can see we are getting
  2092. 1:14:21the shape of the star right. If I just
  2093. 1:14:23move things like this fact in the middle
  2094. 1:14:25and surrounded by dimensions and
  2095. 1:14:28everything is pointing to [music] our
  2096. 1:14:29facts.
  2097. 1:14:33So now of course we are not done yet. We
  2098. 1:14:35still have some descriptive informations
  2099. 1:14:37inside our facts. So the promotion code,
  2100. 1:14:39the order channel and the order status.
  2101. 1:14:42Now the big question is how we going to
  2102. 1:14:44extract those informations. Do they
  2103. 1:14:46relate to each others? Now if you look
  2104. 1:14:48closely, you would not have the feeling
  2105. 1:14:50those informations actually relate to
  2106. 1:14:52each other. So the promotion code has
  2107. 1:14:54nothing to do with the order channel.
  2108. 1:14:55Same thing for the order status. So they
  2109. 1:14:58are actually three different piece of
  2110. 1:15:00informations in the fact and all three
  2111. 1:15:02together will not form a dimension and
  2112. 1:15:05they are not related enough to go and
  2113. 1:15:07bring them together into one dimension.
  2114. 1:15:09So now how are we going to solve this?
  2115. 1:15:10You're going to find in some projects
  2116. 1:15:12that people say you know what for each
  2117. 1:15:14column we're going to go and create a
  2118. 1:15:15dimension. So they start splitting each
  2119. 1:15:17of those columns inside the fact and
  2120. 1:15:19build a dimension and create for it an
  2121. 1:15:21ID. And over the time you're going to
  2122. 1:15:23find in their star schema a lot of many
  2123. 1:15:25dimensions around the facts. One
  2124. 1:15:27dimension, one column and so on. And I
  2125. 1:15:30think this is really overreacting. So
  2126. 1:15:32this going to be a lot of work if you
  2127. 1:15:34have a lot of columns inside the facts.
  2128. 1:15:36And this is usually the thing in
  2129. 1:15:37projects. Fact tables are usually big
  2130. 1:15:39tables and they have a lot of status
  2131. 1:15:41columns. So how we going to solve this?
  2132. 1:15:43We don't want it inside the fact, right?
  2133. 1:15:45Well, the solution for this something
  2134. 1:15:47called a junk dimension. A junk
  2135. 1:15:49dimension. It is a small dimension that
  2136. 1:15:51bundles several unrelated low-level
  2137. 1:15:55flags. So all those junk or garbage,
  2138. 1:15:57let's say columns that are actually not
  2139. 1:15:59related to each others and take space
  2140. 1:16:01inside the facts, we're going to go and
  2141. 1:16:03bundle them into a junk table, a junk
  2142. 1:16:06dimension. And each time you find a new
  2143. 1:16:08flag that is unrelated for anything,
  2144. 1:16:11you're going to go and put it in this
  2145. 1:16:12junk dimension. So this is the best
  2146. 1:16:14practices in dimensional modeling or
  2147. 1:16:17building a star schema to put all
  2148. 1:16:19unrelated informations into one
  2149. 1:16:21dimension. So now let's go and see how
  2150. 1:16:23we're going to do it. So that means my
  2151. 1:16:24friends all those three columns going to
  2152. 1:16:26go into a new dimension. So how we going
  2153. 1:16:28to do it? So same thing as we done with
  2154. 1:16:30the payments. We're going to go to the
  2155. 1:16:31power query. We're going to repeat the
  2156. 1:16:33same steps. So we're going to go and
  2157. 1:16:34duplicate the fact table and we're going
  2158. 1:16:37to give it a name. So here the official
  2159. 1:16:38name people going to go and call it like
  2160. 1:16:40dimension junk or I usually go and use a
  2161. 1:16:43friendly name. So dimension flags well
  2162. 1:16:46it doesn't matter which one you're going
  2163. 1:16:47to use. It is just the idea. So what
  2164. 1:16:49we're going to do same thing we don't
  2165. 1:16:50need all those informations. We just
  2166. 1:16:52need the unrelated columns. So remove
  2167. 1:16:55the columns. And now comes something
  2168. 1:16:57really important to do with that. So we
  2169. 1:16:59have here a lot of nulls inside the junk
  2170. 1:17:02dimension and we have to handle it
  2171. 1:17:04otherwise the join or the merge with the
  2172. 1:17:06fact sales will not work. So this is
  2173. 1:17:08very critical. What we're going to do
  2174. 1:17:10we're going to go and right click on it
  2175. 1:17:11and say replace values. So instead of
  2176. 1:17:14nulls we're going to say unknown or you
  2177. 1:17:16can say okay. So any string value that
  2178. 1:17:18you want like unknown or not available.
  2179. 1:17:20Let's go and hit okay. So this looks way
  2180. 1:17:22better. Now only then we're going to go
  2181. 1:17:24and remove the duplicate. So, make sure
  2182. 1:17:26to select everything and then go over
  2183. 1:17:28here, remove duplicates. Nice. Now,
  2184. 1:17:30things are unique. The last step, we're
  2185. 1:17:32going to go and add a column. So, we're
  2186. 1:17:34going to add an index that starts from
  2187. 1:17:36one and then move it to the starts.
  2188. 1:17:38We're going to call you the flag ID. So,
  2189. 1:17:41this is our junk dimension. Everything
  2190. 1:17:43is ready. We have a lot of unnecessary
  2191. 1:17:45informations to gather, but it is not
  2192. 1:17:47that big. Now, what we're going to do,
  2193. 1:17:48we're going to go to the fact sales and
  2194. 1:17:50connect the junk to the facts. But we
  2195. 1:17:53have to be very careful since we're
  2196. 1:17:55going to use all those three columns in
  2197. 1:17:56the joins. They must match. And now the
  2198. 1:17:59promotion code will not work, right?
  2199. 1:18:01Because here we have nulls and in the
  2200. 1:18:02junk we have the unknown. That's why we
  2201. 1:18:04have to handle this as well. So we're
  2202. 1:18:06going to go and say okay, replace
  2203. 1:18:08values. If you are null, then you are
  2204. 1:18:10unknown. Let's hit okay. Nice. Now we're
  2205. 1:18:12going to go and connect things using the
  2206. 1:18:15merge. So we're going to go to the right
  2207. 1:18:16side and select those three columns and
  2208. 1:18:19connect it to our junk dimension. Same
  2209. 1:18:22thing we just need the flag ID in the
  2210. 1:18:24dimension, right? So left join and let's
  2211. 1:18:26hit okay. So with this we got the
  2212. 1:18:28dimension as a table but all what we
  2213. 1:18:30need is the flag ID. So I'm going to go
  2214. 1:18:32and deselect everything and say flag ID.
  2215. 1:18:35And look at this. It is working. So
  2216. 1:18:37before I move it, I'm going to go and
  2217. 1:18:39call it flag ID. And this junk as well
  2218. 1:18:42deserve its place near the other
  2219. 1:18:44dimensions. So I'm going to go and move
  2220. 1:18:46it to the left side. But I'm going to go
  2221. 1:18:48and put it at the end. So look at this.
  2222. 1:18:50We have the flag ID, the junk, and on
  2223. 1:18:53the right side, now we're going to go
  2224. 1:18:54and remove all those stuff. So, right
  2225. 1:18:56click on it, remove the columns. Now,
  2226. 1:18:59look to our facts. We have over here a
  2227. 1:19:02lot of ids. Then, we have the dates and
  2228. 1:19:05we have numbers and all the junk now
  2229. 1:19:07inside a junk dimension. So, this looks
  2230. 1:19:10really clean. Now, let's go and close
  2231. 1:19:12and save. Everything is loaded
  2232. 1:19:14correctly. Let's go to the model. Now,
  2233. 1:19:16we have our junk dimension. I'm going to
  2234. 1:19:18put it here on top. and you go down and
  2235. 1:19:21we have to make sure this is one to many
  2236. 1:19:24relationship and the correct direction.
  2237. 1:19:26So my friends, I'm really happy with the
  2238. 1:19:28result so far. With this we have
  2239. 1:19:30extracted a new two dimensions out of
  2240. 1:19:32the fact. So we have a really solid
  2241. 1:19:35dimension called the payment. All the
  2242. 1:19:36columns relate to each others. But as
  2243. 1:19:38well we have a lot of junk dimensions, a
  2244. 1:19:41lot of unrelated flags. We bundled
  2245. 1:19:43everything together into one dimension
  2246. 1:19:45and connected back to the fact sales. So
  2247. 1:19:48this is really amazing. I always keep my
  2248. 1:19:50eyes on the directions of the filters,
  2249. 1:19:51the cardalities just to make sure that
  2250. 1:19:53we have a clean star schema in order to
  2251. 1:19:56do analytics.
  2252. 1:20:00All right friends, [music] so now we're
  2253. 1:20:01going to speak about dimensions that
  2254. 1:20:03they are kind of special. So they play
  2255. 1:20:05different roles in different scenarios.
  2256. 1:20:07That's why we call them the roleplaying
  2257. 1:20:09dimensions.
  2258. 1:20:10>> What um what do you think of role play?
  2259. 1:20:13>> So now let's understand what this means.
  2260. 1:20:15Okay. Okay. So now in order to
  2261. 1:20:16understand it, we're going to have this
  2262. 1:20:17very simple scenario where we have two
  2263. 1:20:19dimensions. The salespersons and as well
  2264. 1:20:21the managers. Both of them are connected
  2265. 1:20:24to the fact sales. And now with this
  2266. 1:20:26setup, I can go and find out the total
  2267. 1:20:28sales for example per person. If I go to
  2268. 1:20:30the Anna here, I can see that she made
  2269. 1:20:32two orders and the total sales is around
  2270. 1:20:351,500. Same thing if I go to other
  2271. 1:20:37salesperson like Carlos Dana with that
  2272. 1:20:40I'm able to find out the total sales and
  2273. 1:20:42the total number of orders. But now if I
  2274. 1:20:44go to the other dimension to the
  2275. 1:20:46managers and I go and select the team of
  2276. 1:20:48pop, I'm going to see the total number
  2277. 1:20:50of orders and as well the total number
  2278. 1:20:52of sales for the whole team and his team
  2279. 1:20:54has only two persons. So the one and the
  2280. 1:20:57two, so Anna and Carlos and same thing
  2281. 1:20:59if I go and check the other manager, I'm
  2282. 1:21:01going to see as well the total sales for
  2283. 1:21:03that team. So far nothing is crazy,
  2284. 1:21:05right? It is working. But now what could
  2285. 1:21:07happen in real business that one of the
  2286. 1:21:09managers like for example pop he can go
  2287. 1:21:11and sometime close some sales. So that
  2288. 1:21:14means if I look to pop as a salesperson
  2289. 1:21:16I can go over here and see okay he
  2290. 1:21:18closed two sales and I can see the total
  2291. 1:21:20amount of sales. And if I look at pop as
  2292. 1:21:23a manager I'm going to see now the total
  2293. 1:21:25number of sales and orders for the whole
  2294. 1:21:27team. So that means I can look at pop in
  2295. 1:21:29two directions. One as a salesperson and
  2296. 1:21:32another as a manager. So so far there is
  2297. 1:21:34no big problem. But the issue is that
  2298. 1:21:36the design of the data model. We have
  2299. 1:21:38the same person in two dimensions. So
  2300. 1:21:41that means we have double informations
  2301. 1:21:42and this is not really good because for
  2302. 1:21:44example now if maybe pop now change his
  2303. 1:21:46name or address or whatever we have
  2304. 1:21:48information inside the dimension. I have
  2305. 1:21:50to go now and update both of the
  2306. 1:21:52dimensions. Of course here it's a very
  2307. 1:21:54simple example but over the time this
  2308. 1:21:55can be really hard to maintain and to
  2309. 1:21:58manage and as well this is a bad design
  2310. 1:22:00if I make like a dimension for each
  2311. 1:22:02role. Maybe next day I'm going to get
  2312. 1:22:04like a new role like an account owner.
  2313. 1:22:06Then we're going to have like a third
  2314. 1:22:07dimension about the persons and then
  2315. 1:22:09we're going to have maybe pop in all
  2316. 1:22:11three dimensions. So that means you're
  2317. 1:22:12going to lose control quickly if you
  2318. 1:22:14start splitting the dimensions by the
  2319. 1:22:16role. Especially if they are identical.
  2320. 1:22:18You can see here we have the same
  2321. 1:22:19columns. We have ID, name, team, ID,
  2322. 1:22:22name, team. So they have the same
  2323. 1:22:23schema. The only difference is the role.
  2324. 1:22:25So now of course what is the solution?
  2325. 1:22:27It is very obvious. We're going to go
  2326. 1:22:28and bring all those dimensions that are
  2327. 1:22:31identical and we're going to bring them
  2328. 1:22:33into one dimension that going to play
  2329. 1:22:35different roles. Okay. So now how it
  2330. 1:22:37going to looks like in the modeling
  2331. 1:22:39we're going to go and combine those two
  2332. 1:22:41dimensions into one generic dimension
  2333. 1:22:44called employee. So before it was
  2334. 1:22:46splitted by the role but now we have it
  2335. 1:22:48generic. And of course in the future if
  2336. 1:22:50we had like an HR dimension we can go
  2337. 1:22:52and always fit it inside the employee so
  2338. 1:22:55that we have like single point of truth
  2339. 1:22:57for people inside the company. Now of
  2340. 1:22:59course each person going to be one row
  2341. 1:23:01inside the dimension. And now if we do
  2342. 1:23:03this of course we have to be careful not
  2343. 1:23:05to lose information from the module.
  2344. 1:23:07Like for example before we had a manager
  2345. 1:23:09we had a salespersons. Those
  2346. 1:23:11informations were the table name and
  2347. 1:23:13they are of course important in the
  2348. 1:23:15model. But now instead of having them in
  2349. 1:23:17the names, we're going to go and put
  2350. 1:23:19them as a values inside a new column
  2351. 1:23:21called a ro. So that we have one
  2352. 1:23:23complete dimension that is ready to be
  2353. 1:23:26reused multiple times inside the facts.
  2354. 1:23:28Now by looking to this you can see that
  2355. 1:23:30our dimension going to play two roles
  2356. 1:23:32right salesperson and manager. And for
  2357. 1:23:35that we have to go and create two
  2358. 1:23:37relationships. One for the salesperson
  2359. 1:23:39and one for the manager. And of course
  2360. 1:23:40in PowerBI we cannot have both of them
  2361. 1:23:42active. one of them going to be active
  2362. 1:23:44and the rest going to be inactive. So
  2363. 1:23:46for now, for example, the saleserson
  2364. 1:23:48going to be the active relationship and
  2365. 1:23:50the manager going to be the inactive. So
  2366. 1:23:52now let's have an example like before
  2367. 1:23:53let's see the total sales for Anna. We
  2368. 1:23:56can see we're still going to get the
  2369. 1:23:57total sales the two orders. Same thing
  2370. 1:23:59if I go to Carlos to Diana and as well
  2371. 1:24:02to our manager Bob. So by looking at
  2372. 1:24:04this our dimension now is playing the
  2373. 1:24:06role of the salesperson. But now let's
  2374. 1:24:08say that I would like now to switch the
  2375. 1:24:10roles and I would like to see the total
  2376. 1:24:12sales for the whole team for the
  2377. 1:24:14managers. So that means we have to
  2378. 1:24:16switch roles for this dimension and we
  2379. 1:24:18can do that by using the other
  2380. 1:24:20relationship the manager one. Of course
  2381. 1:24:22we can do that using ducks. And now the
  2382. 1:24:24dimension employee is playing this role.
  2383. 1:24:26So if I go to pop I will not see the
  2384. 1:24:28sales of pop. I'm going to see the sales
  2385. 1:24:31of the whole team. Same thing if I go to
  2386. 1:24:33the other manager I'm going to see as
  2387. 1:24:35well the sales of the whole team. Now if
  2388. 1:24:37I go to Anna, Carlos, Diana, I will not
  2389. 1:24:40see anything because they are not
  2390. 1:24:41managers. They don't have teams. So as
  2391. 1:24:44you can see, I'm using the same table
  2392. 1:24:45but from two different perspectives. One
  2393. 1:24:48as a salesperson and another one as a
  2394. 1:24:50manager. Now imagine you have a third
  2395. 1:24:52role. All what you have to do is to go
  2396. 1:24:54and create a new relationship between
  2397. 1:24:57those two tables and you use that
  2398. 1:24:59relationship in order to play another
  2399. 1:25:01role for this dimension. So that's why
  2400. 1:25:04my friends we call the dimension
  2401. 1:25:06employee is roleplaying dimension. It is
  2402. 1:25:09just a dimension that is playing
  2403. 1:25:11different roles for the same fact table
  2404. 1:25:14by using multiple relationship to it and
  2405. 1:25:17only using one active relationship at a
  2406. 1:25:20time and of course we switch roles by
  2407. 1:25:22using ducks function called the user
  2408. 1:25:24relationship. So this is what we mean
  2409. 1:25:26with the role playinging dimension. Now
  2410. 1:25:28let's go to PowerBI and see how we're
  2411. 1:25:29going to do that. Okay. Okay. So, as
  2412. 1:25:31usual, we're going to go and connect our
  2413. 1:25:32dimensions. This time, we're going to go
  2414. 1:25:34and get to the managers and as well the
  2415. 1:25:37salespersons. So, this one over here.
  2416. 1:25:41Load. Now, at the start, if you are not
  2417. 1:25:43investigating about those new
  2418. 1:25:45dimensions, you're going to see, okay,
  2419. 1:25:46we have here a manager ID. So, I'm going
  2420. 1:25:48to go and connect it with the fact.
  2421. 1:25:50Looks good. One to many. So, I'm not
  2422. 1:25:52hurting the star schema. Same thing for
  2423. 1:25:54the salespersons. I have an ID for it in
  2424. 1:25:57the fact. So I'm going to go and connect
  2425. 1:25:58it as well. One to many. So at the start
  2426. 1:26:02things looks healthy, right? But now if
  2427. 1:26:04you go and investigate the data itself,
  2428. 1:26:06we're going to see that the dimension
  2429. 1:26:08manager has like an ID, name, email,
  2430. 1:26:10team. And it going to look identical to
  2431. 1:26:13the salesperson. We have as well ID,
  2432. 1:26:15name, email, team, and so on. So this
  2433. 1:26:18going to be like an indicator for you to
  2434. 1:26:19say, you know what, let's go and make
  2435. 1:26:21from this roleplaying dimension. So of
  2436. 1:26:24course now the question is how we going
  2437. 1:26:26to merge those two into one dimension.
  2438. 1:26:28As usual we have to do transformations
  2439. 1:26:31using power query. So let's go to
  2440. 1:26:33transform data. Okay. So now we are
  2441. 1:26:35inside and we see here the manager and
  2442. 1:26:37the person. Of course in order to make a
  2443. 1:26:39union between those two tables we have
  2444. 1:26:42to stack them and for that we have the
  2445. 1:26:44append queries. We are not merging. So
  2446. 1:26:47we are just like stacking the tables on
  2447. 1:26:50top of each others. But now if we do
  2448. 1:26:51this immediately we're going to lose a
  2449. 1:26:53very important information to understand
  2450. 1:26:55where the data come from. So for example
  2451. 1:26:58here is Anna is a saleserson or a
  2452. 1:27:00manager. That's why before we append we
  2453. 1:27:03have to go and add a column. That's
  2454. 1:27:05going to help us to understand the
  2455. 1:27:06source of each row. So in order to add a
  2456. 1:27:09new column we're going to go over here
  2457. 1:27:10and say add column. We're going to go
  2458. 1:27:12and say custom column. So we're going to
  2459. 1:27:14give it a name. It's going to be the
  2460. 1:27:16role. And now we have to define what is
  2461. 1:27:18the value for each row. This is going to
  2462. 1:27:20be a static value. So we will not go and
  2463. 1:27:22select any other available columns. It's
  2464. 1:27:24going to be always a same static value
  2465. 1:27:27the saleserson. So actually that's it.
  2466. 1:27:29This is the column name and this is the
  2467. 1:27:31static value. Let's go and say okay. And
  2468. 1:27:33now with this we can see for each row we
  2469. 1:27:35have the same value saleserson. Now we
  2470. 1:27:37have to go and do the same thing for the
  2471. 1:27:39managers so that we don't lose this
  2472. 1:27:41important information. Again a custom
  2473. 1:27:43column. It's going to be the role and a
  2474. 1:27:45static value. So you're going to be the
  2475. 1:27:47manager. That's it. Let's go and hit
  2476. 1:27:50okay. Look at this. We have for each
  2477. 1:27:51person now the role of manager. Okay. So
  2478. 1:27:55with this we prepared the two dimensions
  2479. 1:27:57now to get appended. I'm going to go to
  2480. 1:27:59the saleserson then home and we're going
  2481. 1:28:02to go and say append. So we are
  2482. 1:28:03appending two tables. Append to the
  2483. 1:28:06table manager. All right. Now look at
  2484. 1:28:08this. Each person has the role of
  2485. 1:28:11manager. So with this we have now the
  2486. 1:28:13role for the two tables. But I think
  2487. 1:28:15that we're going to do with that before
  2488. 1:28:16we append. We have to make sure that all
  2489. 1:28:18column names are the same. So here we
  2490. 1:28:21have name, email, team, and so on. The
  2491. 1:28:24only difference is actually the ID. So
  2492. 1:28:26what we're going to do is that we're
  2493. 1:28:27going to go and rename it. So instead of
  2494. 1:28:30salesperson ID, it's going to be an ID.
  2495. 1:28:32And same thing for the managers going to
  2496. 1:28:35go and rename it to ID. So as you can
  2497. 1:28:37see, I'm trying to bring those two
  2498. 1:28:39tables to become really identical. only
  2499. 1:28:41after preparation we go and merge the
  2500. 1:28:44two dimensions into one. Now we are
  2501. 1:28:46ready. So I'm going to go to the
  2502. 1:28:47saleserson and from here I'm going to go
  2503. 1:28:49and append the second table the manager.
  2504. 1:28:52All right we are appending two tables.
  2505. 1:28:53The second table going to be the
  2506. 1:28:55dimension manager. Let's go and hit
  2507. 1:28:57okay. Look at this. The main thing that
  2508. 1:28:59we are not getting any nulls which is
  2509. 1:29:01perfect. So we have here now 10 persons.
  2510. 1:29:03The names the email the team and very
  2511. 1:29:05important of course the role. Now the
  2512. 1:29:08last step that we're going to do is that
  2513. 1:29:09we're going to go and rename this
  2514. 1:29:10because this is not anymore the
  2515. 1:29:12saleserson. This is a generic one the
  2516. 1:29:14role playing dimension. So I'm going to
  2517. 1:29:16go and call it dim employee and of
  2518. 1:29:19course we don't need the manager. So I'm
  2519. 1:29:21going to go and disable it. Don't enable
  2520. 1:29:23load so that we don't see it in our
  2521. 1:29:25model. Okay. So this is our role playing
  2522. 1:29:28dimension. Let's go and save and close
  2523. 1:29:30everything. Now look at this. We got
  2524. 1:29:32only one dimension for the employee and
  2525. 1:29:34not two. And of course now comes the
  2526. 1:29:36very important question how to connect
  2527. 1:29:38the role playing dimension to our facts.
  2528. 1:29:40So again we have two roles that means
  2529. 1:29:42two relationships. The first one I think
  2530. 1:29:45it is working. So we have between the
  2531. 1:29:47saleserson from the fact and the ID and
  2532. 1:29:50this is an active one but we need the
  2533. 1:29:52second one. So what we're going to do
  2534. 1:29:53we're going to grab the ID and now put
  2535. 1:29:55it on the manager ID. So yes this is one
  2536. 1:29:58to many relationship but of course we
  2537. 1:30:00cannot activate it because we have
  2538. 1:30:01already one active relationship to our
  2539. 1:30:04facts. So look at this. This is exactly
  2540. 1:30:07the role playinging dimension. You have
  2541. 1:30:09two relationships. One of them is active
  2542. 1:30:10and the other is inactive. All right. So
  2543. 1:30:12with this we are done with the data
  2544. 1:30:14modeling. Now of course comes the big
  2545. 1:30:15question. How we going to go and use
  2546. 1:30:17those two relationships at the same
  2547. 1:30:19time. So let's go to the report view in
  2548. 1:30:21order to make an example. At the start
  2549. 1:30:24let's go and see the total sales for
  2550. 1:30:26each employee. So, we're going to go
  2551. 1:30:28grab the name, the role, and of course,
  2552. 1:30:30we need the total sales. And that's
  2553. 1:30:32means we're going to go to the fact
  2554. 1:30:33table and grab the line total [snorts]
  2555. 1:30:35and drop it over here. Now, of course,
  2556. 1:30:37the question is which relationship did
  2557. 1:30:39PowerBI uses in order to connect the
  2558. 1:30:41employee and the sales. This is my
  2559. 1:30:44friends, the active one. So, that means
  2560. 1:30:46it is connecting the ID with the
  2561. 1:30:48saleserson and not the manager ID.
  2562. 1:30:51Manager ID is inactive. And with this we
  2563. 1:30:53got a really nice total sales for each
  2564. 1:30:56person. So far nothing crazy right? This
  2565. 1:30:58is like the default setup in PowerBI.
  2566. 1:31:00But now of course comes the question how
  2567. 1:31:02we going to show side by side as well
  2568. 1:31:05the total sales for each team not
  2569. 1:31:08[clears throat] for each individual
  2570. 1:31:09person. So that means I would like to
  2571. 1:31:10see the line total but using the
  2572. 1:31:13relationship manager ID to the dimension
  2573. 1:31:16employee. Now, of course, in order to do
  2574. 1:31:18that, we have to go and create an extra
  2575. 1:31:20calculation in the fact in order to use
  2576. 1:31:23this relationship. So, we're going to go
  2577. 1:31:24and write a DAX. So, how to do it? Right
  2578. 1:31:26click on the fact and say new measure.
  2579. 1:31:28And then we get here a new window. In
  2580. 1:31:30order to write the calculation, I'm
  2581. 1:31:32going to go and expand it. So, now we're
  2582. 1:31:33going to do it step by step. It is not
  2583. 1:31:35that hard. So, first of all, I'm going
  2584. 1:31:36to call it sales by team. So, this is
  2585. 1:31:39the name of the new field. So, now of
  2586. 1:31:41course the question is what we are
  2587. 1:31:43calculating? we are aggregating the line
  2588. 1:31:45of total. So very simple, we're going to
  2589. 1:31:47say sum and then we're going to go and
  2590. 1:31:49find the table. So it's going to be the
  2591. 1:31:51fact sales and we are searching for line
  2592. 1:31:53total. So this you're going to get the
  2593. 1:31:55total sales. But of course, if you leave
  2594. 1:31:57it like this, then you're going to get
  2595. 1:31:59the same effect like before. PowerBI
  2596. 1:32:01going to go and use the active
  2597. 1:32:03relationship between the fact and the
  2598. 1:32:04dimension. But no, we don't want that.
  2599. 1:32:07We want PowerBI to use the inactive
  2600. 1:32:09relationship. And for that we have the
  2601. 1:32:11nice function use relationship so that I
  2602. 1:32:14force PowerBI to use it the way that I
  2603. 1:32:16want. So here we just have to define the
  2604. 1:32:18keys between the two tables. So it is
  2605. 1:32:20between the fact sales and this time we
  2606. 1:32:23need the manager ID and the manager ID
  2607. 1:32:26goes to the dimension employee and here
  2608. 1:32:29we have only the ID. So it is very
  2609. 1:32:32simple. We are just saying okay go and
  2610. 1:32:34calculate the total sales but use the
  2611. 1:32:36relationship. Then we define the keys.
  2612. 1:32:38So the manager ID to the employee ID.
  2613. 1:32:41Now let's go and get out. Now look at
  2614. 1:32:43this. We have new extra column inside
  2615. 1:32:46our fact called sales by team. It has as
  2616. 1:32:49well this calculation icon because we
  2617. 1:32:50just calculated. It has as well this
  2618. 1:32:52calculation item means we are
  2619. 1:32:54calculating this column. And now by
  2620. 1:32:56going to this you have now the two
  2621. 1:32:57options. Either you want the total sales
  2622. 1:32:59using the active relationship by just
  2623. 1:33:02dragging the line total like we have
  2624. 1:33:04done at the start or if you want the
  2625. 1:33:05same measure but using another inactive
  2626. 1:33:08relationship. We're going to go and grab
  2627. 1:33:09our calculation and put it in the
  2628. 1:33:11visual. Look at this. I'm able now to
  2629. 1:33:13see everything side by side. I can see
  2630. 1:33:15over here for example pop. You can see
  2631. 1:33:17in one go his total sales as a
  2632. 1:33:20salesperson and the total sales as a
  2633. 1:33:22manager for his whole team. Now for Anna
  2634. 1:33:25of course she has no team. So that's why
  2635. 1:33:27we don't see any number. For the other
  2636. 1:33:29managers, they are not making any sales.
  2637. 1:33:31That's why you're going to see here
  2638. 1:33:32nulls. But you're going to see their
  2639. 1:33:34total sales for their themes. As you can
  2640. 1:33:36see, my friends, in one go, in one
  2641. 1:33:38visual, we are able to use multiple
  2642. 1:33:40relationships between the two tables,
  2643. 1:33:42the fact and the dimension. And this is
  2644. 1:33:44exactly the power of the roleplaying
  2645. 1:33:46dimension. I don't have here like two,
  2646. 1:33:48three, four tables. I have everything in
  2647. 1:33:51one table in one go. And in the future
  2648. 1:33:53if I got like an access to another role
  2649. 1:33:56I'm going to go and integrate it inside
  2650. 1:33:58the employee table so that I reduce the
  2651. 1:34:01number of dimensions around the fact and
  2652. 1:34:03I'm going to be very flexible using the
  2653. 1:34:05relationships in order to do the
  2654. 1:34:07aggregations. Okay. So now let's do a
  2655. 1:34:09quick recap. Role playing dimension. It
  2656. 1:34:11is one dimension that plays multiple
  2657. 1:34:13roles in the same fact. You're going to
  2658. 1:34:15use it when you see you have multiple
  2659. 1:34:17entities that have the same structure,
  2660. 1:34:19the same schema. And you're going to
  2661. 1:34:21have the fact that is pointing using
  2662. 1:34:23multiple ids to the same [music] entity.
  2663. 1:34:29All right friends. So now finally we're
  2664. 1:34:31going to start talking about a concept
  2665. 1:34:32that is not that easy. The fact tables.
  2666. 1:34:35This one confuses a lot of people and I
  2667. 1:34:37think it get people lost in data
  2668. 1:34:39modeling once they start working with
  2669. 1:34:41facts. But the good news is that there
  2670. 1:34:43is like one trick one very simple
  2671. 1:34:45concept. If you understand it then
  2672. 1:34:47suddenly working with fact tables going
  2673. 1:34:49to feel easy. And here I'm talking about
  2674. 1:34:52understanding the grain in the facts. So
  2675. 1:34:54now of course the big question is what
  2676. 1:34:56is a grain? The grain is the level of
  2677. 1:34:58details that one row in your fact table
  2678. 1:35:01represents. So now of course in order to
  2679. 1:35:04understand what this exactly means we're
  2680. 1:35:06going to have very simple example. All
  2681. 1:35:07right. So in this example we have three
  2682. 1:35:09fact tables and at the start if you look
  2683. 1:35:11at this inside your data model you're
  2684. 1:35:13going to get the feeling they are all
  2685. 1:35:14like the same. The total number of sales
  2686. 1:35:17is like identical and we are speaking
  2687. 1:35:19about the same business. So they are
  2688. 1:35:21very similar fact tables. But now my
  2689. 1:35:23friends if you zoom in and start looking
  2690. 1:35:25to the details you're going to
  2691. 1:35:27understand those three fact tables are
  2692. 1:35:29completely different from each others.
  2693. 1:35:31And that's because of one thing the
  2694. 1:35:33grain is different. Each table has
  2695. 1:35:35different level of details. Okay, let me
  2696. 1:35:37show you what I mean. Let's start with
  2697. 1:35:38the first table. So here we have the
  2698. 1:35:40fact sales. Now you have to ask this
  2699. 1:35:42question. What does one row in this
  2700. 1:35:45table represent? So we have to try to
  2701. 1:35:47explain it in one sentence. So now you
  2702. 1:35:49can see that this one row is actually
  2703. 1:35:52part of like one order. So here we can
  2704. 1:35:54see that we ordered three products in
  2705. 1:35:57the same order number, right? That means
  2706. 1:35:59each row is representing one line of one
  2707. 1:36:02order. And this is my friend the grain
  2708. 1:36:04of this fact table. Each row represent a
  2709. 1:36:06line. Same thing here. For example, in
  2710. 1:36:08this order, the one row representing one
  2711. 1:36:10line of order. So this is the grain for
  2712. 1:36:13the first table. Let's go to the second
  2713. 1:36:14one. Again, we have to ask the same
  2714. 1:36:16question. What does one row represent?
  2715. 1:36:18Now, if you go and pick one row and say
  2716. 1:36:21loud, each row here is representing the
  2717. 1:36:24whole order. It doesn't matter how many
  2718. 1:36:26products did we order. It could be one
  2719. 1:36:28product, 10 products. It's still going
  2720. 1:36:30to be only one row. So my friends the
  2721. 1:36:32grain in this fact table going to be the
  2722. 1:36:35whole order. It is not anymore like
  2723. 1:36:37detailed like the fact sales right. So
  2724. 1:36:39it has like less details than the first
  2725. 1:36:42facts. Same thing if I go to another row
  2726. 1:36:44like for example over here. This one is
  2727. 1:36:46representing the order. But if I go to
  2728. 1:36:48the other fact you can see it contains
  2729. 1:36:50two products. This is the grain of this
  2730. 1:36:53table. Now let's go to the last one.
  2731. 1:36:55Same thing. Ask the same question. What
  2732. 1:36:57does one row represent in this fact? Now
  2733. 1:36:59if you go and check each row you can see
  2734. 1:37:01we don't have anymore the orders like
  2735. 1:37:03each row is representing one month. We
  2736. 1:37:06have January, February and March. So
  2737. 1:37:08that means each row here is representing
  2738. 1:37:10a month of sales right? So the grain for
  2739. 1:37:12this fact table going to be the month
  2740. 1:37:14and of course here it is highly
  2741. 1:37:15aggregated compared to the other facts.
  2742. 1:37:18Other facts contains more details. So
  2743. 1:37:20that means my friends all those three
  2744. 1:37:22facts have different grains and
  2745. 1:37:24different level of details. The first
  2746. 1:37:26one fact sales is the most detailed one.
  2747. 1:37:28One row represent one line of order and
  2748. 1:37:31in the second fact we are losing those
  2749. 1:37:33details. So the fact order the grain
  2750. 1:37:35here is the whole order and the third
  2751. 1:37:37fact sales monthly. The level of detail
  2752. 1:37:40here is really low. So we have here high
  2753. 1:37:42aggregation and the grain here is month
  2754. 1:37:45of sales. We don't see any details about
  2755. 1:37:47the orders or the line of orders. So
  2756. 1:37:50this is what we mean with the grain. It
  2757. 1:37:52is not that hard. Right?
  2758. 1:37:53>> That's what she said. And from now on,
  2759. 1:37:55each time you see a fact table in your
  2760. 1:37:57model, you're going to ask this one
  2761. 1:37:59simple question and you're going to say
  2762. 1:38:00it loud. What does each row represent in
  2763. 1:38:03my facts? And once you answer this
  2764. 1:38:05question, then everything going to be
  2765. 1:38:07simple for you. You're going to
  2766. 1:38:08understand your fact. You're going to
  2767. 1:38:09understand how to connect it inside your
  2768. 1:38:11data model. But what is way more
  2769. 1:38:13important, you're going to write correct
  2770. 1:38:16DAX calculations on top of your fact. So
  2771. 1:38:18my friends, understanding the grain is
  2772. 1:38:20the first thing that you're going to do
  2773. 1:38:22once you start data moduling. And as
  2774. 1:38:24well once you understand it then you
  2775. 1:38:25have really solid foundations otherwise
  2776. 1:38:28things might go wrong. So now let me
  2777. 1:38:29show you an example why exactly it is
  2778. 1:38:32critical for calculations. Okay again
  2779. 1:38:34here we have one fact table the sales
  2780. 1:38:36and it looks simple right and now if I
  2781. 1:38:38go and start asking you business
  2782. 1:38:39questions for this fact and you jump
  2783. 1:38:41immediately to the calculations without
  2784. 1:38:44understanding the grain of this fact you
  2785. 1:38:46might start doing wrong calculations.
  2786. 1:38:48Like for example if I tell you go and
  2787. 1:38:50find the total number of orders. Now you
  2788. 1:38:52might say okay this is really simple I'm
  2789. 1:38:54going to go and count the order ids
  2790. 1:38:56inside the fact and you tell me okay we
  2791. 1:38:58have six orders in the table my friend
  2792. 1:39:00that was really quick look again do we
  2793. 1:39:02have really six orders well no right we
  2794. 1:39:05have here only three orders so my
  2795. 1:39:07friends without like taking step back
  2796. 1:39:09and understanding the grain of your fact
  2797. 1:39:11table even if it's like simple like this
  2798. 1:39:13you're going to do wrong calculations so
  2799. 1:39:16what one row represent in this fact it
  2800. 1:39:18is a line of order so that means if I
  2801. 1:39:21want to find the total the number of
  2802. 1:39:22orders in this very detailed fact table.
  2803. 1:39:25I have to go and count the order ID but
  2804. 1:39:28using distinct counts. So I'm counting
  2805. 1:39:30one ID only once and with that you're
  2806. 1:39:32going to get three orders. Now of course
  2807. 1:39:34in some calculations you're going to be
  2808. 1:39:35lucky like for example if you go over
  2809. 1:39:37here and I tell you find the total sales
  2810. 1:39:39inside our business. You're going to go
  2811. 1:39:41and make the sum of this column and
  2812. 1:39:43you're going to get it correct. All
  2813. 1:39:44right. So now let's move to the third
  2814. 1:39:46one. This going to be tricky one. If I
  2815. 1:39:48ask you to find the total cost of
  2816. 1:39:50shipping, if you don't understand the
  2817. 1:39:51grains, you're going to go immediately
  2818. 1:39:53to the shipping and say, okay, the sum
  2819. 1:39:55of all those values and this is wrong,
  2820. 1:39:57my friends. Because look at this, the
  2821. 1:39:59same cost is like repeating for each
  2822. 1:40:01line, right? And this of course makes
  2823. 1:40:03sense because the cost of shipping going
  2824. 1:40:05to be for the whole order, right? For
  2825. 1:40:07all products. So that means if you go
  2826. 1:40:09blindly and start like aggregating all
  2827. 1:40:10those values and you tell me, okay, the
  2828. 1:40:12total cost of shipping is 450. This is
  2829. 1:40:14wrong. You still have to be careful with
  2830. 1:40:16the grain and it is way more correct if
  2831. 1:40:19you say okay I'm going to go and find
  2832. 1:40:20the highest shipping cost in the whole
  2833. 1:40:23order in case we got like wrong numbers
  2834. 1:40:25or different pricing you're going to go
  2835. 1:40:26with the highest one and with that the
  2836. 1:40:28total cost of shipping is 200 and here
  2837. 1:40:31comes really something important to
  2838. 1:40:32understand that in one table we have
  2839. 1:40:35different columns with different grains
  2840. 1:40:37and the grain of the line of sales is
  2841. 1:40:40actually the line of order and not the
  2842. 1:40:42whole order and if you go and compare it
  2843. 1:40:44to the shipping Here we have different
  2844. 1:40:46grain in this column. It is again the
  2845. 1:40:48order itself and not the line of order.
  2846. 1:40:50So that means not only you have to
  2847. 1:40:52understand what each one row is
  2848. 1:40:55representing but as well you have to
  2849. 1:40:56understand your numbers at which level
  2850. 1:40:59they are. It could be as the same level
  2851. 1:41:01as the table itself like the line of
  2852. 1:41:03sales or it could be a different
  2853. 1:41:05aggregated grain like we had in the
  2854. 1:41:08shipping and the order ID. So my
  2855. 1:41:10friends, as you can see, even with a
  2856. 1:41:11very simple fact table, you might do
  2857. 1:41:14wrong calculations if you don't
  2858. 1:41:15understand the grain of your table and
  2859. 1:41:17as well the grain of each column.
  2860. 1:41:19Otherwise, you're going to be delivering
  2861. 1:41:21wrong numbers to the business and they
  2862. 1:41:23might do wrong decisions. [music]
  2863. 1:41:28All right friends, so now we come to the
  2864. 1:41:30most confusing topic in data modeling.
  2865. 1:41:32How to work with multiple facts. Here I
  2866. 1:41:34can tell you from my projects I saw a
  2867. 1:41:36lot of weird things a lot of mistakes
  2868. 1:41:38that happens in data modeling once you
  2869. 1:41:41start working with facts. So what
  2870. 1:41:42happened that people see like two facts
  2871. 1:41:44and they might noticed okay they are
  2872. 1:41:46sharing a common column and usually
  2873. 1:41:48comes the idea why not to go and build a
  2874. 1:41:51relationship between them. I would like
  2875. 1:41:52to combine those two. Maybe others going
  2876. 1:41:54to say you know what let's go and merge
  2877. 1:41:56those two facts together or maybe go and
  2878. 1:41:58append those two facts. So you have
  2879. 1:42:01different opinions and different designs
  2880. 1:42:02and at the end all what you want to do
  2881. 1:42:04is I would like to do some analyszis
  2882. 1:42:06like colorations in order to compare the
  2883. 1:42:09numbers between those two facts. So at
  2884. 1:42:11the start this sounds smart but once you
  2885. 1:42:13start like combining building
  2886. 1:42:15relationships you're going to understand
  2887. 1:42:17this going to be the main mistake that
  2888. 1:42:19you do in data modeling that going to
  2889. 1:42:20generate a lot of issues and wrong
  2890. 1:42:22numbers in the reports. And this is
  2891. 1:42:25exactly what we're going to do now. I'm
  2892. 1:42:26going to show you multiple scenarios,
  2893. 1:42:28multiple fact tables, show you the bad
  2894. 1:42:30data modeling design and of course I'm
  2895. 1:42:32going to show you the solutions, the
  2896. 1:42:33best practices. So now let's get
  2897. 1:42:35started. All right. So now let's start
  2898. 1:42:36with this very simple scenario. We have
  2899. 1:42:38two fact tables. Fact sales US and fact
  2900. 1:42:41sales EU. Now before we do anything, we
  2901. 1:42:43have to understand those two facts and
  2902. 1:42:45we start with the very important
  2903. 1:42:46question. What is the grain? What each
  2904. 1:42:49row is representing? On the left side,
  2905. 1:42:51each row is actually representing one
  2906. 1:42:53order. So we have 1 2 3 4. If you go to
  2907. 1:42:55the right side, it is the same thing.
  2908. 1:42:57Each row is representing actually an
  2909. 1:42:59order as well. So this is the first
  2910. 1:43:01thing that we understood from those two
  2911. 1:43:03facts. They have the same grain. It is
  2912. 1:43:05the order. So this is the first thing
  2913. 1:43:07that we have understood. Now the second
  2914. 1:43:08thing is to check what we are talking
  2915. 1:43:10about inside each table. What is the
  2916. 1:43:12event on the left side? You can see the
  2917. 1:43:14event is actually a sales is happening.
  2918. 1:43:16So we have an order ID, customer, a
  2919. 1:43:18product, and the total amount of sales.
  2920. 1:43:20So it is an event about the sales. Now
  2921. 1:43:22let's go and check the right side. Well,
  2922. 1:43:24it is the same event as well. Sales are
  2923. 1:43:27happening here. Order ID, customer,
  2924. 1:43:29product and total amount of sales. So
  2925. 1:43:31thus means those two fact tables are
  2926. 1:43:33actually not only having the same grain
  2927. 1:43:35but as well they are identical. They are
  2928. 1:43:37talking about the same event. They have
  2929. 1:43:39as well the same structure, the same
  2930. 1:43:41shape. They are just splitted into two
  2931. 1:43:43tables. And this happens a lot in real
  2932. 1:43:45world because source systems usually
  2933. 1:43:47tend to split things into multiple
  2934. 1:43:49tables. So here they split by the
  2935. 1:43:51region, by countries, maybe by dates as
  2936. 1:43:54well. Very classical one, they split
  2937. 1:43:55tables by years, but at the end it is
  2938. 1:43:58the same table, but it's splited into
  2939. 1:44:00multiple tables in order to make things
  2940. 1:44:02more manageable or maybe for security
  2941. 1:44:04reasons. So now this is the setup. And
  2942. 1:44:06now of course the big question is if I
  2943. 1:44:07want to go and build a reports where I
  2944. 1:44:10need data from the left and from the
  2945. 1:44:11right. So what you're going to do in the
  2946. 1:44:13data modeling in order to build this
  2947. 1:44:15visual either you're going to go and
  2948. 1:44:17build a relationship or you're going to
  2949. 1:44:18go and combine those two tables into one
  2950. 1:44:21by using merge or append. So you have to
  2951. 1:44:23decide on what to do with those two
  2952. 1:44:25facts inside the data model. Now let's
  2953. 1:44:27start with the first one about the
  2954. 1:44:28relationships. It makes no sense to
  2955. 1:44:30build a relationship between those two
  2956. 1:44:31because they are identical tables and
  2957. 1:44:33usually we build a relationship between
  2958. 1:44:35two different things like sales and
  2959. 1:44:38customers orders and products. So that
  2960. 1:44:40means it makes no sense to build a
  2961. 1:44:42relationship between those two facts.
  2962. 1:44:44What is left is to go and combine them
  2963. 1:44:45into one. And here we have the two
  2964. 1:44:46options, merge or append. Now if you go
  2965. 1:44:49and merge those two, it will not work
  2966. 1:44:50because yes, you have a key like the
  2967. 1:44:52order ID. But actually there is no match
  2968. 1:44:55between them. Here they start with the
  2969. 1:44:561,001 and here they start with the
  2970. 1:44:582,000s. So if you merge those two, you
  2971. 1:45:01will not get any result. What is way
  2972. 1:45:03better is to go and append those two
  2973. 1:45:05together. So you go and stack them on
  2974. 1:45:07top of each others. And with this you're
  2975. 1:45:08going to get all the orders inside your
  2976. 1:45:10business. So with this you got all the
  2977. 1:45:12eight orders and things looks healthy
  2978. 1:45:14right? But there is like small mistake
  2979. 1:45:16that we have in the module or in this
  2980. 1:45:18one table. We don't know anymore which
  2981. 1:45:20order comes from where. So we lost this
  2982. 1:45:22small information in the table name.
  2983. 1:45:24From here we can see the orders come
  2984. 1:45:26from the US and on the right side we can
  2985. 1:45:28see they come from the EU. That's why in
  2986. 1:45:30best practices if you go and append two
  2987. 1:45:32tables go and create a new column like
  2988. 1:45:34for example here the source in order to
  2989. 1:45:36know where those sales come from. So
  2990. 1:45:39with this after combining the two facts
  2991. 1:45:41into one we will not lose any
  2992. 1:45:43information. And now of course the last
  2993. 1:45:44question is can we use now this fact
  2994. 1:45:46table in order to do aggregations? Well
  2995. 1:45:48yes if you go and find the total amount
  2996. 1:45:50of sales you're going to get a correct
  2997. 1:45:52number. You will not get anything
  2998. 1:45:53corrupted. So this my friends the best
  2999. 1:45:55way to react on this scenario. If you
  3000. 1:45:57have two tables having the same grain,
  3001. 1:45:59having the same event, the same shape so
  3002. 1:46:01they are completely identical, go and
  3003. 1:46:04append them together into one single
  3004. 1:46:06facts. But of course, don't forget to
  3005. 1:46:07add this new column in order to
  3006. 1:46:09understand the source of each row. Okay,
  3007. 1:46:11so that was an easy scenario. Now let's
  3008. 1:46:13go to another one where we have as well
  3009. 1:46:14two fact tables. This time we have the
  3010. 1:46:17fact sales and on the right side we have
  3011. 1:46:18the fact revenue. Same thing before we
  3012. 1:46:20do anything we have to understand the
  3013. 1:46:21content of those two facts. So what is
  3014. 1:46:24the grain on the left side? Each row is
  3015. 1:46:26representing one order. On the right
  3016. 1:46:28side, same thing. Each row is
  3017. 1:46:29representing as well one order. So again
  3018. 1:46:32we have two fact tables with the same
  3019. 1:46:33grain. Now the second question are they
  3020. 1:46:35are dealing with the same events? Well
  3021. 1:46:37on the left side like the previous
  3022. 1:46:39scenario we are dealing with the sales.
  3023. 1:46:41So we have an order ID, customer and the
  3024. 1:46:43total sales. But now on the right side
  3025. 1:46:45this time we have different event. Yes
  3026. 1:46:47we have the order ID but we are talking
  3027. 1:46:49about the source of the revenue and as
  3028. 1:46:51well the total number of the revenue. So
  3029. 1:46:53this is the setup. We have the same
  3030. 1:46:54grain. We have different events but we
  3031. 1:46:56are talking about the same thing about
  3032. 1:46:58the orders. Now of course same question.
  3033. 1:47:00What we going to do if we need to build
  3034. 1:47:02a reports and we need informations from
  3035. 1:47:04those two fact sales. Are we going to go
  3036. 1:47:06connect them using a relationship or go
  3037. 1:47:08and combine them into one fact using
  3038. 1:47:10merge or append. So now let's start with
  3039. 1:47:12the relationship. If you go and connect
  3040. 1:47:14them you're going to get the cardality
  3041. 1:47:16one to one. Well usually if we have one
  3042. 1:47:18to one relationship it makes no sense to
  3043. 1:47:20keep them splitted. It's way better if
  3044. 1:47:22you just combine them into one table.
  3045. 1:47:24But of course, always under one
  3046. 1:47:26condition if they have the same grain.
  3047. 1:47:29So what are the other options? We're
  3048. 1:47:30going to go and combine those two facts
  3049. 1:47:32tables into one single fact. Here we
  3050. 1:47:34have two options either append or merge.
  3051. 1:47:36Now I found a lot of projects where they
  3052. 1:47:38go and actually append those two facts
  3053. 1:47:41together. So they look like almost
  3054. 1:47:42similar those two fact tables. You have
  3055. 1:47:45an ID, you have maybe something that is
  3056. 1:47:47describing the ID and then the measure
  3057. 1:47:49the total sales. So they are not
  3058. 1:47:51identical but they have the same pattern
  3059. 1:47:53that's why they go and like append them
  3060. 1:47:55together. So if you look at this you're
  3061. 1:47:56going to say wow this looks nice right I
  3062. 1:47:58have all the orders here I have the
  3063. 1:48:00measures and I can see the grain so the
  3064. 1:48:03measure type that I have in the amount
  3065. 1:48:05so things looks clean and with this I
  3066. 1:48:07can go and do multiple like analyzes and
  3067. 1:48:09I have some dynamic well you can go and
  3068. 1:48:11do that of course but you have to be
  3069. 1:48:13very careful each time you use this fact
  3070. 1:48:15table like for example if you don't
  3071. 1:48:16explain this for the others and someone
  3072. 1:48:18goes and start like doing a sum of the
  3073. 1:48:21amount they're going to go and get like
  3074. 1:48:223,500 and this makes no sense Because
  3075. 1:48:26here those numbers they have different
  3076. 1:48:27meanings for each row. In one row this
  3077. 1:48:30number is a sales but in another row
  3078. 1:48:32this number is revenue. So if you go
  3079. 1:48:34blindly and do a total sales on this
  3080. 1:48:36fact or maybe an average for the sales
  3081. 1:48:38you're going to get of course wrong
  3082. 1:48:40numbers in the reports and you have
  3083. 1:48:42always to be careful that you do the
  3084. 1:48:44aggregations based on the grain. And
  3085. 1:48:46this of course makes everything
  3086. 1:48:47complicated and open the door for many
  3087. 1:48:50mistakes. That's why I never recommend
  3088. 1:48:52to append it like this. Instead, we go
  3089. 1:48:54and merge them. So, you're going to say,
  3090. 1:48:56you know what, they are sharing onetoone
  3091. 1:48:58relationship. I'm going to go and just
  3092. 1:49:00put everything side by side. So, I have
  3093. 1:49:02the order ID, I have the customer, the
  3094. 1:49:04source, the sales, and the revenue. And
  3095. 1:49:06with that, my measures are actually not
  3096. 1:49:08mixing together. And it's still very
  3097. 1:49:10easy to analyze. Like for example, if I
  3098. 1:49:12need to find the total sales, I'm just
  3099. 1:49:14going to go to this column over here and
  3100. 1:49:16find the total sales. Same thing for the
  3101. 1:49:18revenue. So yes, I have wider table and
  3102. 1:49:20I have more columns inside my data
  3103. 1:49:22model, but doing aggregations and stuff
  3104. 1:49:25on the fact it is way easier and safe
  3105. 1:49:28compared to the append. So my friends,
  3106. 1:49:29in this scenario, if you have two fact
  3107. 1:49:31tables that have the same grain like
  3108. 1:49:33this, they have one to one
  3109. 1:49:35relationships. They are not identical.
  3110. 1:49:37So they have like different events or
  3111. 1:49:39different columns. Then just go and
  3112. 1:49:40combine them, merge them together into
  3113. 1:49:42one single fact table. And don't use
  3114. 1:49:44append if they are not exactly
  3115. 1:49:47identical. Okay. So let's keep moving
  3116. 1:49:48now to the third scenario. Things going
  3117. 1:49:50to get a little bit more advanced. So
  3118. 1:49:51again we have two fact tables. The fact
  3119. 1:49:53sales and the fact budget. We have to
  3120. 1:49:55start with the first question. What is
  3121. 1:49:56the grain? So what each row is
  3122. 1:49:58representing in each fact. You can see
  3123. 1:50:00that in the fact sales is actually each
  3124. 1:50:02row is one order. So it is very simple.
  3125. 1:50:05But now if you go to the fact budget you
  3126. 1:50:07can see that each row is actually a
  3127. 1:50:09month. It is the planned budget for
  3128. 1:50:11specific product in a month. So for
  3129. 1:50:13example for the product laptop we can
  3130. 1:50:15see that in January we have so much
  3131. 1:50:17budget and for February we have another
  3132. 1:50:19planned budget for it. So that means my
  3133. 1:50:21friend the grain is different between
  3134. 1:50:23those two tables they have completely
  3135. 1:50:25different level of details. Now the next
  3136. 1:50:27question are we talking about the same
  3137. 1:50:29events the same structure well they are
  3138. 1:50:31totally different from each others. The
  3139. 1:50:33fact sales here the event is sales is
  3140. 1:50:35happening but on the right side planning
  3141. 1:50:37is happening. So for each month for each
  3142. 1:50:40product we have a planned budget as
  3143. 1:50:41well. The structure it is totally
  3144. 1:50:43different. Here we don't have any ids.
  3145. 1:50:44On the left side we have an order ID. So
  3146. 1:50:47those two fact tables they are
  3147. 1:50:48completely different. They don't have
  3148. 1:50:50the same events. They are not sharing
  3149. 1:50:52the grain. They are not sharing the
  3150. 1:50:53event or the structure. And now of
  3151. 1:50:55course the question is if a business
  3152. 1:50:57user ask you to go and compare the sales
  3153. 1:51:00versus the budget by the product. So you
  3154. 1:51:02need data from those two facts into one
  3155. 1:51:05visual. What you have to do? So again we
  3156. 1:51:07have the same options. Either we're
  3157. 1:51:08going to build a relationship between
  3158. 1:51:09them or merge those two facts together
  3159. 1:51:11into one single fact. So now let's start
  3160. 1:51:13with combining everything together. Here
  3161. 1:51:15you have the two options either append
  3162. 1:51:17or merge. Well, it makes no sense to
  3163. 1:51:19append. Please don't do that unless they
  3164. 1:51:21are totally identical and they have the
  3165. 1:51:23same grain. But now a mistake that might
  3166. 1:51:25happen is that you can see you know what
  3167. 1:51:27we have a product on the left side and a
  3168. 1:51:29product on the right side. Actually we
  3169. 1:51:31can go and merge them together using
  3170. 1:51:33this key. So if you go and do that
  3171. 1:51:34you're going to get something like this.
  3172. 1:51:36So you have the order ID, you have the
  3173. 1:51:37month, you have all the products and
  3174. 1:51:39then you have the two measures, the
  3175. 1:51:41sales and the budget. So with this you
  3176. 1:51:42have everything like side by side and
  3177. 1:51:44you can go and compare them right. But
  3178. 1:51:46my friends those numbers going to makes
  3179. 1:51:48no sense at all once you start
  3180. 1:51:50aggregating. So if you go and give this
  3181. 1:51:51to your business users they're going to
  3182. 1:51:53say well actually we didn't plan so much
  3183. 1:51:55budget. We don't have like 9,000. We
  3184. 1:51:57have planned only 6K. So actually your
  3185. 1:52:00numbers are wrong and PowerBI has maybe
  3186. 1:52:02an issue. You're going to go to your
  3187. 1:52:03data model and check well actually we
  3188. 1:52:05have correct numbers we don't have like
  3189. 1:52:06wrong data inside PowerBI it's only the
  3190. 1:52:09decision that you have made to merge
  3191. 1:52:11those two together into one table
  3192. 1:52:13because my friend the relationship
  3193. 1:52:14between those two fact tables are
  3194. 1:52:16actually money to money like for example
  3195. 1:52:17on the left side the laptop if you
  3196. 1:52:19combine it with a budget you're going to
  3197. 1:52:20get actually two plan budget for this
  3198. 1:52:22product so you get the January and
  3199. 1:52:24February and you're going to have them
  3200. 1:52:26as two rows inside the new table and
  3201. 1:52:28same thing for example for the order
  3202. 1:52:30number three as well It going to connect
  3203. 1:52:32to two plan budget the January and
  3204. 1:52:35February. So with this you're going to
  3205. 1:52:36get the same budget inside the combined
  3206. 1:52:38table twice. One for the first order and
  3207. 1:52:41another one for the second order. And of
  3208. 1:52:42course this is really bad if you combine
  3209. 1:52:45two tables that has many to many
  3210. 1:52:47relationship. It will just cause
  3211. 1:52:48duplicates in the new combined table. So
  3212. 1:52:50no, you cannot go and combine those two
  3213. 1:52:53tables together. They don't have a key
  3214. 1:52:55between them and they have different
  3215. 1:52:56grains. So what are the other options?
  3216. 1:52:58Well, actually, we can go and build a
  3217. 1:53:00relationship between them, right? So,
  3218. 1:53:02you're going to start something like
  3219. 1:53:03this. You're going to leave them
  3220. 1:53:04separated so we don't merge. And you're
  3221. 1:53:06going to start picking maybe the product
  3222. 1:53:07ID from the fact sales in order to build
  3223. 1:53:09the visual and then put the sales for
  3224. 1:53:12each product. So, everything so far is
  3225. 1:53:13clean. Right now, what is missing is of
  3226. 1:53:15course the budget. So, what you're going
  3227. 1:53:16to do, you're going to go and relate
  3228. 1:53:18those two tables together using the
  3229. 1:53:20product. Again, you see here the money
  3230. 1:53:21to many relationship between those two.
  3231. 1:53:23And then you're going to go and grab the
  3232. 1:53:25budget and you put it on the visual. So
  3233. 1:53:27now if you go and give this as well to
  3234. 1:53:29the users, they're going to as well see
  3235. 1:53:31bad numbers in the visual. They're going
  3236. 1:53:32to say okay from one side you are
  3237. 1:53:34getting the total sales correct not like
  3238. 1:53:36the previous one as you merge the two
  3239. 1:53:38tables. But my friend that total budget
  3240. 1:53:40makes no sense. We didn't plan so much.
  3241. 1:53:43So again your report is wrong, your data
  3242. 1:53:45is wrong and they will not trust it. So
  3243. 1:53:46again you're going to go back to the
  3244. 1:53:47data model and you start adding those
  3245. 1:53:49numbers. Well it makes no sense. The
  3246. 1:53:51data is correct. It's all because you
  3247. 1:53:53are connecting directly two fact tables
  3248. 1:53:55together. And this can only cause
  3249. 1:53:57issues. From one hand, you are totally
  3250. 1:53:59depending on the products from the fact
  3251. 1:54:01sales. And this is a big issue because
  3252. 1:54:03in the fact sales you can see only the
  3253. 1:54:05products where sales happens. But maybe
  3254. 1:54:08on the budget you are planning for the
  3255. 1:54:10future. So you have a new product and
  3256. 1:54:11you have a budget for it. But no orders
  3257. 1:54:14yet happened to this new product. So for
  3258. 1:54:16example here the monitor we have a
  3259. 1:54:18budget for it but still we don't have
  3260. 1:54:19any sales for it. Now of course this
  3261. 1:54:21product now is missing from the report
  3262. 1:54:23because you are building the access for
  3263. 1:54:25the visual based on the products from
  3264. 1:54:27the fact sales. So that means you cannot
  3265. 1:54:30count on the products from the fact
  3266. 1:54:31sales. Same thing if you say you know
  3267. 1:54:33what let's go and use the products on
  3268. 1:54:34the right side as well. You will not get
  3269. 1:54:36the full big picture like for example
  3270. 1:54:38here the mouse we have an order for it
  3271. 1:54:40but we don't have a planned budget for
  3272. 1:54:42it. So it doesn't matter where you start
  3273. 1:54:44building the visual it will not work if
  3274. 1:54:46you are connecting two facts together.
  3275. 1:54:48And as well same thing since we have
  3276. 1:54:49many to many relationship we're going to
  3277. 1:54:51get this effect where the budget going
  3278. 1:54:52to fan out and you're going to get here
  3279. 1:54:54duplicates inside your visual and this
  3280. 1:54:56is of course what is causing the big
  3281. 1:54:58number of the budget. So actually my
  3282. 1:55:00friends we cannot append we cannot
  3283. 1:55:01combine we cannot build a relationship
  3284. 1:55:04between those two facts. We have only
  3285. 1:55:06one solution to make this clean and
  3286. 1:55:08that's by introducing something else. So
  3287. 1:55:11what we're going to do we're going to
  3288. 1:55:12get rid of this bad relationship between
  3289. 1:55:14those two facts and we're going to
  3290. 1:55:15introduce a new dimension in the middle.
  3291. 1:55:17So now you're going to hear a lot of
  3292. 1:55:19different names about this dimension
  3293. 1:55:20here in the middle. Some people call it
  3294. 1:55:22a shared dimension, others call it
  3295. 1:55:24confirmed dimension or you might hear
  3296. 1:55:27about the bridge table between two fact
  3297. 1:55:29tables. You can call it whatever you
  3298. 1:55:31want. At the end it is the same concept.
  3299. 1:55:33We're going to build one dimension where
  3300. 1:55:34it has the single point of truth. So it
  3301. 1:55:37is complete and it has all the products
  3302. 1:55:39in the business. So here should be
  3303. 1:55:41nothing missing. We have the laptop, we
  3304. 1:55:43have the phone, we have the monitor and
  3305. 1:55:45as well we have the mouse. So all the
  3306. 1:55:47products in the business and after that
  3307. 1:55:49we connect our facts to this single
  3308. 1:55:51dimension and if you do it like this on
  3309. 1:55:53one side you're going to get money to
  3310. 1:55:54one relationship between the sales and
  3311. 1:55:56the dimension and same thing on the
  3312. 1:55:58other side between the budget and the
  3313. 1:55:59dimension you're going to get one to
  3314. 1:56:00many. And now once you start building
  3315. 1:56:02the visual things going to be way easy
  3316. 1:56:04for the axis you start always from the
  3317. 1:56:06dimension in order to make sure that all
  3318. 1:56:09the products are inside my visual. So I
  3319. 1:56:12have all my four products and the
  3320. 1:56:13measures going to come from each fact.
  3321. 1:56:16So the total sales going to come from
  3322. 1:56:17the fact sales and the budget going to
  3323. 1:56:19come from the budget. So with this first
  3324. 1:56:20of all you make sure that nothing is
  3325. 1:56:22missing right? So we have here the
  3326. 1:56:24monitor. We don't have sales for it but
  3327. 1:56:26we have a budget for it and we have as
  3328. 1:56:28well the mouse where we have a total
  3329. 1:56:29sales for it but no budget. So with this
  3330. 1:56:32I'm getting completeness in my visual.
  3331. 1:56:34Nothing is missing and as well the
  3332. 1:56:36numbers going to be correct. There is no
  3333. 1:56:37more fan out effect like for the laptop.
  3334. 1:56:40things are connecting to my dimension
  3335. 1:56:42using the many to one relationship and
  3336. 1:56:44this will not cause any duplicate effect
  3337. 1:56:46in the visual. So this solution is a
  3338. 1:56:49clear win for me. I have the complete
  3339. 1:56:50picture. Nothing is missing and as well
  3340. 1:56:52my numbers are correct. My friends, if
  3341. 1:56:54you see two fact tables, two tables that
  3342. 1:56:56they have different grains, then you
  3343. 1:56:58have to be very careful. You might see
  3344. 1:57:00things that could be related to each
  3345. 1:57:02others or could be combined. Otherwise,
  3346. 1:57:04you're going to deliver only wrong
  3347. 1:57:05numbers. Leave them separated and
  3348. 1:57:07connect things only using a shared
  3349. 1:57:10dimension. Okay. So now to the last
  3350. 1:57:11scenario. This one going to be a little
  3351. 1:57:12bit tricky. So I need your full focus.
  3352. 1:57:14This is advanced. Again we have two fact
  3353. 1:57:16tables. So we have the sales, we have
  3354. 1:57:18the budget. We will not go through
  3355. 1:57:19everything. They have different grains.
  3356. 1:57:21They have different events. But the
  3357. 1:57:22thing is they don't connect using the
  3358. 1:57:25products. They connect only using a
  3359. 1:57:27higher level. So we have the category.
  3360. 1:57:29So this is a setup. And now the business
  3361. 1:57:31user has the same question. I would like
  3362. 1:57:33you to go and compare sales versus
  3363. 1:57:35budget but by the product. So again if
  3364. 1:57:37you go and build a direct relationship
  3365. 1:57:39between those two you're going to get of
  3366. 1:57:41course a wrong budget. We said you don't
  3367. 1:57:43do that. So instead what we're going to
  3368. 1:57:45do we're going to go and introduce the
  3369. 1:57:46shared dimension in between and the
  3370. 1:57:48shared dimension this time going to be
  3371. 1:57:50the category because they are not
  3372. 1:57:51sharing products right? They are sharing
  3373. 1:57:53category and after that you go and
  3374. 1:57:55connect your facts to the new dimension
  3375. 1:57:57category. Now the thing is we're going
  3376. 1:57:59to still have an issue in the visual
  3377. 1:58:00even if we introduce the shared
  3378. 1:58:02dimension between because the user is
  3379. 1:58:04asking us to compare those two measures
  3380. 1:58:06by the products and the products my
  3381. 1:58:08friends it's not an information that
  3382. 1:58:10exist in the budget right the budget
  3383. 1:58:12knows only about the categories and the
  3384. 1:58:14categories as I said it is a higher
  3385. 1:58:16aggregated level than the products so
  3386. 1:58:19that means with the products and the
  3387. 1:58:21fact sales we have more details than the
  3388. 1:58:23budget and here we have very important
  3389. 1:58:25rule to understand we can show a measure
  3390. 1:58:27only at the grain that it was recorded
  3391. 1:58:30at or a higher level so more summarized.
  3392. 1:58:33So that means we can never show the
  3393. 1:58:34measure at a lower level than the grain
  3394. 1:58:37that is recorded at like for example the
  3395. 1:58:39budget was only recorded at the category
  3396. 1:58:42level. So we can show only the numbers
  3397. 1:58:43at this level or we can roll up if we
  3398. 1:58:46remove the categories in order to have
  3399. 1:58:47the total budget. But we never can go
  3400. 1:58:50down that it cannot go to the budget by
  3401. 1:58:52the products because it is not recorded
  3402. 1:58:54at this level. And if you use any tool
  3403. 1:58:56it going to go only and fake the
  3404. 1:58:58numbers. It will not work. So the rule
  3405. 1:59:00is very simple. If you have two fact
  3406. 1:59:01tables, you can compare them only at the
  3407. 1:59:04highest level they share. So that means
  3408. 1:59:06if you want to do really this
  3409. 1:59:07comparison, we have to do it at the
  3410. 1:59:10category level. So yes, we compare the
  3411. 1:59:12sales versus budget but by the category.
  3412. 1:59:15And don't misunderstand me if you want
  3413. 1:59:16to build a visual only for the fact
  3414. 1:59:18sales. Of course, you can go and use the
  3415. 1:59:20products, but we are talking only about
  3416. 1:59:22connecting two facts into one visual.
  3417. 1:59:25Here you have to be careful which one is
  3418. 1:59:27the highest and only that you can use. I
  3419. 1:59:29know this one was an advanced one, but
  3420. 1:59:31once you know those rules, then
  3421. 1:59:32everything going to be simple. Back to
  3422. 1:59:34PowerBI to practice. Again, we are at
  3423. 1:59:36our data model. So far, we have only
  3424. 1:59:38dimensions around one fact. the fact
  3425. 1:59:41sales. Now, what we're going to do,
  3426. 1:59:42we're going to go and grab another fact
  3427. 1:59:43to the data model and we're going to go
  3428. 1:59:45and connect it. So, get a new data CSV
  3429. 1:59:48and this time we're going to go and
  3430. 1:59:49connect the fact budget. So, let's go
  3431. 1:59:52and do this. Okay. So, go and load it.
  3432. 1:59:54All right. So, with this we got our new
  3433. 1:59:56fact inside our model. And the thing is
  3434. 1:59:58I'm going to go and remove the
  3435. 2:00:00relationship that PowerBI automatically
  3436. 2:00:02created between this fact and other
  3437. 2:00:04things. So, let's go and remove it
  3438. 2:00:06because now we are dealing with the
  3439. 2:00:07facts and we have to be careful. So
  3440. 2:00:09first we have to understand our facts
  3441. 2:00:12not only the budget but as well the fact
  3442. 2:00:14sales. Now in order in PowerBI to
  3443. 2:00:16understand the grains and all those
  3444. 2:00:17stuff we're going to go to other tab. So
  3445. 2:00:20we're going to go to that table view and
  3446. 2:00:21let's go to the fact sales. And now of
  3447. 2:00:24course we're going to ask the classical
  3448. 2:00:25question what each row here is
  3449. 2:00:27representing. So we can see that the
  3450. 2:00:29order ID, 101 we can see it twice. So we
  3451. 2:00:33have two rows for the same ID. So a row
  3452. 2:00:35is not representing the whole order. row
  3453. 2:00:37is a line of order. This is a really
  3454. 2:00:40detailed one. Now let's go and check the
  3455. 2:00:42budget. So now look at this. This is
  3456. 2:00:44highly aggregated. So each row is
  3457. 2:00:46representing actually a month. The plant
  3458. 2:00:48budget and the plant quantity for each
  3459. 2:00:50product for one month. The fact sales
  3460. 2:00:52has a lot of details and the fact budget
  3461. 2:00:55is highly aggregated. That means those
  3462. 2:00:57two facts have different grains and of
  3463. 2:01:00course we cannot go and combine them.
  3464. 2:01:01And of course we will not relate them
  3465. 2:01:03directly to each others just because we
  3466. 2:01:05have here a product ID and as well in
  3467. 2:01:07the budget we have a product ID. So we
  3468. 2:01:09will not do this where we're going to
  3469. 2:01:11grab the product ID from the fact budget
  3470. 2:01:13to the fact sales. Look at this. PowerBI
  3471. 2:01:16says many to many relationship and as
  3472. 2:01:18well we are getting here like a warning
  3473. 2:01:20from PowerBI says this is many to many
  3474. 2:01:22both of the product ids are not
  3475. 2:01:24containing unique values and it's like
  3476. 2:01:26[snorts] be careful of this behavior. So
  3477. 2:01:29if I go and save it, we are doing now
  3478. 2:01:31bad practices by connecting the fact
  3479. 2:01:34tables together. So my friends, we will
  3480. 2:01:36not do that. So we're going to remove
  3481. 2:01:37it. Instead, we need a dimension in
  3482. 2:01:39between a bridge, a conform dimension.
  3483. 2:01:42And this is going to be our friend, the
  3484. 2:01:44dimension product. So let's go and grab
  3485. 2:01:46it over here and just put it nicely
  3486. 2:01:48between those two facts. So you can see
  3487. 2:01:50it is already connected to the fact
  3488. 2:01:52sales. So we don't have to deal with
  3489. 2:01:54this side. But we have to go and connect
  3490. 2:01:56it to the fact pageto. Grab the product
  3491. 2:01:58ID and put it on the dimension product.
  3492. 2:02:01Look at this. Looks nice. We have many
  3493. 2:02:02to one relationship. And that's because
  3494. 2:02:04the product ID in the dimension products
  3495. 2:02:06is unique. So, looks good. Let's go and
  3496. 2:02:09save it. And actually, that's it. Look
  3497. 2:02:11at this. We have a nice shared dimension
  3498. 2:02:14between two facts. So, one to many
  3499. 2:02:15relationship, many to one. And this
  3500. 2:02:17dimension is just like shared between
  3501. 2:02:20those two facts. So, this is how we
  3502. 2:02:22connect two facts together. And now we
  3503. 2:02:24can go and use the values of those two
  3504. 2:02:26facts inside our visuals and reports.
  3505. 2:02:28Let's go and try this out. Now, as we
  3506. 2:02:30learned in order to build a visual, we
  3507. 2:02:32always start from the shared dimension
  3508. 2:02:34which is the dimension products. So, it
  3509. 2:02:36is over here. I'm going to go and pick
  3510. 2:02:38the product name and only then you start
  3511. 2:02:40picking the measures from the facts. So
  3512. 2:02:42now let's go and grab let's say the
  3513. 2:02:44total sales from the fact sales. So I'm
  3514. 2:02:46going to go and drop it here. So this is
  3515. 2:02:47the first fact. Now let's go and compare
  3516. 2:02:49it by another measure from another fact,
  3517. 2:02:51the budget. So we're going to go and
  3518. 2:02:53grab the budget sales and drop it on the
  3519. 2:02:55view. Look at this. Everything is
  3520. 2:02:57working. And now I'm able to do sales
  3521. 2:02:59versus budget analyzes. Now of course in
  3522. 2:03:02order to test whether you are missing
  3523. 2:03:03any numbers, what we can do is that you
  3524. 2:03:05can just go and duplicate this view like
  3525. 2:03:08twice. One left, one right. And now we
  3526. 2:03:10can make one view dedicated only for one
  3527. 2:03:13fact. So that means I'm going to go over
  3528. 2:03:14here and remove the budget. This going
  3529. 2:03:16to be only for the sales. And if the
  3530. 2:03:19numbers are exactly the same as the
  3531. 2:03:21combined one over here, then everything
  3532. 2:03:23is healthy. Same thing on the right
  3533. 2:03:25side. This time this going to be
  3534. 2:03:27dedicated only for one fact, the budget.
  3535. 2:03:29So that means I'm going to go and remove
  3536. 2:03:31any value from the other facts. Now look
  3537. 2:03:33at this. The total budget is exactly
  3538. 2:03:36like the combined one. And this means
  3539. 2:03:38everything is working perfectly. So this
  3540. 2:03:40is how I test if I'm combining two facts
  3541. 2:03:43tables together. You make one dedicated
  3542. 2:03:44view for each and see whether the
  3543. 2:03:46numbers are matching. And now of course
  3544. 2:03:48you can go and check other stuff like by
  3545. 2:03:50grabbing other measures to our view and
  3546. 2:03:52see whether everything working fine. And
  3547. 2:03:54now one more thing that we could
  3548. 2:03:56practice that we could actually connect
  3549. 2:03:58multiple dimensions as a shared
  3550. 2:04:00dimension. So it must not be always like
  3551. 2:04:02only one we can go and add more. So that
  3552. 2:04:05means if we go and check the facts and
  3553. 2:04:07see something in common. So here we have
  3554. 2:04:09the month of the budget. So this is a
  3555. 2:04:11date. And now if we go to the fact sales
  3556. 2:04:13we can see as well let's say the order
  3557. 2:04:15date. This is not a month but as well it
  3558. 2:04:18is a date and we could like use a shared
  3559. 2:04:20dimension called the dimension date in
  3560. 2:04:22between. Let me show you how to do it.
  3561. 2:04:24So let's go back to the model view. Now
  3562. 2:04:26of course we need a dimension date. We
  3563. 2:04:27don't have it yet inside our model.
  3564. 2:04:29We're going to go and connect something
  3565. 2:04:30new. So over here you can see we have a
  3566. 2:04:33dimension date. Let's go and load it and
  3567. 2:04:35let's go and hit load. All right. So
  3568. 2:04:36with this we got a new dimension and I'm
  3569. 2:04:39going to put it just in between those
  3570. 2:04:41two facts. Now of course in order to
  3571. 2:04:43make a share dimension we have to go and
  3572. 2:04:45connect both facts to this new
  3573. 2:04:47dimension. So for example let's go and
  3574. 2:04:49grab the order date and connected to the
  3575. 2:04:52date inside the dimension. So as you can
  3576. 2:04:54see they are using the same informations
  3577. 2:04:56and we have many to one relationship. So
  3578. 2:04:58perfect. Let's save it. So this is one
  3579. 2:05:00side. Now let's go and connect the other
  3580. 2:05:01side. So budget month it goes as well to
  3581. 2:05:04the same key to the date. Same story we
  3582. 2:05:07have here money to one relationship
  3583. 2:05:08which is active and this is nice. So now
  3584. 2:05:11with this we have two shared dimensions
  3585. 2:05:13between our two facts and this of course
  3586. 2:05:15open the door for more analytics between
  3587. 2:05:18the two measures inside the different
  3588. 2:05:19facts. Now we can compare things by the
  3589. 2:05:21dates. Let's go and try this out to the
  3590. 2:05:23report view. As usual we start with the
  3591. 2:05:25dimension. So the new one is the
  3592. 2:05:27dimension date. Let's go and drop it in
  3593. 2:05:29the visual. Now here very important to
  3594. 2:05:31understand the level of details the
  3595. 2:05:33grains. You can see the dimension is
  3596. 2:05:35based on the days. So for each day we
  3597. 2:05:37have one row. So we have to keep this in
  3598. 2:05:39our mind. Now let's go and grab the
  3599. 2:05:41measures. It's going to be the again the
  3600. 2:05:43total sales. Now look at this and
  3601. 2:05:44understand we have for few days a total
  3602. 2:05:47sales. So in January we have two sales
  3603. 2:05:49and in February we have two days of
  3604. 2:05:51sales. With this we can understand that
  3605. 2:05:53the level of details of the dates inside
  3606. 2:05:55the fact sales is as well the day and
  3607. 2:05:57you can check as well that in the table
  3608. 2:05:59view you can see the order date always
  3609. 2:06:01include like a day. So far everything is
  3610. 2:06:04matching. Now let's go to the budget. We
  3611. 2:06:06need as well the planned budget for the
  3612. 2:06:08sales and drop it on the same view. Now
  3613. 2:06:10the first thing that we have to check is
  3614. 2:06:12of course the total. So the total budget
  3615. 2:06:14is matching over here and as well for
  3616. 2:06:16the sales. We don't have to worry about
  3617. 2:06:18now wrong numbers. But now if you look
  3618. 2:06:20to the table over here you can see there
  3619. 2:06:22is something weird right? You can see
  3620. 2:06:24that the numbers are not really side by
  3621. 2:06:26side. There is like some shifting. Now
  3622. 2:06:28if you look closer to the budget you can
  3623. 2:06:30see it's always at the first day of the
  3624. 2:06:32month. So the 1st of January, the 1st of
  3625. 2:06:35February and so on. So we see a budget
  3626. 2:06:38only on the first day and for the total
  3627. 2:06:40sales we see it in different days.
  3628. 2:06:42Sometimes the 5th, sometimes 12th, third
  3629. 2:06:44and so on. So we are not really able to
  3630. 2:06:47compare the two measures side by side.
  3631. 2:06:49And this is my friends because we have
  3632. 2:06:52different level of details and grain for
  3633. 2:06:54the budget. So we can go and check this
  3634. 2:06:56over here. Let's switch to the fact
  3635. 2:06:58budget. We see it like the 1st of
  3636. 2:06:59January. This is only the format but the
  3637. 2:07:01level here is a month and not a day. And
  3638. 2:07:04what we have learned before if you have
  3639. 2:07:06different level of details, if you have
  3640. 2:07:08different grains, you have always to
  3641. 2:07:10work on the highest level. Otherwise,
  3642. 2:07:12your chart kind of looks exactly weird
  3643. 2:07:14like this. So in order to compare now
  3644. 2:07:16the budget and the total sales, we have
  3645. 2:07:18to bring them together at the same level
  3646. 2:07:20where both of them can understand the
  3647. 2:07:22level. And this is my friend not the
  3648. 2:07:24day. This is the month. That's why I'm
  3649. 2:07:26going to go to the date over here and
  3650. 2:07:28just get rid of the day. And with this,
  3651. 2:07:30we have like a roll up to the month. And
  3652. 2:07:32look at this. Now we see things side by
  3653. 2:07:35side. So the budget is near the total
  3654. 2:07:37sales. That's because both of the fact
  3655. 2:07:39tables can work at that same level at
  3656. 2:07:41the month. And now things are more
  3657. 2:07:43healthy and we can go and compare the
  3658. 2:07:45two measures side by side. As you can
  3659. 2:07:47see my friends, not only you have to
  3660. 2:07:49build a healthy data model, you have as
  3661. 2:07:51well to understand the grain of
  3662. 2:07:53everything. the grain of the dimensions,
  3663. 2:07:55the grain of the facts. Without that,
  3664. 2:07:57you're going to build weird reports and
  3665. 2:08:00in the worst case you will be reporting
  3666. 2:08:02wrong numbers. So now let's recap. So if
  3667. 2:08:04two fact tables have the same grain, the
  3668. 2:08:07same fact, the same structure, the same
  3669. 2:08:08event, then go and just append those two
  3670. 2:08:11facts together. But if you have a
  3671. 2:08:12scenario where the two facts yes have
  3672. 2:08:14the same grain but they have different
  3673. 2:08:15shapes and you can build a onetoone
  3674. 2:08:18relationship between those two facts
  3675. 2:08:19then just go and combine them into one
  3676. 2:08:21fact by merging them together. But now
  3677. 2:08:24in the other scenario if they have
  3678. 2:08:25different grains different shapes
  3679. 2:08:27different events. Never combine those
  3680. 2:08:29two facts and as well never relate them
  3681. 2:08:32directly to each others. Always build in
  3682. 2:08:34between a shared or bridge dimension and
  3683. 2:08:37connect your facts to it. And at the
  3684. 2:08:39visual level if you are comparing two
  3685. 2:08:41facts only work at the level that both
  3686. 2:08:44facts understand. So always pick the
  3687. 2:08:46highest level that both facts can
  3688. 2:08:48understand. So my friends once you
  3689. 2:08:50understand those rules then it's going
  3690. 2:08:51to be really easy to work with facts in
  3691. 2:08:53[music] data modeling.
  3692. 2:08:58All right friends now we're going to
  3693. 2:08:59talk about something really important
  3694. 2:09:00for data modeling and as well for real
  3695. 2:09:02projects. The security. The thing is in
  3696. 2:09:05real projects it is not enough to have a
  3697. 2:09:07model that gives correct numbers but
  3698. 2:09:09also you have to control who is allowed
  3699. 2:09:11to see which data. So that means you
  3700. 2:09:12have to make it secure and this is
  3701. 2:09:14deeply connected into data moduling. If
  3702. 2:09:17you have clean data model then it's
  3703. 2:09:18going to be really easy to implement the
  3704. 2:09:20security requirement and it's going to
  3705. 2:09:21be safe. But if you have a data model
  3706. 2:09:23that is messy chaotic the security going
  3707. 2:09:26to be really hard to implement and your
  3708. 2:09:28data going to leak to the wrong users.
  3709. 2:09:30And this is exactly what we're going to
  3710. 2:09:32do now. And we start as usual with the
  3711. 2:09:33foundations. So what is security in data
  3712. 2:09:36moduling? Let's go. Okay. So we have a
  3713. 2:09:38table and by default this table has no
  3714. 2:09:41security. So that means if we are
  3715. 2:09:42building a report on top of it, everyone
  3716. 2:09:45all the users going to be able to see
  3717. 2:09:46all the data of this table. But now
  3718. 2:09:48let's say that we are a real project and
  3719. 2:09:50we have to go and apply security on top
  3720. 2:09:52of this table. Here we're going to have
  3721. 2:09:53like three options. The first scenario
  3722. 2:09:55if the whole table is actually contains
  3723. 2:09:58a lot of sensitive informations like the
  3724. 2:10:00salaries, the contacts, the finance data
  3725. 2:10:03and some users are actually not allowed
  3726. 2:10:05to access this table at all. So that
  3727. 2:10:07means what we have to do in this
  3728. 2:10:08scenario we have to go and hide the
  3729. 2:10:10whole table everything all the rows and
  3730. 2:10:12all the columns and for them this table
  3731. 2:10:14is basically doesn't exist. This is what
  3732. 2:10:16we call the table level security. Now
  3733. 2:10:19the second scenario maybe not that
  3734. 2:10:21extreme where you say you know what we
  3735. 2:10:23have a table like employees and it
  3736. 2:10:25contains a lot of data that are actually
  3737. 2:10:27not sensitive but we have like one two
  3738. 2:10:29columns that are really sensitive like
  3739. 2:10:31for example the salary. So we will not
  3740. 2:10:33go and hide the whole table for the
  3741. 2:10:35users. What we can do we can go and
  3742. 2:10:37protect and hide only one specific
  3743. 2:10:39column. So that means the user is going
  3744. 2:10:41to be able to see all the data but only
  3745. 2:10:43this column going to be hidden for them.
  3746. 2:10:45This is what we call the column level
  3747. 2:10:48security. Now to the third scenario
  3748. 2:10:50which is the most common one in many
  3749. 2:10:52projects where we can say actually the
  3750. 2:10:54table is totally okay. All the columns
  3751. 2:10:56are not sensitive but now it is not
  3752. 2:10:58allowed to show all the rows for all the
  3753. 2:11:00users. Like for example a salesperson
  3754. 2:11:02can only see the region or maybe the
  3755. 2:11:05managers are allowed only to see their
  3756. 2:11:06own departments. So that means the whole
  3757. 2:11:09table can be visible. All the columns
  3758. 2:11:10are allowed but the users will not see
  3759. 2:11:13all the rows. They are allowed to see
  3760. 2:11:14only specific rows. And this is what we
  3761. 2:11:17call the very famous rowle security and
  3762. 2:11:20you're going to hear a lot of people are
  3763. 2:11:22saying RLS. So those are the three
  3764. 2:11:24levels of security or hiding things in
  3765. 2:11:27data modeling. The table level security
  3766. 2:11:29you want to hide the whole table. The
  3767. 2:11:31column level security you want to hide
  3768. 2:11:32only specific sensitive columns. And the
  3769. 2:11:35third one is the role level security if
  3770. 2:11:37you want to go and hide specific rows.
  3771. 2:11:39Now of course the most common technique
  3772. 2:11:40that is used almost in every project is
  3773. 2:11:42the role level security. And this is
  3774. 2:11:44exactly what we're going to deep dive
  3775. 2:11:46now. So we have to understand why and
  3776. 2:11:48what. Let's go. Okay. So now we have
  3777. 2:11:49this following setup where we have a
  3778. 2:11:51table about the sales and a report in
  3779. 2:11:53top of it. Now this sales table going to
  3780. 2:11:55contain all the sales. So for all
  3781. 2:11:57departments or regions. Now the thing is
  3782. 2:12:00in companies we have different people
  3783. 2:12:01with different roles. Like for example,
  3784. 2:12:03we might have like a director that is
  3785. 2:12:05actually allowed to see all the data and
  3786. 2:12:08we might have another person like for
  3787. 2:12:09example a manager that is allowed only
  3788. 2:12:12to see the sales for specific
  3789. 2:12:14department. So this means not all the
  3790. 2:12:16rows only specific one and we might have
  3791. 2:12:18a third one. So we have a salesperson
  3792. 2:12:20that is allowed only to see the data
  3793. 2:12:22based on the region that is assigned to
  3794. 2:12:24it like maybe only Europe. So that means
  3795. 2:12:26we have three different users with three
  3796. 2:12:28different security requirements. Now, of
  3797. 2:12:30course, because of this, you cannot go
  3798. 2:12:32and just share the report with everyone.
  3799. 2:12:34You have to be careful with the security
  3800. 2:12:36requirements. Now, one of the ideas is
  3801. 2:12:38to go and do this where you're going to
  3802. 2:12:39say, "Okay, I'm going to go and
  3803. 2:12:40duplicate my report into three files.
  3804. 2:12:42I'm going to build a filter specifically
  3805. 2:12:45tailored for each role and then start
  3806. 2:12:47sharing those reports based on the
  3807. 2:12:49role." So, you are making like
  3808. 2:12:51role-based reports. But of course I
  3809. 2:12:53think it's obvious this is really bad
  3810. 2:12:55solution because you have the same
  3811. 2:12:56report the same work over and over and
  3812. 2:12:59all those duplicates is just because of
  3813. 2:13:01one simple filter and of course if you
  3814. 2:13:03want to change one thing it going to be
  3815. 2:13:05really nightmare you have to go through
  3816. 2:13:06all the files and start implementing the
  3817. 2:13:08same change again and again. So this
  3818. 2:13:10going to be really nightmare to maintain
  3819. 2:13:12and it will not work. Now we have
  3820. 2:13:13smarter and better solution that instead
  3821. 2:13:16of having all those duplicates we're
  3822. 2:13:18going to go back to one model and one
  3823. 2:13:19reports. But now what we're going to do,
  3824. 2:13:21we're going to go and add a rowle
  3825. 2:13:23security component on top of the data
  3826. 2:13:25model. And it is smart enough to let
  3827. 2:13:27PowerBI understand who is looking at the
  3828. 2:13:30reports and based on the information
  3829. 2:13:32based on the role PowerBI going to go
  3830. 2:13:34and filter the data model specially for
  3831. 2:13:37that person and this is exactly the best
  3832. 2:13:39solution is to implement the relevant
  3833. 2:13:41security so that you stick with the one
  3834. 2:13:43project without having you to duplicate
  3835. 2:13:45things. Now of course the question is
  3836. 2:13:46how we going to go and build this smart
  3837. 2:13:48component in the data model? how this
  3838. 2:13:50works and how to build it. Now, of
  3839. 2:13:52course, implementing role security
  3840. 2:13:53depend on the tech stack that you are
  3841. 2:13:55using. One solution that you might find
  3842. 2:13:58rarely in projects where they build a
  3843. 2:14:00live connection between PowerBI and
  3844. 2:14:03underneath like database or maybe like
  3845. 2:14:05data bricks and they decide to build the
  3846. 2:14:07whole role security in the back end. So
  3847. 2:14:10they build the whole filtering logic in
  3848. 2:14:12the database and PowerBI has only to go
  3849. 2:14:14and pass the user information to the
  3850. 2:14:17back end and of course the backend
  3851. 2:14:18system going to return only the rows the
  3852. 2:14:21user is allowed to see. So that means
  3853. 2:14:23the whole logic going to be built
  3854. 2:14:24outside of PowerBI and to be honest this
  3855. 2:14:27is something really complicated to do
  3856. 2:14:29because now you have two systems the
  3857. 2:14:31testing going to be really hard and we
  3858. 2:14:33rarely use the live connection between
  3859. 2:14:35PowerBI and the backend system. Most of
  3860. 2:14:37the times we import the data to PowerBI.
  3861. 2:14:39So that's why the second option is to go
  3862. 2:14:42and build the role of it security inside
  3863. 2:14:44PowerBI and this is the most common
  3864. 2:14:46option that we actually build and
  3865. 2:14:47implements in real projects and this is
  3866. 2:14:49exactly what we're going to learn. So
  3867. 2:14:50now how we're going to build this RLS
  3868. 2:14:52inside PowerBI and how it works. So now
  3869. 2:14:54we have again this setup where we have a
  3870. 2:14:55table in the model and this table has a
  3871. 2:14:58column called region where you have the
  3872. 2:14:59values US and EU. After that we have a
  3873. 2:15:02report and then three users are using
  3874. 2:15:04this report and accessing it. Now if you
  3875. 2:15:06leave it like this then we don't have
  3876. 2:15:07security that means everyone is seeing
  3877. 2:15:09everything. But now if we cannot leave
  3878. 2:15:11it like this and we have to go and
  3879. 2:15:12implement the role level security then
  3880. 2:15:14of course we cannot go and build some
  3881. 2:15:16random filters inside PowerBI. We need
  3882. 2:15:18more tools. So the first component or
  3883. 2:15:21tool that we're going to use for role
  3884. 2:15:22level security is the role and it is a
  3885. 2:15:24tool that we're going to use in order to
  3886. 2:15:26filter the model. So it's very simple.
  3887. 2:15:28It has a name and a value. Now the value
  3888. 2:15:31could be either static or a ducks
  3889. 2:15:33calculation if you have expression. Now
  3890. 2:15:35if you decide for the static values then
  3891. 2:15:37you're going to have like two roles
  3892. 2:15:38based on the regions one for EU and
  3893. 2:15:41another one for US. So this is the rule
  3894. 2:15:43and with this PowerBI knows how to
  3895. 2:15:45filter the data model based on the role.
  3896. 2:15:48But that's not enough of course because
  3897. 2:15:49PowerBI is missing another important
  3898. 2:15:52information the mapping between the
  3899. 2:15:54users and the role. PowerBI doesn't know
  3900. 2:15:56whether Maria has the role like us or U.
  3901. 2:15:59So we don't have yet this mapping. And
  3902. 2:16:01for this you have two options. either
  3903. 2:16:03you're going to leave it like this
  3904. 2:16:04static where you go and publish the
  3905. 2:16:06report to PowerBI service and from there
  3906. 2:16:09you start manually mapping which user
  3907. 2:16:12belong to which role and now this
  3908. 2:16:14PowerBI has everything the two
  3909. 2:16:15informations the mapping between the
  3910. 2:16:17user and the role and the mapping
  3911. 2:16:19between the role and the data model. So
  3912. 2:16:22everything is linked. Now if a user like
  3913. 2:16:24Maria go and access the reports, what
  3914. 2:16:26going to happen? PowerBI first has to go
  3915. 2:16:27and check the role and say ahuh she
  3916. 2:16:29belongs to the role EU and then go to
  3917. 2:16:31the other mapping. Okay, the role EU has
  3918. 2:16:34the static value EU and after that it's
  3919. 2:16:37going to go to the data model and filter
  3920. 2:16:38the data based on this static value. So
  3921. 2:16:41this Maria going to see only EU data and
  3922. 2:16:44this is my friends what we call the
  3923. 2:16:46static role security in PowerBI. Now by
  3924. 2:16:49looking into this the role of security
  3925. 2:16:51has actually two problems. The first
  3926. 2:16:53issue we are creating like a role for
  3927. 2:16:55each value inside our data. So here we
  3928. 2:16:57have like two values in the region we
  3929. 2:16:59have create two roles. But if the
  3930. 2:17:01security concept is based like on
  3931. 2:17:02another column on another values where
  3932. 2:17:04you have 10 and 30 you have to go and
  3933. 2:17:06create like 30 rules and if you keep
  3934. 2:17:08like getting new values you have to go
  3935. 2:17:10and keep expanding and maybe you're
  3936. 2:17:12going to go and miss something. And the
  3937. 2:17:13second issue, each time we get a new
  3938. 2:17:15user, we have always to go to the
  3939. 2:17:16PowerBI service. We have to assign those
  3940. 2:17:19new users to the different roles. To be
  3941. 2:17:21honest, I have never done this in
  3942. 2:17:22projects because I had like 3,000 users
  3943. 2:17:24and I don't have the time to go and
  3944. 2:17:26assign manually each user to each role.
  3945. 2:17:28That's why we have another option where
  3946. 2:17:30things are more dynamic and we call it
  3947. 2:17:33dynamic role level security where we're
  3948. 2:17:35going to say we will not do those manual
  3949. 2:17:36things but instead we're going to add a
  3950. 2:17:38new table to the data model. This is a
  3951. 2:17:41special table only for security where it
  3952. 2:17:43has two informations which user is
  3953. 2:17:45allowed to see which region. So we're
  3954. 2:17:47going to see like information for each
  3955. 2:17:49user like Maria going to see you and so
  3956. 2:17:51on. Now of course the big question is
  3957. 2:17:53where this data come from. Now if you
  3958. 2:17:55are unlucky you have to go and create it
  3959. 2:17:57manually. So you can have your own Excel
  3960. 2:17:59where you are mapping the users to the
  3961. 2:18:01regions. Again it is kind of manual
  3962. 2:18:03work. Or if you are lucky enough and
  3963. 2:18:05this is something that really happens a
  3964. 2:18:07lot in projects where you're going to
  3965. 2:18:08find this kind of information stored
  3966. 2:18:10somewhere in your source systems and
  3967. 2:18:12this is actually what I usually do. I go
  3968. 2:18:14and load the security informations like
  3969. 2:18:16any other tables inside my model. So
  3970. 2:18:18with that I don't have to map anything
  3971. 2:18:19manually and everything going to be
  3972. 2:18:20automatic. Now so far we have just like
  3973. 2:18:22table and data and PowerBI has no idea
  3974. 2:18:25how to do the role of a security. So now
  3975. 2:18:28what do we want? We want just to connect
  3976. 2:18:30the users to this security table and we
  3977. 2:18:32can do that by doing two steps. First
  3978. 2:18:34PowerBI has to know who are the users
  3979. 2:18:37that are looking at the reports and for
  3980. 2:18:39that we have a nice function called user
  3981. 2:18:41principle name. It's going to return the
  3982. 2:18:43current user that is opening the
  3983. 2:18:45reports. So usually going to get the
  3984. 2:18:46email address. So with this PowerBI
  3985. 2:18:48knows okay who is looking at the report.
  3986. 2:18:50Now in order to map this value that is
  3987. 2:18:53returned from this function to the
  3988. 2:18:55security table we have to go and create
  3989. 2:18:57a role. But now of course we will not go
  3990. 2:18:58and create a role for each value inside
  3991. 2:19:01the table. We're going to make things
  3992. 2:19:02more dynamic by creating only one role
  3993. 2:19:04and we're going to use some DAX
  3994. 2:19:06calculation in order to just map the
  3995. 2:19:08value from this function to the security
  3996. 2:19:11table. So those are the component and
  3997. 2:19:12now let's understand what going to
  3998. 2:19:14happen if Maria go and open the reports.
  3999. 2:19:16Barbie going to go and execute the
  4000. 2:19:17function and understand okay who is that
  4001. 2:19:19it's going to get the value. Okay Maria
  4002. 2:19:21then Barbie going to go to the role in
  4003. 2:19:22order to understand how to filter and
  4004. 2:19:24where to go with this information. Then
  4005. 2:19:26it's going to say okay we have to go and
  4006. 2:19:28filter the security table and this is
  4007. 2:19:30very important to understand it is
  4008. 2:19:32filtering the security table and not
  4009. 2:19:33going directly to the whole data model
  4010. 2:19:35and filtering the tables. So that means
  4011. 2:19:37only the security table going to get
  4012. 2:19:39filtered to Maria and now what's going
  4013. 2:19:41to happen this filter going to travel to
  4014. 2:19:44our data model. So it is very important
  4015. 2:19:46to have a correct relationship between
  4016. 2:19:48the security table and your data model.
  4017. 2:19:51So this is how it works. This is the
  4018. 2:19:53dynamic role level security. And now
  4019. 2:19:54let's go and compare the static with the
  4020. 2:19:56dynamic side by side. In the static RLS,
  4021. 2:19:59we have to go and create multiple roles
  4022. 2:20:01based on the values inside our tables.
  4023. 2:20:03But for the dynamic RLS, we have usually
  4024. 2:20:05to go and create only one role with a
  4025. 2:20:08DAX calculation. Now for the static, the
  4026. 2:20:10users are assigned to the roles inside
  4027. 2:20:12the PowerBI service. But for the
  4028. 2:20:14dynamic, the users are mapped inside a
  4029. 2:20:17security table inside the model in
  4030. 2:20:19PowerBI desktop. Now for the static if
  4031. 2:20:21the access change we have to go and
  4032. 2:20:23change the assignment in the PowerBI
  4033. 2:20:25service. But with the dynamic if access
  4034. 2:20:27change we just change the data inside
  4035. 2:20:29the security table. And here the
  4036. 2:20:30recommendation is if you have like small
  4037. 2:20:32projects, small data and only few users
  4038. 2:20:34and then go and use the static because
  4039. 2:20:36it is more straightforward and it is
  4040. 2:20:38easier to implement. But if you have
  4041. 2:20:40like more data, you have a lot of users,
  4042. 2:20:42you have bigger projects, then the best
  4043. 2:20:43practices says go and use the dynamic
  4044. 2:20:45role of the security. It is yeah at the
  4045. 2:20:47start not that easy to build but you are
  4046. 2:20:49investing for the future so things going
  4047. 2:20:51to be way faster and dynamic once you
  4048. 2:20:53get a lot of users using your reports
  4049. 2:20:56and now based on this we will be
  4050. 2:20:57focusing on the dynamic role the
  4051. 2:20:59security because it is the method that
  4052. 2:21:00we usually implement in real projects at
  4053. 2:21:03companies. So now since this is
  4054. 2:21:04confusing topic and you have to pay
  4055. 2:21:06attention to the filters and directions
  4056. 2:21:08we're gonna have this very simple
  4057. 2:21:09example where we have a fact table fact
  4058. 2:21:11sales and two dimensions and now we have
  4059. 2:21:13to pay attention to the numbers. So here
  4060. 2:21:14we have the total sales of 10K. We have
  4061. 2:21:16five customers and five products. So a
  4062. 2:21:19very classical star schema. Now of
  4063. 2:21:21course anyone that is using this data
  4064. 2:21:22model going to see exactly those
  4065. 2:21:24numbers. Nothing is filtered unless they
  4066. 2:21:26go and make a filter slicer or something
  4067. 2:21:29to interact with the report. But if they
  4068. 2:21:31don't filter anything, they're going to
  4069. 2:21:33see the whole thing. Now of course we
  4070. 2:21:34want to make this secure by implementing
  4071. 2:21:36the dynamic RLS. And we start with the
  4072. 2:21:39first step where we're going to go and
  4073. 2:21:40add a security table. Now this table is
  4074. 2:21:42just mapping between the email address
  4075. 2:21:44of the users and the region and we have
  4076. 2:21:46a relationship between this security
  4077. 2:21:48table to the fact sales since we have as
  4078. 2:21:50well here the region. But now look at
  4079. 2:21:52this even if we have the security table
  4080. 2:21:54everyone is able to see the 10k. So
  4081. 2:21:56adding a security table and build the
  4082. 2:21:58relationship doesn't mean the data going
  4083. 2:22:00to get filtered automatically. For that
  4084. 2:22:02we have to go and add more steps like
  4085. 2:22:03for example a rule where it going to
  4086. 2:22:05check the user principle name. Now let's
  4087. 2:22:07say that after adding the role we have a
  4088. 2:22:09user called Alice and she going to go
  4089. 2:22:11and now open the report and start
  4090. 2:22:13looking at the data. Now suddenly she
  4091. 2:22:16will not see the whole 10k as a default.
  4092. 2:22:18She going to see only 4k even without
  4093. 2:22:21filtering any data in the report and
  4094. 2:22:23that's all because of the security role
  4095. 2:22:25and as well the security table that is
  4096. 2:22:27connected to our fact. But now we have
  4097. 2:22:29to pay attention to this. You can see
  4098. 2:22:31that she is able to see the five
  4099. 2:22:33customers and the five products and
  4100. 2:22:35that's all because of the filter
  4101. 2:22:36direction. We are not filtering from the
  4102. 2:22:39fact to the dimension. It is the
  4103. 2:22:40opposite from dimension to fact. So that
  4104. 2:22:43means it's going to stop over here and
  4105. 2:22:44will not carry out to the other
  4106. 2:22:46dimensions. But now if you say you know
  4107. 2:22:48what I would like as well to filter the
  4108. 2:22:50dimension customers based on the
  4109. 2:22:52security then what you have to do is to
  4110. 2:22:54just go and change the filter direction
  4111. 2:22:56to both. Now look at this. The security
  4112. 2:22:58table is filtering the fact and the fact
  4113. 2:23:00is actually carrying the filter to the
  4114. 2:23:02dimension customer. But with that Alice
  4115. 2:23:04going to see 4K and as well only two
  4116. 2:23:07customers not anymore the five but the
  4117. 2:23:09dimension product is not affected
  4118. 2:23:10because here we have one direction but
  4119. 2:23:12if you say let's go and filter the whole
  4120. 2:23:14data model then as well you have to go
  4121. 2:23:16and add like both and with this actually
  4122. 2:23:18you are filtering the whole data model.
  4123. 2:23:20So that means my friend you have to pay
  4124. 2:23:22attention to the filter direction in the
  4125. 2:23:24relationships because it's going to
  4126. 2:23:26define the behavior of the security of
  4127. 2:23:28the whole data model. If you do it wrong
  4128. 2:23:30then the whole security will not work
  4129. 2:23:32even if you have the best setup like you
  4130. 2:23:34have the roles you have the table but
  4131. 2:23:36the relationship is wrong. Like for
  4132. 2:23:38example if you just switch it like this
  4133. 2:23:40where you say the filter direction is
  4134. 2:23:42from the fact to the security. Now what
  4135. 2:23:44going to happen? The user going to see
  4136. 2:23:45the 10k because the data is not
  4137. 2:23:47traveling from the security table to the
  4138. 2:23:49fact. So whoever like go and look to the
  4139. 2:23:52table all of them going to see the 10k.
  4140. 2:23:54So that means the filter is not
  4141. 2:23:56traveling the whole setup going to be
  4142. 2:23:58wrong and you're going to have like
  4143. 2:23:59security leak that's why the definition
  4144. 2:24:01of the direction going to be very
  4145. 2:24:03critical topic. And now for example if
  4146. 2:24:05you go and switch to pop has different
  4147. 2:24:07scenario where he is mapped to South
  4148. 2:24:08America and for that we have like two
  4149. 2:24:10orders that means pop can see only 3k
  4150. 2:24:13two customers and two products. Now if
  4151. 2:24:15you go to Carla, she has the region
  4152. 2:24:18east. She can see only three orders and
  4153. 2:24:20she can see three customers, three
  4154. 2:24:22products. Now of course something that
  4155. 2:24:23might happen a lot where you have a user
  4156. 2:24:25that is not actually inside your
  4157. 2:24:27security table. What going to happen?
  4158. 2:24:29This user will not see anything. They
  4159. 2:24:31will see total sales of zero, no
  4160. 2:24:33customers, no product. Since Dan has no
  4161. 2:24:35record inside our security table, he
  4162. 2:24:37will be completely blind and will not
  4163. 2:24:38see anything. So this is exactly how the
  4164. 2:24:40dynamic role level security works. And
  4165. 2:24:42as you can see it is something that is
  4166. 2:24:44completely depending on the data model
  4167. 2:24:47and how things are connected. That's why
  4168. 2:24:49building the relevant security it is
  4169. 2:24:51part of data moduling. If you do it
  4170. 2:24:53wrong then you will not be able to
  4171. 2:24:54connect things nicely like now we are
  4172. 2:24:56doing. So now back to our data model. Of
  4173. 2:24:58course here we have only star schema. So
  4174. 2:25:00we have dimensions facts connected to
  4175. 2:25:02each others but we don't have security.
  4176. 2:25:03Trust means everyone going to see
  4177. 2:25:05everything. Now how we going to do it?
  4178. 2:25:07Of course we have to do it step by step
  4179. 2:25:08and we don't have to rush it. Now I'm
  4180. 2:25:10going to show you how to do the static.
  4181. 2:25:11It's very simple. So now the first step
  4182. 2:25:13we have to understand the security
  4183. 2:25:15requirement in our project. So we cannot
  4184. 2:25:17go and apply like some random filters on
  4185. 2:25:19top of our data based on our like gut
  4186. 2:25:21feeling. If you don't know about that
  4187. 2:25:23you have to ask your team your
  4188. 2:25:24department and usually there is like a
  4189. 2:25:26security officer that understand those
  4190. 2:25:28topics. Now let's say after some
  4191. 2:25:30discussions I understood we have always
  4192. 2:25:32to secure our data based on the regions.
  4193. 2:25:34So this is very important step because
  4194. 2:25:36now I know my goal. I want to secure
  4195. 2:25:38this data model based on the region and
  4196. 2:25:40not based on the city or the country or
  4197. 2:25:43some specific departments and so on. Now
  4198. 2:25:45the next step is that we have to
  4199. 2:25:47understand where are the regions inside
  4200. 2:25:49our data model. So that means I start
  4201. 2:25:51going to the table view and start
  4202. 2:25:53investigating all my dimensions and
  4203. 2:25:54facts to understand where I can find the
  4204. 2:25:56region informations. Now for example
  4205. 2:25:58here we can see it in the dimension
  4206. 2:25:59store. This is very good and in other
  4207. 2:26:01tables like the facts the fact sales we
  4208. 2:26:04don't see this information. So that I
  4209. 2:26:06located the dimension store. This going
  4210. 2:26:08to be a very good starting point. So now
  4211. 2:26:09that means based on the stores I will be
  4212. 2:26:12able to use it in order to secure the
  4213. 2:26:14fact table in the middle. So this I know
  4214. 2:26:16exactly my target tables and this is
  4215. 2:26:18very important in order to build the
  4216. 2:26:20relevant security. Now the third step
  4217. 2:26:22before I start doing anything I'm going
  4218. 2:26:24to go to the report view and then make
  4219. 2:26:26like a special view only for testing.
  4220. 2:26:28You have always to understand the big
  4221. 2:26:30numbers of your data model and
  4222. 2:26:32understand the behavior of the role
  4223. 2:26:33level security on top of it. Otherwise
  4224. 2:26:35you don't know whether you have done
  4225. 2:26:36things correctly or not and you might
  4226. 2:26:38have some security leaks or maybe are
  4227. 2:26:40filtering unnecessary things. So I have
  4228. 2:26:42to memorize it in my head. The total
  4229. 2:26:44sales in the whole data set is 5500 five
  4230. 2:26:47customers six products. So that means I
  4231. 2:26:49know the numbers. I know which table is
  4232. 2:26:51going to be affected and filtered and I
  4233. 2:26:53know how to build the roles. Now since
  4234. 2:26:54we are building the static one you have
  4235. 2:26:56always to understand the values. So as
  4236. 2:26:58you can see here the regions we have
  4237. 2:26:59two. That means we need two roles and
  4238. 2:27:02those are the values that we're going to
  4239. 2:27:03use in order to filter the data model.
  4240. 2:27:05So Europe and USA you have exactly to
  4241. 2:27:07use those values as it is. So now how we
  4242. 2:27:10going to build it? We're going to go
  4243. 2:27:10back to the model view. Now in order to
  4244. 2:27:12create the roles we're going to go to
  4245. 2:27:14the rep points over here and we have
  4246. 2:27:15manage roles. It is very simple. We're
  4247. 2:27:17going to go from left to right. So we're
  4248. 2:27:18going to start by creating the roles.
  4249. 2:27:20Now the first one we're going to go and
  4250. 2:27:22create the role for EU. And another one
  4251. 2:27:25we're going to go and create the role of
  4252. 2:27:27US. So now the next step we have to tell
  4253. 2:27:29PowerBI which table must be filtered and
  4254. 2:27:32as we checked the dimension store should
  4255. 2:27:34be filtered because only here we have
  4256. 2:27:35the region informations of course if you
  4257. 2:27:37have multiple tables then go and select
  4258. 2:27:39multiple tables but now we have only one
  4259. 2:27:40and now the next step we have to go and
  4260. 2:27:42create the filter condition and here we
  4261. 2:27:44have two options either we're going to
  4262. 2:27:45go and click around if we are creating
  4263. 2:27:47the static one or we're going to switch
  4264. 2:27:48to DAX in order to create the dynamic
  4265. 2:27:51RLS but now we are creating only the
  4266. 2:27:53static so I'm going to go and say new
  4267. 2:27:54rule it's just a very simple filter
  4268. 2:27:56condition so we're going to go and
  4269. 2:27:57select the column. It's going to be the
  4270. 2:27:59region. And now the value, we're going
  4271. 2:28:00to write it exactly like the value
  4272. 2:28:02inside our data set. So since this is
  4273. 2:28:04Europe, we're going to write it like
  4274. 2:28:05this. And it is case sensitive. Now if
  4275. 2:28:07you just go and read it from left to
  4276. 2:28:08right, we are creating a new role in
  4277. 2:28:11order to filter the dimension store. And
  4278. 2:28:13this is the filter condition. Region
  4279. 2:28:15must be equal to Europe. So that's it.
  4280. 2:28:17We have to go and do it again for the
  4281. 2:28:19US. Yes, we are filtering the dimension
  4282. 2:28:21store. And then we can go and create the
  4283. 2:28:23condition. Same thing to the region. And
  4284. 2:28:25now the value going to be USA. So
  4285. 2:28:27actually it is very easy. That's it.
  4286. 2:28:29With that we have created the two roles
  4287. 2:28:31and now we can go and save it. So that's
  4288. 2:28:33it and then go and close it. Now of
  4289. 2:28:35course you might ask okay what happened
  4290. 2:28:36now. Go to the report view and check.
  4291. 2:28:39You can see nothing changed. So yes we
  4292. 2:28:41have created the roles but PowerBI is
  4293. 2:28:43not filtering anything yet because in
  4294. 2:28:45order to do that we have to go and
  4295. 2:28:46publish the report to the PowerBI
  4296. 2:28:48service and then start assigning the
  4297. 2:28:50different people to the different roles
  4298. 2:28:51and then it going to work. But now of
  4299. 2:28:53course the question is how we going to
  4300. 2:28:54test it? Are we going to go and create
  4301. 2:28:56like a dummy user or go and ask someone
  4302. 2:28:58to test for us? Well, of course, no. We
  4303. 2:29:00have something smarter in PowerBI. All
  4304. 2:29:02what you have to do to test is just to
  4305. 2:29:04go back to the model view and then we
  4306. 2:29:05have in the report as well something
  4307. 2:29:07side by side called view as. So, it is
  4308. 2:29:09very cool. We can go and view the report
  4309. 2:29:12as a specific role. Like for example, I
  4310. 2:29:14would like to view the report as the
  4311. 2:29:15role you. And this is of course very
  4312. 2:29:17cool because now I can test the report
  4313. 2:29:19as a person that has this specific role.
  4314. 2:29:22So now let's go and do that and say
  4315. 2:29:23okay. Now you're going to see this nice
  4316. 2:29:25warning. It says now viewing as the role
  4317. 2:29:28AU. So very cool. But now of course in
  4318. 2:29:30order to know whether this works. We
  4319. 2:29:32have always to test by going back to the
  4320. 2:29:34report view. And look at this. So you
  4321. 2:29:36can see in the fact we are seeing only
  4322. 2:29:38the orders with the region Europe not
  4323. 2:29:40from USA. You can see as well the total
  4324. 2:29:43sale did change. So that means my friend
  4325. 2:29:45this role is working. Now let's go and
  4326. 2:29:47test the opposite. So I'm going to say
  4327. 2:29:48again okay views and then we're going to
  4328. 2:29:50go and switch to US and then hit okay.
  4329. 2:29:53Now it says viewing as RO US. Let's go
  4330. 2:29:56and test. Look at this. Now we are
  4331. 2:29:58seeing the orders only from the region
  4332. 2:30:00USA. So as you can see it is working.
  4333. 2:30:02And now as you might noticed the total
  4334. 2:30:04products and the total customers they
  4335. 2:30:05are not changing and that's all because
  4336. 2:30:07of the star schema relationships that we
  4337. 2:30:09have created. You can see the filter
  4338. 2:30:11directions are always from the
  4339. 2:30:13dimensions to the facts. So that means
  4340. 2:30:14the filters will not reach the
  4341. 2:30:16dimensions. Now, of course, if you want
  4342. 2:30:17to test, we can go and try this out by
  4343. 2:30:20going, for example, to the relationship
  4344. 2:30:22between the fact sales and the
  4345. 2:30:23dimension. Now, of course, we're going
  4346. 2:30:24to go to the direction instead of
  4347. 2:30:26single, we're going to go and switch it
  4348. 2:30:27to both. Now, here we have another
  4349. 2:30:29option. It says apply security filter in
  4350. 2:30:31both directions. Well, yes, this is
  4351. 2:30:33exactly what we want. So, that's it.
  4352. 2:30:35Let's go and save. Now, we can see the
  4353. 2:30:37filter is in both directions. So, the
  4354. 2:30:39filtering should reach now the products.
  4355. 2:30:41Let's go and test. Look at this. We
  4356. 2:30:42moved from six products to five
  4357. 2:30:44products. So that means not only the
  4358. 2:30:46fact table is getting filtered by the
  4359. 2:30:48role of the security but as well our
  4360. 2:30:50dimension. So as you can see my friends
  4361. 2:30:52this is the power of the relationships
  4362. 2:30:54and the filter directions. We can
  4363. 2:30:55control which tables must be secured
  4364. 2:30:57based on the security requirements. So
  4365. 2:30:59actually you have it. This is how we
  4366. 2:31:01create a static role security. Now of
  4367. 2:31:04course let's move to that dynamic one.
  4368. 2:31:06So now how we going to do it? First of
  4369. 2:31:07all I'm going to go and remove all those
  4370. 2:31:08stuff. So we don't need you. Same thing
  4371. 2:31:11for you. And then reset everything back.
  4372. 2:31:14Now before I start creating any roles,
  4373. 2:31:16we actually need a security table. So I
  4374. 2:31:18need a mapping between a user and their
  4375. 2:31:21regions. Now there is like two options
  4376. 2:31:23for that again. Either you load it from
  4377. 2:31:25outside or if it's like only few users,
  4378. 2:31:27you can go and enter data for that. But
  4379. 2:31:29for this I have prepared something for
  4380. 2:31:31you. So if you go and connect a new CSV,
  4381. 2:31:33there is here a table called security.
  4382. 2:31:35Let's go and connect it. So now look at
  4383. 2:31:37this. We have user emails and the
  4384. 2:31:39regions. Now we can see that the first
  4385. 2:31:41row is actually not the header. So
  4386. 2:31:42[clears throat] that's why I'm going to
  4387. 2:31:43go and transform the data quickly. And
  4388. 2:31:45all what you have to do is to just use
  4389. 2:31:46first row as a headers. All right. This
  4390. 2:31:49looks way nicer. Now let's go and close
  4391. 2:31:51and apply. All right. So with this we
  4392. 2:31:52got our new security table. Of course
  4393. 2:31:54the next step we have to go and connect
  4394. 2:31:56it to our data model. So we're going to
  4395. 2:31:58go through the dimensions. We're going
  4396. 2:31:59to connect the regions per region. Okay.
  4397. 2:32:01So now here we have like many to many
  4398. 2:32:03relationship which is totally fine. What
  4399. 2:32:05is very important is the filter
  4400. 2:32:07direction. So we have to pick this. The
  4401. 2:32:09security filters the dimension store.
  4402. 2:32:11This is very critical to do it correctly
  4403. 2:32:14otherwise it will not reach our data
  4404. 2:32:16model. So actually that's it. Let's go
  4405. 2:32:17and save it again. Look at this. The
  4406. 2:32:20arrow is moving from the security to the
  4407. 2:32:22dimension and the dimension is moving to
  4408. 2:32:24the facts. This is very important one.
  4409. 2:32:26All right. So now if you go of course to
  4410. 2:32:28the report view, you're going to see all
  4411. 2:32:29the data. PowerBI don't know yet how to
  4412. 2:32:31use the security table. So nothing
  4413. 2:32:33actually going to happen. That's why
  4414. 2:32:35we're going to go back to the model
  4415. 2:32:36view. And of course comes the magic.
  4416. 2:32:38We're going to go and create a new role.
  4417. 2:32:40So again manage roles this is not static
  4418. 2:32:42we are working on the dynamic we will
  4419. 2:32:44not go and create like a role for each
  4420. 2:32:47region it is enough to have only one. So
  4421. 2:32:49let's go and create one and let's go and
  4422. 2:32:51call it regional access. Now of course
  4423. 2:32:54the question is which table should be
  4424. 2:32:56filtered based on this role. It's again
  4425. 2:32:58the same thing the dimension store. And
  4426. 2:33:00now since the dynamic it is little bit
  4427. 2:33:02more advanced we will not go and create
  4428. 2:33:03here a new rule. It is not a simple
  4429. 2:33:05filter. We're going to go and switch to
  4430. 2:33:07DAX in order to write the filter
  4431. 2:33:09expression for PowerBI to understand how
  4432. 2:33:11to filter the dimension. Okay. So now
  4433. 2:33:13let's do it step by step. We just want
  4434. 2:33:15to create the filter condition. And the
  4435. 2:33:17first question is what we are actually
  4436. 2:33:19filtering. We are filtering the regions
  4437. 2:33:21inside the dimension store. So that
  4438. 2:33:23means I'm going to go and write it like
  4439. 2:33:24this. The region inside the dimension
  4440. 2:33:26store should be equal to the following
  4441. 2:33:28value. Now if you are just creating like
  4442. 2:33:30a static RLS, it's going to be like
  4443. 2:33:32this. So equal to Europe or USA. But
  4444. 2:33:34actually we will not do that. We want to
  4445. 2:33:36make things dynamic. Now the first thing
  4446. 2:33:38that we have to decide is actually we
  4447. 2:33:40will not go and use the equal operator.
  4448. 2:33:42We're going to go with the in. And
  4449. 2:33:43that's because one user might have
  4450. 2:33:45multiple regions. So that means we might
  4451. 2:33:47have a list and in order to filter using
  4452. 2:33:50a list we have to use an n operator not
  4453. 2:33:52an equal. Equal is only for one value.
  4454. 2:33:54Now the regions should be filtered based
  4455. 2:33:56on the other table. The security. So
  4456. 2:33:58that means we have to get the values of
  4457. 2:34:00the security in the filter and we can do
  4458. 2:34:03that using the function calculate table.
  4459. 2:34:05So we're going to tell PowerBI go and
  4460. 2:34:07grab the values from another table based
  4461. 2:34:10on a filter. So that means we're going
  4462. 2:34:11to go and use the values and actually we
  4463. 2:34:13need the security region. Perfect. With
  4464. 2:34:16that we are getting the regions from the
  4465. 2:34:17security but of course I don't need all
  4466. 2:34:19the regions. I need only the regions of
  4467. 2:34:22specific user that is actually opening
  4468. 2:34:24the reports. That's why we have to go
  4469. 2:34:25and build a filter. And of course comes
  4470. 2:34:28now the magic the most important thing
  4471. 2:34:29we're going to say filter the emails
  4472. 2:34:31inside the security but based on the
  4473. 2:34:34email of the person that is actually
  4474. 2:34:36looking at the reports and for that we
  4475. 2:34:38have the very nice function user
  4476. 2:34:40principle name. This function will just
  4477. 2:34:42return the email address of the current
  4478. 2:34:44user. So with that we will not get all
  4479. 2:34:45the regions from the security only for
  4480. 2:34:47the one that is looking at the report.
  4481. 2:34:49And actually that's it. So now let's
  4482. 2:34:51read it again. filter the regions inside
  4483. 2:34:53the dimension store based of the values
  4484. 2:34:56of the security regions but of course
  4485. 2:34:59not all the regions only for the regions
  4486. 2:35:01that are equal to the email address of
  4487. 2:35:04the current user so this is exactly how
  4488. 2:35:06we build a dynamic role level security
  4489. 2:35:08now we can go and verify the DAX looks
  4490. 2:35:10good we're going to go and save it and
  4491. 2:35:12actually that's it we have only one role
  4492. 2:35:14we are filtering one dimension and we
  4493. 2:35:16have a dynamic flexible expression so
  4494. 2:35:18let's go and close it of course we have
  4495. 2:35:20to test if you go to the report view.
  4496. 2:35:22You can see nothing is changed. We still
  4497. 2:35:23have all the orders. Of course, the
  4498. 2:35:25effect is going to happen once you
  4499. 2:35:26publish to PowerBI service. Again, we
  4500. 2:35:28will not go and ask a user to test for
  4501. 2:35:30us. We can test it directly in the
  4502. 2:35:32desktop. So, we just need like an email
  4503. 2:35:34address to test. I'm going to go to the
  4504. 2:35:35security and go and pick Maria. I'm just
  4505. 2:35:38go and copy the value. Now, in order to
  4506. 2:35:40test, we're going to go to the model
  4507. 2:35:41view and then view us. Now, again, we're
  4508. 2:35:43going to go and activate the regional
  4509. 2:35:45access and then say okay. Now, as usual,
  4510. 2:35:48we're going to see this warning. And now
  4511. 2:35:49we are viewing as the regional access.
  4512. 2:35:51Of course, we have to test. If you go to
  4513. 2:35:52the report view, we will not see
  4514. 2:35:54anything. Well, what is going on? Now
  4515. 2:35:56the thing is PowerBI is trying to get my
  4516. 2:35:59email address that is currently looking
  4517. 2:36:01to the report and try to filter the data
  4518. 2:36:03based on that. And since I don't have my
  4519. 2:36:05email address inside my data, this is
  4520. 2:36:08just like fake one. I will not find any
  4521. 2:36:10match over here. And it going to say
  4522. 2:36:11okay, you are not allowed to see
  4523. 2:36:13anything. That's why I cannot see
  4524. 2:36:15anything in the fact table, which is a
  4525. 2:36:16good thing of course. But in order to
  4526. 2:36:18really test this is not a bad effect.
  4527. 2:36:20We're going to go to the view as and
  4528. 2:36:22this time we're going to say other user
  4529. 2:36:23not my user. So I would like to see the
  4530. 2:36:25report as Maria is looking to the
  4531. 2:36:27report. So we're going to go over here
  4532. 2:36:29and put her email. So that I'm going to
  4533. 2:36:31see exactly how she can see the report
  4534. 2:36:33and say okay. Now you can see now
  4535. 2:36:34viewing as a regional access and the
  4536. 2:36:37email address. So Maria now let's go and
  4537. 2:36:39test to the report view. Look at this.
  4538. 2:36:41Now we can see only Europe data and
  4539. 2:36:43that's because Maria has access only to
  4540. 2:36:45the region Europe. So this is perfect.
  4541. 2:36:48Now let's go and test another user. So
  4542. 2:36:50we're going to say okay not Maria this
  4543. 2:36:53going to be John and then okay. You can
  4544. 2:36:55see now we are viewing as John. Let's
  4545. 2:36:57see what he can see. Well John has
  4546. 2:36:58access only to region USA. That's why
  4547. 2:37:01the report is now showing only USA
  4548. 2:37:03region. So this is exactly the dynamic
  4549. 2:37:05the report the data model going to be
  4550. 2:37:07filtered exactly for specific user and
  4551. 2:37:09if the user doesn't exist like the one
  4552. 2:37:11that I had at the start then the user
  4553. 2:37:13will not see anything. Now let's go and
  4554. 2:37:15test the fake one that we had. So I had
  4555. 2:37:17another one called bar which has of
  4556. 2:37:19course all the access of all regions.
  4557. 2:37:21Now we can see okay we are viewing the
  4558. 2:37:23data as bar Gmail. Now let's go and
  4559. 2:37:25test. You can see now I'm able to see
  4560. 2:37:27multiple regions which is totally okay.
  4561. 2:37:29So even if a user like me with multiple
  4562. 2:37:32access to multiple regions the role
  4563. 2:37:34level security is working because we are
  4564. 2:37:36using the in operator and actually my
  4565. 2:37:38friends that's it. This is how we create
  4566. 2:37:40a dynamic role level security in PowerBI
  4567. 2:37:43by using a very simple expression index.
  4568. 2:37:46All right friends, so now let's do a
  4569. 2:37:47quick recap. Security is a very
  4570. 2:37:49important part in data moduling. Do the
  4571. 2:37:51data moduling correctly. Then it's going
  4572. 2:37:53to be really easy to build a security on
  4573. 2:37:55top of it. Security have three types.
  4574. 2:37:57Table level, column level, and rowle
  4575. 2:37:59security. Of course, the most common one
  4576. 2:38:01that is used in project is the rowle
  4577. 2:38:03security RLS. It's all about how to
  4578. 2:38:05filter the rows of your tables to show
  4579. 2:38:07only the allowed rows. And there are
  4580. 2:38:09actually two ways on how to build the
  4581. 2:38:11row level security. We have the static
  4582. 2:38:14RLS to filter only the rows based on a
  4583. 2:38:17static value. It works great if you have
  4584. 2:38:19a small projects with few users. But if
  4585. 2:38:21your project is growing over the time,
  4586. 2:38:23then you have to switch to more flexible
  4587. 2:38:25way by building a dynamic RLS where
  4588. 2:38:28you're going to filter the data based on
  4589. 2:38:30users not static values. And in order to
  4590. 2:38:33do that, we need some extra stuff like
  4591. 2:38:35for example a security table where it
  4592. 2:38:37going to map the users to specific
  4593. 2:38:39values of your data model. Then you have
  4594. 2:38:42to be very careful how to connect this
  4595. 2:38:44security table to your data model by
  4596. 2:38:46using the right direction of the
  4597. 2:38:48filters. Otherwise, nothing going to
  4598. 2:38:49happen. And the last step, we're going
  4599. 2:38:51to go and write a very simple DAX
  4600. 2:38:53expression in order to let PowerBI know
  4601. 2:38:55how to filter your data model based on
  4602. 2:38:57the security values. Of course in real
  4603. 2:38:59projects we don't rush and build the
  4604. 2:39:01role securities. We have always to do it
  4605. 2:39:03step by step and slowly. So first we
  4606. 2:39:05have to understand the security
  4607. 2:39:07requirement in our domain. Usually we go
  4608. 2:39:09and ask a security officer or someone
  4609. 2:39:11that knows about those topics. We don't
  4610. 2:39:13go and randomly apply security stuff
  4611. 2:39:15inside our data model that is totally
  4612. 2:39:17maybe unnecessary. So don't follow your
  4613. 2:39:19guts about this. Always ask and make
  4614. 2:39:21sure that you are implementing what is
  4615. 2:39:23needed. Once you understand the
  4616. 2:39:24requirements then understand where you
  4617. 2:39:26can apply it inside your data model.
  4618. 2:39:28Don't try to force it in all tables
  4619. 2:39:30unless it's needed. And of course, not
  4620. 2:39:32only that as well, your filter should be
  4621. 2:39:34able to reach those tables and
  4622. 2:39:36dimensions. But again, we secure only
  4623. 2:39:38the things that is required. We don't
  4624. 2:39:40have to go and like secure every single
  4625. 2:39:42table inside the data model. So don't
  4626. 2:39:44make your life hard if it's not
  4627. 2:39:46required. And what is very important, we
  4628. 2:39:48always have to test. That means you have
  4629. 2:39:50to know the big numbers of your data
  4630. 2:39:51model by heart and you have always to
  4631. 2:39:53test the effect of the RLS. So actually
  4632. 2:39:56that's it. This is the role of security
  4633. 2:39:57in PowerBI. I know that was not an easy
  4634. 2:40:00one. This is an advanced topic. But once
  4635. 2:40:02you understand it, you can go and apply
  4636. 2:40:03it [music] to any project.
  4637. 2:40:08Hey friends. So now we're going to do
  4638. 2:40:09something amazing. We're going to go and
  4639. 2:40:11build data model projects in PowerBI
  4640. 2:40:13exactly like I do in my real projects.
  4641. 2:40:15The thing is I have been involved in
  4642. 2:40:17many PowerBI projects at my work that
  4643. 2:40:19had bad struggle with the performance
  4644. 2:40:21and as well delivering wrong numbers.
  4645. 2:40:23But after investigating it was not the
  4646. 2:40:25dashboard was bad or ducks. Almost each
  4647. 2:40:27time it was the bad model underneath the
  4648. 2:40:30reports. So that's why I have prepared
  4649. 2:40:32for you for this project a nightmare
  4650. 2:40:34data set that looks exactly like the one
  4651. 2:40:36that I have seen in companies. Full
  4652. 2:40:38chaos, bad shapes, bad data models and
  4653. 2:40:40as well bad relationships. So now what
  4654. 2:40:42I'm going to do, I'm going to walk you
  4655. 2:40:43through this data model step by step
  4656. 2:40:45exactly like I do in my real project. So
  4657. 2:40:47that at the end we're going to get a
  4658. 2:40:49healthy data model that is ready for
  4659. 2:40:51reporting. And yes, this is the best way
  4660. 2:40:53to learn data modeling by doing
  4661. 2:40:55projects, not just like watching
  4662. 2:40:57disconnected videos. So that at the end,
  4663. 2:40:59you develop like a feeling for the whole
  4664. 2:41:01process end to end. And very important,
  4665. 2:41:03you don't just watch me doing the
  4666. 2:41:05things, you always work with me. So for
  4667. 2:41:07each step, you pause the video, you do
  4668. 2:41:09it at your end, and then you continue.
  4669. 2:41:11All right, my friends. So this is going
  4670. 2:41:12to be fun project to do. And now let's
  4671. 2:41:14get started.
  4672. 2:41:15>> Battle stations, everybody. Let's go,
  4673. 2:41:16go, go, go, go, go. Okay, so now before
  4674. 2:41:19we jump in, I'm going to show you the
  4675. 2:41:20project faces for the data moduling. So
  4676. 2:41:22first we have to prepare. We're going to
  4677. 2:41:24open the mess. We're going to set up the
  4678. 2:41:25workspaces in power query and then we're
  4679. 2:41:28going to start investigating. So we're
  4680. 2:41:30going to start exploring and have basic
  4681. 2:41:32understanding of the tables. What is the
  4682. 2:41:34business? What are the entities? Which
  4683. 2:41:36one are good candidates for dimensions?
  4684. 2:41:38Which are for facts. So we're going to
  4685. 2:41:40develop like a big picture in our head.
  4686. 2:41:42The second phase we start building. So
  4687. 2:41:44we start building the dimensions. We're
  4688. 2:41:46going to find like a group of tables
  4689. 2:41:47that relate to each others and turn them
  4690. 2:41:50into clean dimension. So we keep
  4691. 2:41:52iterating until we build all the
  4692. 2:41:54dimensions for the data model. Then the
  4693. 2:41:56third step we're going to start building
  4694. 2:41:57the facts and connect the dimensions to
  4695. 2:41:59them. So we take all those event tables
  4696. 2:42:02and start building the fact. And after
  4697. 2:42:03that we connect all the dimensions to
  4698. 2:42:05our new facts and start testing of
  4699. 2:42:08course so that the numbers never break
  4700. 2:42:09silently in our data model. And then the
  4701. 2:42:11last phase is going to be the polishing
  4702. 2:42:13phase. We're going to go and add
  4703. 2:42:14security to our data model and then we
  4704. 2:42:16do like final test to validate the whole
  4705. 2:42:18data model. So this is the whole project
  4706. 2:42:20those are the phases that we're going to
  4707. 2:42:22go through and as well before we start
  4708. 2:42:23like building anything we have to keep
  4709. 2:42:25in our mind those rules we're going to
  4710. 2:42:27follow them from the start to the end no
  4711. 2:42:29matter which step we are in. So the
  4712. 2:42:32first rule or goal is to build star
  4713. 2:42:34schema fact table in the middle
  4714. 2:42:36surrounded by dimensions and we never
  4715. 2:42:38connect fact table together. The second
  4716. 2:42:41rule we have always to understand before
  4717. 2:42:43do any changes specially we have to
  4718. 2:42:45understand always first the grain of
  4719. 2:42:47each table. We have always to say it
  4720. 2:42:49loud in order to understand the grain
  4721. 2:42:51otherwise we're going to build wrong
  4722. 2:42:52dimensions and facts. Now the third rule
  4723. 2:42:54every info every column inside our data
  4724. 2:42:56model must earn its place. So that means
  4725. 2:42:59if we find any column that is not really
  4726. 2:43:01needed for analytics and reporting we
  4727. 2:43:04have to go and drop it. And that's
  4728. 2:43:05because of two reasons. First of all,
  4729. 2:43:07they are wasting space inside our
  4730. 2:43:09PowerBI file. If you have a lot of
  4731. 2:43:10unnecessary columns, your PowerBI file
  4732. 2:43:13going to be really heavy and hard to
  4733. 2:43:14refresh and hard to move. So that's why
  4734. 2:43:16we remove them to have some space. And
  4735. 2:43:18the second and more important, they
  4736. 2:43:20going to confuse you during building the
  4737. 2:43:22visuals and reports. So if we find
  4738. 2:43:24anything unnecessary, we just go and
  4739. 2:43:26drop it. We can always go and bring it
  4740. 2:43:28back if we need it. Rule number four, we
  4741. 2:43:30always have to protect the numbers. We
  4742. 2:43:32must know by heart the totals of our
  4743. 2:43:34data model so that each time we do like
  4744. 2:43:36a change or we connect something new. We
  4745. 2:43:38go and check those numbers to make sure
  4746. 2:43:40that they don't break. And now we come
  4747. 2:43:42to the final rule or let's say big step
  4748. 2:43:45we have to make sure that we are
  4749. 2:43:46following standards that we have to
  4750. 2:43:48define before starting the projects. And
  4751. 2:43:50of course those standards we can define
  4752. 2:43:52them from one project to another depends
  4753. 2:43:54on the requirements. But for this
  4754. 2:43:56project the standards going to be like
  4755. 2:43:57this. First of all we have to define the
  4756. 2:43:59language. Yes, this sounds like simple
  4757. 2:44:01but I saw a lot of projects where they
  4758. 2:44:02are mixing languages in the data model.
  4759. 2:44:05So yes, the language going to be here
  4760. 2:44:06English. Then we have to follow the same
  4761. 2:44:08naming convention for the table and the
  4762. 2:44:10columns. And of course there are a lot
  4763. 2:44:12of naming conventions but for these
  4764. 2:44:14projects we're going to follow the snake
  4765. 2:44:15case. All letters, all characters are
  4766. 2:44:17lowered and they are separated with
  4767. 2:44:19underscore. Now as well you have to
  4768. 2:44:21define the prefixes and the suffixes.
  4769. 2:44:23Like for example in the table names if
  4770. 2:44:25we have a fact table we can have the
  4771. 2:44:26prefix fact core. Like for example fact
  4772. 2:44:30sales and if it is dimension is going to
  4773. 2:44:32be dim shortcut for dimension like only
  4774. 2:44:34three letters underscore then the
  4775. 2:44:36dimension name like for example dim
  4776. 2:44:38customer this is really important
  4777. 2:44:40because I saw a lot of confusion if a
  4778. 2:44:42lot of people are working on the same
  4779. 2:44:43powerbi project one going to call it d
  4780. 2:44:46customer and another developer going to
  4781. 2:44:48call it dimension customer so we have to
  4782. 2:44:51set up the standard for our projects
  4783. 2:44:53before we start building now about the
  4784. 2:44:55columns we as well could bring some
  4785. 2:44:57standards like For example, the
  4786. 2:44:58surrogate keys, anything that we create
  4787. 2:45:00inside the data model going to ends with
  4788. 2:45:02the suffix underscore key like for
  4789. 2:45:04example customer key, product key. So
  4790. 2:45:07once you see in the data model, okay, it
  4791. 2:45:09ends with the underscore key that means
  4792. 2:45:11we created that. It is not a natural key
  4793. 2:45:14that cames from the source like for
  4794. 2:45:15example the customer underscore ID. This
  4795. 2:45:18is something comes from the source file
  4796. 2:45:19and the customer underscore key it is a
  4797. 2:45:22surrogate key that we just created in
  4798. 2:45:24the model. So that you have understand
  4799. 2:45:25the different types of your keys in the
  4800. 2:45:27model. Now the last rule we have to make
  4801. 2:45:29everything friendly. So that means we
  4802. 2:45:31have to give for everything the table
  4803. 2:45:33name, the column name, even some values
  4804. 2:45:35inside our tables friendly meaningful
  4805. 2:45:38name. So that once you start building
  4806. 2:45:39the reports the values can be friendly
  4807. 2:45:41and everyone can follow the reports. We
  4808. 2:45:44don't bring any cryptical shortcut
  4809. 2:45:46technical names that we inherited from
  4810. 2:45:49the source systems. So this is the
  4811. 2:45:50setup. Those are the faces, the rules,
  4812. 2:45:52the mindsets that we're going to follow
  4813. 2:45:54through the whole project. Now, let's
  4814. 2:45:56get started with our PowerBI project.
  4815. 2:45:58All right, friends. So, now I'm really
  4816. 2:45:59glad to present you the nightmare data
  4817. 2:46:02set that you're going to use for this
  4818. 2:46:03project. Have a look to this beautiful
  4819. 2:46:05chaos because my friends, there is high
  4820. 2:46:06chance if you join a company, join
  4821. 2:46:08PowerBI projects that their data model
  4822. 2:46:10looks exactly like this. I have seen
  4823. 2:46:12this in many projects where the data
  4824. 2:46:14model makes no sense. You cannot see
  4825. 2:46:16like a star schema here. Many to many
  4826. 2:46:18relationships between tables. The filter
  4827. 2:46:21direction is like everywhere and that's
  4828. 2:46:23all because people skip the data
  4829. 2:46:25modeling step. They just connect the
  4830. 2:46:27source systems to PowerBI and jump
  4831. 2:46:29immediately to the visuals to the report
  4832. 2:46:31dashboards. They just want to build
  4833. 2:46:33fancy reports for the end users. But of
  4834. 2:46:35course, after a while once they start
  4835. 2:46:37sharing the dashboards, the users can
  4836. 2:46:39understand all the numbers makes no
  4837. 2:46:40sense. they usually come back to this
  4838. 2:46:42model and start fixing the data model in
  4839. 2:46:45order to bring better numbers. So my
  4840. 2:46:47friends what I have done for the
  4841. 2:46:48preparations I brought all the scenarios
  4842. 2:46:49from my project and build this nightmare
  4843. 2:46:51data set in order to cover all the
  4844. 2:46:53scenarios that you might face in the
  4845. 2:46:55projects. So our goal is to turn this
  4846. 2:46:58into a healthy star schema bring correct
  4847. 2:47:00numbers and as well has good
  4848. 2:47:02performance. [music]
  4849. 2:47:06Okay. So now we're going to start with
  4850. 2:47:07the phase number one the preparation.
  4851. 2:47:09That means first we have to have good
  4852. 2:47:11understanding about the content of those
  4853. 2:47:13tables. So what is the business? What
  4854. 2:47:15are the entities? Which tables are good
  4855. 2:47:17candidates for dimensions? Which are for
  4856. 2:47:19facts. So basic understanding about what
  4857. 2:47:21we have and we don't have like to deep
  4858. 2:47:23dive into each small detail just to
  4859. 2:47:25develop a feeling about the business
  4860. 2:47:27about the data and after that we're
  4861. 2:47:28going to do like few setups in the power
  4862. 2:47:30query as a preparation for the project.
  4863. 2:47:32So now let's start let's understand what
  4864. 2:47:34you have here and I will not go through
  4865. 2:47:35all the relationships because we're
  4866. 2:47:37going to break the data model and anyway
  4867. 2:47:39we have like to build the relationships
  4868. 2:47:40again. So just basic understanding of
  4869. 2:47:42the tables and we're going to do that by
  4870. 2:47:44going to the table view. So we're going
  4871. 2:47:46to start from the top to the addresses.
  4872. 2:47:47So what do we have here? We have an
  4873. 2:47:49address ID, street, city name. So it's
  4874. 2:47:51all about the geographic, the addresses
  4875. 2:47:53and maybe for the customers or
  4876. 2:47:55something. So this is for the first
  4877. 2:47:56table. Let's go to the second one. The
  4878. 2:47:58campaign log. Okay, this one is a little
  4879. 2:48:00bit bigger. So here we have the
  4880. 2:48:01[clears throat] campaign name, the
  4881. 2:48:02channel, start date, end date, a budget,
  4882. 2:48:04impressions, click and spend. So it's
  4883. 2:48:06all about our marketing campaign day by
  4884. 2:48:08day. So this looks like an event and
  4885. 2:48:10this is really good candidate for a
  4886. 2:48:12fact. So we have numbers, we have dates.
  4887. 2:48:14Now let's go to the third one. We have
  4888. 2:48:15the campaign SKUs. This one looks
  4889. 2:48:17compacted. So we have the campaign name
  4890. 2:48:20again. And for each campaign, we have
  4891. 2:48:21like a list. And I think those are the
  4892. 2:48:24products that we have in the business.
  4893. 2:48:25So that means this table shows us what
  4894. 2:48:27are the products that were involved in
  4895. 2:48:30the campaign. And of course this is not
  4896. 2:48:32easy one to consume because the list is
  4897. 2:48:34usually bad for reporting and we can see
  4898. 2:48:36as well the column names are not correct
  4899. 2:48:39and we can find them in the first row
  4900. 2:48:41inside our table. Of course we have to
  4901. 2:48:42clean those up. Now let's go to another
  4902. 2:48:44table the cities. So what do we have
  4903. 2:48:46here? We have again the cities and as
  4904. 2:48:48well the regions. So this is again a
  4905. 2:48:50part of the informations about the
  4906. 2:48:52geography, the locations, the addresses.
  4907. 2:48:54This is of course a descriptive
  4908. 2:48:56informations and we're going to need
  4909. 2:48:57those stuff as a dimensions. Now let's
  4910. 2:48:59go to the next one. We have the custom
  4911. 2:49:01master. So it looks like this is our
  4912. 2:49:03customer table. So we have customer ID,
  4913. 2:49:06customer name, segments, the address ID.
  4914. 2:49:08So this is the first connection to our
  4915. 2:49:10addresses. Then we have like people, the
  4916. 2:49:12account manager, payment terms, some
  4917. 2:49:14hash keys and source ids. Those stuff
  4918. 2:49:17comes from the sources. But now look at
  4919. 2:49:19this. The customer name is not actually
  4920. 2:49:21like a person. They are companies. Like
  4921. 2:49:23here for example we have the Atlas
  4922. 2:49:25industries. So that means this is a very
  4923. 2:49:27important table for the customers and
  4924. 2:49:29our business is B2B. So that's all for
  4925. 2:49:31this one. Let's go to the next one. We
  4926. 2:49:33have the customer contacts. So what do
  4927. 2:49:35we have here? We have again the customer
  4928. 2:49:36ID, the contact name, the emails is
  4929. 2:49:39primary. Now you can see for each
  4930. 2:49:41customer like for each company we have
  4931. 2:49:43multiple contacts which makes sense of
  4932. 2:49:45course because our customers are
  4933. 2:49:46companies and usually we have to deal
  4934. 2:49:48with multiple people in the same
  4935. 2:49:49company. So this is all about who we
  4936. 2:49:51talk inside each company. Let's go to
  4937. 2:49:53the next one. We have a dimension
  4938. 2:49:55underscore order. So this one looks
  4939. 2:49:57really garbage. We have only one column
  4940. 2:50:00and no context to it. So we have some
  4941. 2:50:02kind of ids that actually we cannot
  4942. 2:50:04relate to anything so far. So I think
  4943. 2:50:06this is junk. This is something that we
  4944. 2:50:08could drop. So we just faced our first
  4945. 2:50:10garbage inside the data model. Let's go
  4946. 2:50:12to the next one. We have the exchange
  4947. 2:50:13rate. So what do we have here? We have
  4948. 2:50:15the currency, the rate and as well the
  4949. 2:50:17date. So this is as well information
  4950. 2:50:19about our business. Let's keep going to
  4951. 2:50:21the inventory. So now what do we see
  4952. 2:50:23here? We see the product names and for
  4953. 2:50:25each month we have like numbers. So this
  4954. 2:50:27all about the inventory. So that means
  4955. 2:50:30how much stock we are holding month by
  4956. 2:50:32month. And here we have like a whole
  4957. 2:50:34year. So for each month we have one
  4958. 2:50:36column. All right. Let's move to the
  4959. 2:50:38next one. We have the invoice lines. So
  4960. 2:50:40here we have like an invoice line, an
  4961. 2:50:41invoice ID, product and amount. So that
  4962. 2:50:44means we have invoices in our system and
  4963. 2:50:46those are the details about each invoice
  4964. 2:50:48and that brings us to the next table the
  4965. 2:50:51invoices and here we see like the master
  4966. 2:50:53table for the invoices. So we have the
  4967. 2:50:55invoice ID the order ID the customer
  4968. 2:50:58name the invoice date and the amount as
  4969. 2:51:00well. So this looks an event a good
  4970. 2:51:02candidate for a fact table. So it is
  4971. 2:51:04connecting to other things like the
  4972. 2:51:05invoice ID the order ID the customer
  4973. 2:51:07name to the customer table. We have a
  4974. 2:51:09date and numbers. And if we need more
  4975. 2:51:11details about the invoices, we have the
  4976. 2:51:13other table that we just checked, the
  4977. 2:51:14invoice lines. So we just puted another
  4978. 2:51:17fact. Now let's move to the next one. We
  4979. 2:51:19have the order line items. So again
  4980. 2:51:21sounds similar to the invoices. We have
  4981. 2:51:23the details about each order. So for
  4982. 2:51:25each order we have like lines and order
  4983. 2:51:27ID. And this time we are connecting to
  4984. 2:51:29the product names. So finally we see
  4985. 2:51:31here the products and then we have here
  4986. 2:51:33some numbers like the quantity, the
  4987. 2:51:34price, the cost, discount and total
  4988. 2:51:37sales. So those are the details for each
  4989. 2:51:39line. Now we're going to go to the
  4990. 2:51:41orders. So we have here two orders where
  4991. 2:51:43the orders are splitted by the year. So
  4992. 2:51:45for 2025 we have here a lot of things.
  4993. 2:51:48So here we have an order ID, a legacy
  4994. 2:51:50reference, customer name, customer city,
  4995. 2:51:52region. So again we have like some
  4996. 2:51:54repetitions inside our data set to which
  4997. 2:51:56city we're going to ship to which city
  4998. 2:51:57we're going to pill. So we have here
  4999. 2:51:59different cities. Then we have the date,
  5000. 2:52:01the order date, the order channel and a
  5001. 2:52:04lot of columns in this table. So again
  5002. 2:52:06this looks like a big table for a fact
  5003. 2:52:09because here we have an events each line
  5004. 2:52:11is about an order but as well at the
  5005. 2:52:13same time we have a lot of context
  5006. 2:52:15inside these facts. So this is a
  5007. 2:52:17gigantic one for the 2025 and I think
  5008. 2:52:19the 2026 looks exactly the same. So they
  5009. 2:52:23are just getting splitted. All right. So
  5010. 2:52:25this is our third fact I believe but
  5011. 2:52:27inside it we have a lot of dimensions
  5012. 2:52:29that we could extract. Now let's go to
  5013. 2:52:31the next one. We have the payments. So
  5014. 2:52:32this one is a small one. We have the
  5015. 2:52:34payment ID, the invoice ID, customer
  5016. 2:52:36name, date and amount. Again, looks like
  5017. 2:52:38transactions events. So this sounds like
  5018. 2:52:40a fact table as well. And now to the
  5019. 2:52:43next one which is really important, the
  5020. 2:52:45products. Finally, we have a dimension.
  5021. 2:52:47So what do you have over here? We have
  5022. 2:52:48the product code, the name, the brand,
  5023. 2:52:50the subcategory, the price and many
  5024. 2:52:53other descriptions for the products. So
  5025. 2:52:55this table holds the context for the
  5026. 2:52:58business products which is a classical
  5027. 2:53:00one for a dimension. Let's go to the
  5028. 2:53:02next one. We have the regions. Well,
  5029. 2:53:04again we have informations about the
  5030. 2:53:05region and as you can see we are
  5031. 2:53:07operating globally. North America,
  5032. 2:53:09Europe, Asia. So our business is
  5033. 2:53:11everywhere. Now let's go to the next
  5034. 2:53:12one. We have the sales targets. So we
  5035. 2:53:15have a row for each month and as well
  5036. 2:53:17the target revenue. So it looks like
  5037. 2:53:19someone planned the budget the revenue
  5038. 2:53:21for each month. And this is a classical
  5039. 2:53:23use case where we're going to compare
  5040. 2:53:25the target to the actual sales that we
  5041. 2:53:27have in the transactions. So for sure
  5042. 2:53:29we're going to need this. Now let's go
  5043. 2:53:30to the next one. We have the security.
  5044. 2:53:32This is really important one. So here we
  5045. 2:53:34can see the user email and the region.
  5046. 2:53:36So we can see each employee which region
  5047. 2:53:39they are responsible to. And of course
  5048. 2:53:41this is a perfect table that we're going
  5049. 2:53:42to use in order to build the role level
  5050. 2:53:44security. So we have to keep our eyes on
  5051. 2:53:46it. Now let's go to the next one. We
  5052. 2:53:48have the sheet one. Weird name right? I
  5053. 2:53:50think this is like something wrong here.
  5054. 2:53:52So we have the shipment ID, order ID,
  5055. 2:53:54mode, ship day, delivery date. So all
  5056. 2:53:57informations about the delivery. So we
  5057. 2:53:59can see for each step how and when
  5058. 2:54:01orders get out. Okay, interesting one.
  5059. 2:54:03But we have to rename the table. Now
  5060. 2:54:05let's go to the next one. We have the
  5061. 2:54:06shipments. Well, those two tables are
  5062. 2:54:08identical. And yes, I think the sheet
  5063. 2:54:11one is an import problem. And this is a
  5064. 2:54:13classical thing that happens inside the
  5065. 2:54:15data model that you have like two tables
  5066. 2:54:17that are identical and you have to get
  5067. 2:54:19rid one of them. So this is not really
  5068. 2:54:21good. Now let's go to the subcategories.
  5069. 2:54:23So very simple one we have here like
  5070. 2:54:25mapping between the category and the
  5071. 2:54:27subcategory. Of course, this is going to
  5072. 2:54:28help us in order to organize our
  5073. 2:54:30products later. Now, let's go to the
  5074. 2:54:32last table, the user details. So, we can
  5075. 2:54:34see here for each user we have like
  5076. 2:54:37credit limits and a phone number. Well,
  5077. 2:54:39of course, this is confusing which user
  5078. 2:54:41we are talking about. I think this going
  5079. 2:54:43to be for the customers. If you go and
  5080. 2:54:45check the customer master, well, yes, we
  5081. 2:54:47have like the same patterns in the ID.
  5082. 2:54:50So, those are more details for the
  5083. 2:54:52customers. So, that means in the data
  5084. 2:54:53sets we are using like two names.
  5085. 2:54:55sometimes users, sometimes like
  5086. 2:54:57customers. Of course, we have to deal
  5087. 2:54:58with that. All right, my friends. So
  5088. 2:55:00that's it. We just visited all the
  5089. 2:55:02tables. We developed like a feeling
  5090. 2:55:04about the business. What are the
  5091. 2:55:05entities, what are good candidate for
  5092. 2:55:07dimensions? Of course, here the big
  5093. 2:55:09dimensions going to be the customers and
  5094. 2:55:10the products. And as well, we have a lot
  5095. 2:55:12of events happening in the business. So
  5096. 2:55:14we have a lot of facts. We have
  5097. 2:55:16invoices. We have orders. We have
  5098. 2:55:18payments. And as well, we have
  5099. 2:55:19shipments. So campaign. So a lot of
  5100. 2:55:22events are happening in the business.
  5101. 2:55:23And this is going to be really
  5102. 2:55:24interesting on how to make a data model
  5103. 2:55:27out of this and how to connect things
  5104. 2:55:29together. So as you can see my friends
  5105. 2:55:30this is really important step. We have
  5106. 2:55:32to get a feeling about the data before
  5107. 2:55:34we change anything. The more you explore
  5108. 2:55:36the more you analyze you build this
  5109. 2:55:38understanding about the data about the
  5110. 2:55:40domain and it's going to be easier for
  5111. 2:55:42you later to understand the grain and
  5112. 2:55:44how to build the dimensions and facts.
  5113. 2:55:46The more you invest in this phase the
  5114. 2:55:48less errors and mistakes you're going to
  5115. 2:55:50do in the data moduling. Now, of course,
  5116. 2:55:52I have done this quickly because I have
  5117. 2:55:54built these data sets. But I really
  5118. 2:55:55recommend you to pause the video and go
  5119. 2:55:57through them one by one, understand its
  5120. 2:55:59contents. If you have done this already,
  5121. 2:56:01now we're going to go and do a last step
  5122. 2:56:03in this phase where we're going to
  5123. 2:56:04prepare the power query because we're
  5124. 2:56:05going to work a lot with the power query
  5125. 2:56:07in order to shape the data model. Not
  5126. 2:56:09everything going to be like connected.
  5127. 2:56:11We have sometimes to merge, append, and
  5128. 2:56:13as well clear some quality issues. So
  5129. 2:56:15now let's go to power query. As usual,
  5130. 2:56:17we go to transform data. Now of course
  5131. 2:56:18in this phase we will not go now and
  5132. 2:56:20transform or change any table. All what
  5133. 2:56:22we want is to just organize it because
  5134. 2:56:24the thing is as you start like building
  5135. 2:56:26the data model you will be creating new
  5136. 2:56:28tables references and quickly the
  5137. 2:56:30queries over here going to go in chaos.
  5138. 2:56:32So you will not remember which tables
  5139. 2:56:34are the source table which tables are
  5140. 2:56:36the new one that you just created. So
  5141. 2:56:38this going to get out of hand quickly
  5142. 2:56:40especially if you have like big model
  5143. 2:56:42like this. Now of course there is like
  5144. 2:56:43no best practices how to organize your
  5145. 2:56:45project but I'm going to show you how I
  5146. 2:56:47usually do it. So everyone does it in
  5147. 2:56:48their own way on their own style but
  5148. 2:56:50this is how I like to do it. So I start
  5149. 2:56:52by creating a new group. So new one and
  5150. 2:56:55we're going to give it a name. So I like
  5151. 2:56:56like numbering the folders just to sort
  5152. 2:56:58it on the left side. So the first one
  5153. 2:57:00going to be the stage. So the stage
  5154. 2:57:02going to be the folder that going to
  5155. 2:57:03contain all the row queries as it is
  5156. 2:57:06from the source systems. So that mean is
  5157. 2:57:07my friends all those queries that we see
  5158. 2:57:09now on the left side going to be inside
  5159. 2:57:11this folder. So that I know okay all the
  5160. 2:57:14row stuff are living inside this folder.
  5161. 2:57:16with that we don't mix it with new
  5162. 2:57:18tables that we generate. So let's go and
  5163. 2:57:20create it. Now you can see PowerBI put
  5164. 2:57:22everything under other queries which is
  5165. 2:57:24a good thing. Now I'm going to go and
  5166. 2:57:26select everything and drag and drop them
  5167. 2:57:28on the new folder. So this my new folder
  5168. 2:57:30the stage contains all the row sources.
  5169. 2:57:33So this is the first folder. We're going
  5170. 2:57:34to go and create another one and we're
  5171. 2:57:36going to call it two dimensions. Now,
  5172. 2:57:39this is going to be an empty folder for
  5173. 2:57:40now because we're going to put inside it
  5174. 2:57:42the new dimensions that we create from
  5175. 2:57:44the stage like the customers, the
  5176. 2:57:46products and so on. So, that means if I
  5177. 2:57:47want to go and do something for the
  5178. 2:57:48dimensions, I go immediately inside this
  5179. 2:57:50folder and I'm going to see it. Now,
  5180. 2:57:52usually after I build the dimensions,
  5181. 2:57:53I'm going to go and build the facts.
  5182. 2:57:55That's why the third one going to be the
  5183. 2:57:57fact folder. So, same thing, any fact
  5184. 2:58:00that I build from the stage, it going to
  5185. 2:58:01land inside the folder facts. Of course,
  5186. 2:58:03you can go and put them together like
  5187. 2:58:05maybe call it the data model where the
  5188. 2:58:07prefix is going to decide for you
  5189. 2:58:08whether it's fact or dimension. But I
  5190. 2:58:10like to split it like this in order to
  5191. 2:58:12have like a quick access. Now we're
  5192. 2:58:13going to go and create a last one. So a
  5193. 2:58:15new group. We're going to call this for
  5194. 2:58:17support. Now in our data model, we're
  5195. 2:58:19going to have some tables that don't
  5196. 2:58:21belong to dimensions and facts. Like for
  5197. 2:58:23example, the security stuff or maybe
  5198. 2:58:25some like data that we insert. So
  5199. 2:58:27anything that don't belong to dimensions
  5200. 2:58:29and facts going to go to this folder,
  5201. 2:58:31the support. Now you might ask okay why
  5202. 2:58:33do we have the support if we have like
  5203. 2:58:34another folder called others right we
  5204. 2:58:36could use it as well but the other
  5205. 2:58:38queries has different job so in case we
  5206. 2:58:40connected any new tables any new sources
  5207. 2:58:42to our data model it going to land
  5208. 2:58:44inside the other queries they are like
  5209. 2:58:46tables that are in my to-do list that I
  5210. 2:58:48have to work on so my friends this is
  5211. 2:58:50how I usually organize my power query in
  5212. 2:58:53order to build the data model out of the
  5213. 2:58:55row tables now look at this we have 23
  5214. 2:58:57tables inside the stage and nothing
  5215. 2:59:00inside other tables of course As we
  5216. 2:59:02progress in the projects, we're going to
  5217. 2:59:03take all those tables and put them
  5218. 2:59:04inside the different folders. We have to
  5219. 2:59:06grab all those stuff and start building
  5220. 2:59:08the data model. All right, friends. So,
  5221. 2:59:10that's what's for the phase one. We have
  5222. 2:59:11now basic understanding about the
  5223. 2:59:13content, the tables, and we have
  5224. 2:59:14prepared our projects to start building.
  5225. 2:59:16Finally, we're going to kick off the
  5226. 2:59:18phase two where we start building the
  5227. 2:59:20dimensions.
  5228. 2:59:24This is how we're going to do it. So,
  5229. 2:59:25we're going to have like a loop. We're
  5230. 2:59:27going to go through each dimension where
  5231. 2:59:29we're going to grab a group of tables
  5232. 2:59:30that describes the same thing. So the
  5233. 2:59:33same entity. So all tables that have the
  5234. 2:59:35same context for something like a
  5235. 2:59:37customer. So what we're going to do,
  5236. 2:59:38we're going to go and pull them
  5237. 2:59:39together, reshape them into one clean
  5238. 2:59:42dimension if it's possible. And we're
  5239. 2:59:44going to do whatever it takes. So we're
  5240. 2:59:46going to split, merge, append, fix, drop
  5241. 2:59:49until we get the shape of a dimension.
  5242. 2:59:51And of course before we move on to the
  5243. 2:59:53next one we have to polish the dimension
  5244. 2:59:55to make sure that we are following the
  5245. 2:59:57standards that we agreed on the starts.
  5246. 2:59:59So the snake case names the table names
  5247. 3:00:02the prefixes the suffixes everything.
  5248. 3:00:04Once it is polished then we go to the
  5249. 3:00:06next dimension. So my friends this is
  5250. 3:00:08the whole loop. We pick tables build
  5251. 3:00:10clean it to the standards and then we
  5252. 3:00:12move to the next one. But I'm going to
  5253. 3:00:13warn you from now you might find
  5254. 3:00:14yourself that you are repeating the same
  5255. 3:00:16steps over and over for each dimension.
  5256. 3:00:18And guess what? This is the part of the
  5257. 3:00:20job. This is the nature of things how we
  5258. 3:00:22build data modules. And with each
  5259. 3:00:23iterations, of course, you're going to
  5260. 3:00:25be faster. So now let's start building
  5261. 3:00:27our dimensions.
  5262. 3:00:28>> Let's go build an airport.
  5263. 3:00:30>> Okay. So now let's start with the first
  5264. 3:00:31dimension. And here we have to go and
  5265. 3:00:33pick like one topic or entity. And I'm
  5266. 3:00:35going to start with the big elephant in
  5267. 3:00:36the data model. We have the dimension
  5268. 3:00:38customer. So we're going to go and build
  5269. 3:00:40it. Now how we going to do it? We go and
  5270. 3:00:41pick all the tables that are related to
  5271. 3:00:43the customers and turn it into one
  5272. 3:00:45dimension. So now based on what we have
  5273. 3:00:47learned we have a lot of tables but
  5274. 3:00:49obviously the biggest table that's going
  5275. 3:00:50to gives us context about the customers
  5276. 3:00:52is the customer master. So now what I
  5277. 3:00:54usually do is that in this scenario
  5278. 3:00:56since we have like a lot of chaos over
  5279. 3:00:58here it's like a basel game. I'm going
  5280. 3:01:00to go and grab all those tables that are
  5281. 3:01:02related to the same topic and move them
  5282. 3:01:04to one section in the model. So for
  5283. 3:01:06example here the table customer master
  5284. 3:01:08I'm going to go and grab it over here
  5285. 3:01:09just in order to get like feeling of
  5286. 3:01:11progress over the time. Now what is the
  5287. 3:01:13other table that actually gives us more
  5288. 3:01:15context about the customers? We had the
  5289. 3:01:17contacts. So it is over here the
  5290. 3:01:19customer contacts and at the end we
  5291. 3:01:21found like a table the user details
  5292. 3:01:23where we get like phones and emails as
  5293. 3:01:25well. This one gives us some context
  5294. 3:01:27about the customers. Now there is a
  5295. 3:01:29topic that actually could be relevant
  5296. 3:01:31that the addresses. Each customer has an
  5297. 3:01:33address. Of course here the question is
  5298. 3:01:35whether we make like an extra dimension
  5299. 3:01:37for the addresses or we merge everything
  5300. 3:01:39inside the customer. So I'm going to say
  5301. 3:01:41let's go and group them as well together
  5302. 3:01:43with the customers. So this is the
  5303. 3:01:45addresses over here and for the
  5304. 3:01:46addresses we saw as well some other
  5305. 3:01:48related tables for the locations. So we
  5306. 3:01:50had like the cities it is over here and
  5307. 3:01:53as well we had the regions. So this
  5308. 3:01:56could be as well interesting. So now by
  5309. 3:01:57looking to this we have like three
  5310. 3:01:59tables about the customers and three
  5311. 3:02:01tables about the addresses. So now I
  5312. 3:02:03know okay on the top right I have the
  5313. 3:02:05dimension customers and my goal is to go
  5314. 3:02:07and turn all those tables into one
  5315. 3:02:09single dimension. So as you can see our
  5316. 3:02:11data model is getting like maybe slowly
  5317. 3:02:14less chaotic but we are not there yet we
  5318. 3:02:16didn't start. So now in order to change
  5319. 3:02:17the shape of the tables of course we
  5320. 3:02:19have to go to the power query. Now in
  5321. 3:02:21this scenario where we have a lot of
  5322. 3:02:22tables I usually start with the
  5323. 3:02:24foundations with the biggest table
  5324. 3:02:26that's going to gives us a lot of
  5325. 3:02:28context about the customer and the one
  5326. 3:02:30table that let's say has a completeness
  5327. 3:02:32like has all the customer and I'm going
  5328. 3:02:34to say this is very obvious it's going
  5329. 3:02:35to be our customer master here we have a
  5330. 3:02:37lot of columns about the customers and
  5331. 3:02:39this is very good starting point so now
  5332. 3:02:41before we do anything we will not go and
  5333. 3:02:43change now directly the shape of this
  5334. 3:02:46table we have to go and make a reference
  5335. 3:02:48out of it so that I can work on a copy
  5336. 3:02:50let's say and leave the row data as it
  5337. 3:02:52is. Maybe later we're going to need as
  5338. 3:02:54well this table for something else.
  5339. 3:02:56That's why I usually go and say okay
  5340. 3:02:58let's go and build a reference out of
  5341. 3:03:00this. So we have it over here and then
  5342. 3:03:02drag and drop it to the dimensions. All
  5343. 3:03:04right. So now let's minimize this. The
  5344. 3:03:06next step we have to go and rename it.
  5345. 3:03:08And here we have to be really careful
  5346. 3:03:09with our rules. So we said we have a
  5347. 3:03:12prefix for each dimension called dim and
  5348. 3:03:14we are using the snake case. So
  5349. 3:03:16everything should be lowered. Actually
  5350. 3:03:18that's it. This is our first dimension.
  5351. 3:03:19Now let's have a look. What do we have
  5352. 3:03:21here? We have a lot of context about the
  5353. 3:03:23customers. And how many customers do we
  5354. 3:03:25have? We have 61 customers. And this is
  5355. 3:03:28really interesting. The last row is 999.
  5356. 3:03:30And it sounds like a test customer. So
  5357. 3:03:33this is like a dummy information that
  5358. 3:03:35came from the source system. And I'm
  5359. 3:03:37going to say we have to get rid of it.
  5360. 3:03:38So I'm going to go and filter this data
  5361. 3:03:40out. And we can do that very simply by
  5362. 3:03:42going to the filter over here and search
  5363. 3:03:44for the ID. And then all what you have
  5364. 3:03:46to do is to just unmark it. That's it.
  5365. 3:03:48So now by looking to this we have 60
  5366. 3:03:51customers inside this table. This is the
  5367. 3:03:52foundations. We have to keep this in our
  5368. 3:03:54mind because as we start adding more and
  5369. 3:03:56more things to this table we have to
  5370. 3:03:58make sure that everything stay unique
  5371. 3:04:00and we stay with the 60 customers. So
  5372. 3:04:02now we have the foundations. Now let's
  5373. 3:04:04go and look to the other tables. So we
  5374. 3:04:06have the customer contacts. So over here
  5375. 3:04:08we have the ID, the name, the email and
  5376. 3:04:11is primary. So we have here more context
  5377. 3:04:13about the customers. And of course it
  5378. 3:04:15makes sense to go and put those
  5379. 3:04:16informations side by side with the other
  5380. 3:04:18context. So with the dimension customer
  5381. 3:04:20and how we do that we go and merge the
  5382. 3:04:22two tables. So it is very simple. We're
  5383. 3:04:24going to go to the dimension customers
  5384. 3:04:26and say okay let's merge the queries
  5385. 3:04:28together. So dimension customer and the
  5386. 3:04:30next one it's going to be the customer
  5387. 3:04:32contacts. The ID going to be the
  5388. 3:04:33customer ID and the left join. Make sure
  5389. 3:04:35it is always left. If you use inner you
  5390. 3:04:38might lose data from the main dimension.
  5391. 3:04:40We don't want that. So okay. Now we get
  5392. 3:04:42it like a new column over here. we have
  5393. 3:04:43to expand and select exactly what do we
  5394. 3:04:46need. So we need the name, the email and
  5395. 3:04:48is primary. So with this we got our
  5396. 3:04:50three columns side by side with the
  5397. 3:04:52other context. Now it is very important
  5398. 3:04:54once you add once you merge new data
  5399. 3:04:56inside your table you have to make sure
  5400. 3:04:58that everything stay correct. That means
  5401. 3:05:00the data is not fanning out or let's say
  5402. 3:05:02getting duplicated. Now if you go and
  5403. 3:05:04check here we had 60 customers. But now
  5404. 3:05:07as I scroll down, we have way more than
  5405. 3:05:0960 customers. And that's because the
  5406. 3:05:11same ID is keep repeating over and over.
  5407. 3:05:14And of course, that's all because the
  5408. 3:05:16new merge table that we have attached to
  5409. 3:05:18this table. So that was a really bad
  5410. 3:05:20merge between those two tables. And this
  5411. 3:05:23is exactly what you have to be careful.
  5412. 3:05:25But merging is not destroying your
  5413. 3:05:27dimension or maybe your fact. Now of
  5414. 3:05:29course the question is why did this
  5415. 3:05:30happen? Because my friends, we are
  5416. 3:05:32merging two tables with different
  5417. 3:05:34grains. So again the customer contacts
  5418. 3:05:36each row doesn't represent one customer
  5419. 3:05:38each row is representing one contact for
  5420. 3:05:41the customer. So here for example for
  5421. 3:05:43the second customer we have four
  5422. 3:05:45contacts. So the grain is different from
  5423. 3:05:47the customer master. Here each row is
  5424. 3:05:49really representing only one customer.
  5425. 3:05:52And once you merge different grains you
  5426. 3:05:54get this bad effect. So of course the
  5427. 3:05:56question is how we going to solve this?
  5428. 3:05:58Well there is like different ways on how
  5429. 3:06:00to do it. You can say you know what we
  5430. 3:06:02can go and convert this table into the
  5431. 3:06:04grain of customer. So that means each
  5432. 3:06:06row represent one customer and what do
  5433. 3:06:08we do with the contacts? We make like a
  5434. 3:06:10list of contacts. It's like we are
  5435. 3:06:12grouping up or let's say aggregating
  5436. 3:06:13this table to the level of the customer.
  5437. 3:06:15And of course we can do that if you go
  5438. 3:06:17to the transform and then group by the
  5439. 3:06:19columns by the customer ID. Another
  5440. 3:06:21solution that you might say you know
  5441. 3:06:22what this is the contact of the
  5442. 3:06:24customers and we can make another
  5443. 3:06:25dimension out of it and then make a
  5444. 3:06:27relationship between this new dimension
  5445. 3:06:29and the customer or a third solution
  5446. 3:06:31that you might say you know what let's
  5447. 3:06:33not go and add all the contacts inside
  5448. 3:06:35the customer dimension let's just add
  5449. 3:06:37the primary contact so for example for
  5450. 3:06:39the second customer we have here like
  5451. 3:06:41four people only one of them Sara is
  5452. 3:06:44actually the primary contact for this
  5453. 3:06:46customer and if that is okay for the
  5454. 3:06:47analyzes and the reports then we can go
  5455. 3:06:49and merge actually this table to the
  5456. 3:06:52customers again. But of course we have
  5457. 3:06:53to make sure that we really have like
  5458. 3:06:55one primary contact for each customer.
  5459. 3:06:57We can do that by filtering the data for
  5460. 3:06:59example over here and say show me only
  5461. 3:07:02the primary contact. So of course this
  5462. 3:07:04dimension is very small. You can go and
  5463. 3:07:06check like by eyes and see with this I
  5464. 3:07:08have exactly 60 customers and I don't
  5465. 3:07:10have like any duplicates in the primary
  5466. 3:07:12key. So now again my grain over here is
  5467. 3:07:15one row is one customer and the
  5468. 3:07:17relationship between the customer
  5469. 3:07:18contacts and the dimension customer is
  5470. 3:07:20again one to one and this is very safe
  5471. 3:07:22in order to do a merge. So now since we
  5472. 3:07:24filter the data like this let's go and
  5473. 3:07:26check our dimension customer. Now let's
  5474. 3:07:29see again we have here a clean dimension
  5475. 3:07:32where we have only 60 customers and on
  5476. 3:07:34the right side of course we have our
  5477. 3:07:36primary contacts for each customer. So
  5478. 3:07:38with this finally it is safe to merge
  5479. 3:07:40those two tables into one. Now of course
  5480. 3:07:42we are just checking by looking right
  5481. 3:07:44whether there's duplicates or not. There
  5482. 3:07:46is like smarter way on how to do it that
  5483. 3:07:48you go to the primary key the customer
  5484. 3:07:50ID and you group up the data by the
  5485. 3:07:52rows. So you say here group by and you
  5486. 3:07:54just say okay count and here the
  5487. 3:07:56operation going to be count rows. So if
  5488. 3:07:58you go and say okay of course the data
  5489. 3:08:00going to get grouped up by the rows and
  5490. 3:08:02if you see it like this where the count
  5491. 3:08:04is everywhere is one then my friend you
  5492. 3:08:06don't have any duplicates and you are
  5493. 3:08:08okay. Of course, you can go and check
  5494. 3:08:09for here. And you can see, okay, we have
  5495. 3:08:11only one value, the one. So, this is
  5496. 3:08:12something that I do each time I merge
  5497. 3:08:14two tables together to check quickly
  5498. 3:08:16whether we have duplicates or not. But
  5499. 3:08:17of course, this is only for checking.
  5500. 3:08:19So, I'm going to go and remove it. All
  5501. 3:08:20right. So, that's what the first lesson.
  5502. 3:08:22Be careful for the grains. If you are
  5503. 3:08:23merging things together now, let's go
  5504. 3:08:25and check the third table. We had the
  5505. 3:08:27user details. Right now, again, we have
  5506. 3:08:29more context to the dimension customer.
  5507. 3:08:32We have the limits and the phone. That
  5508. 3:08:33means we have to go and merge those
  5509. 3:08:35informations to our new dimension. But
  5510. 3:08:37this time we have to be careful. Do we
  5511. 3:08:38have here the same grain? Well, by
  5512. 3:08:40looking to this, I'm going to say we
  5513. 3:08:42don't have here any duplicates. Each row
  5514. 3:08:45representing one customer. So this one
  5515. 3:08:47going to be really easy. I'm going to go
  5516. 3:08:48to the table customers. Same thing.
  5517. 3:08:50We're going to go home and then merge.
  5518. 3:08:52Find our table was at the end. So user
  5519. 3:08:55details. Now things here getting
  5520. 3:08:57interesting about the entity. We have
  5521. 3:08:59here the user ID. But in other table
  5522. 3:09:02they call it user ID. We have of course
  5523. 3:09:04to talk about this because we have now
  5524. 3:09:05like two different names for the same
  5525. 3:09:07entity right but first let's go and
  5526. 3:09:09merge things together and of course we
  5527. 3:09:11have to expand. So we just need the new
  5528. 3:09:12informations credit limit and the phone.
  5529. 3:09:15And again before we celebrate having
  5530. 3:09:16more data inside our dimension we have
  5531. 3:09:18to go and check whether everything is
  5532. 3:09:20unique and we don't have duplicates. So
  5533. 3:09:22looks really good. Now before we
  5534. 3:09:24continue with the other tables and
  5535. 3:09:25building the dimension I still don't
  5536. 3:09:27like it that we found out inside our
  5537. 3:09:29data we have like two names for the same
  5538. 3:09:31entity. We had the customer and as well
  5539. 3:09:33the user. So of course what is the
  5540. 3:09:35through how we going to call this
  5541. 3:09:36dimension customer or dimension user.
  5542. 3:09:39This happens a lot of course by the way
  5543. 3:09:40in the companies where you have
  5544. 3:09:42different departments calling the same
  5545. 3:09:44entity different names. In one
  5546. 3:09:45department they call all the customers
  5547. 3:09:47as users and other is customer. So of
  5548. 3:09:49course this is always a dilemma as you
  5549. 3:09:51are building a data model especially if
  5550. 3:09:53you are connecting like multiple sources
  5551. 3:09:55inside one model inside your projects.
  5552. 3:09:57Now of course one idea could be let's go
  5553. 3:09:59and ask the business users who are using
  5554. 3:10:01the report which name they want to use.
  5555. 3:10:04Now the thing is if you are asking a
  5556. 3:10:05business user from specific department
  5557. 3:10:08they might say you know what we use
  5558. 3:10:09customers then I want to see it in the
  5559. 3:10:11report as well as customers. But if you
  5560. 3:10:13go and ask another department another
  5561. 3:10:15business they might say use the user. So
  5562. 3:10:18still it is dilemma and they will not
  5563. 3:10:20really help you in order to decide for
  5564. 3:10:21your data model. You cannot go and use
  5565. 3:10:23both of them. That's why you have to
  5566. 3:10:25have like feeling about the data model.
  5567. 3:10:27If you have a lot of tables are using
  5568. 3:10:29the customer as an info, then go with
  5569. 3:10:32the customer. Like here in our example,
  5570. 3:10:33most of our tables are using this term
  5571. 3:10:36customer and only like one table is
  5572. 3:10:38using the user. That's why I'm going to
  5573. 3:10:40decide for our data model to go with the
  5574. 3:10:42customer as an entity name and let's say
  5575. 3:10:45ignore the user as a term. So now let's
  5576. 3:10:47go back. So that means we're going to
  5577. 3:10:48stick with the name dimension customer.
  5578. 3:10:50We will not rename anything. Now let's
  5579. 3:10:52go back to the other three tables. Now
  5580. 3:10:54the next batch of tables, they are all
  5581. 3:10:56to do with the addresses. Look at this.
  5582. 3:10:58We have here the address ID. And now
  5583. 3:11:00here my friend, you have two options.
  5584. 3:11:01Either you're going to go and build a
  5585. 3:11:03new dimension called addresses and then
  5586. 3:11:05connected to the dimension customer. And
  5587. 3:11:08with that you are actually building
  5588. 3:11:09remember the snowflake schema one
  5589. 3:11:12dimension connect and branch to another
  5590. 3:11:14dimension or we're going to stick with
  5591. 3:11:16our goal where we are building the star
  5592. 3:11:18schema. So we always try to fit
  5593. 3:11:20everything together into one dimension
  5594. 3:11:22and only in extreme cases we might go
  5595. 3:11:25and branch. So of course I'm going to
  5596. 3:11:26stick with the goal. We are building
  5597. 3:11:28star schema. That means all the address
  5598. 3:11:30informations going to go inside the
  5599. 3:11:32dimension customer. And don't worry, we
  5600. 3:11:33can always go and split if things goes
  5601. 3:11:35wrong. So that means we have now to go
  5602. 3:11:37and merge more and more things to the
  5603. 3:11:39dimension customer. And I would like to
  5604. 3:11:40show you one trick that I usually use in
  5605. 3:11:42order to feel safe before merging things
  5606. 3:11:45together. Yes, you can go and count
  5607. 3:11:46things after merging, but usually I go
  5608. 3:11:48to the module layer. So, first save.
  5609. 3:11:51Yeah. Okay. Close and apply before going
  5610. 3:11:53to the model view. Now, look at this.
  5611. 3:11:55This is our new dimension that we are
  5612. 3:11:57actually building all the time. And you
  5613. 3:11:58can see that PowerBI is always trying to
  5614. 3:12:01connect a new table to the whole data
  5615. 3:12:03model. Of course, we have to remove all
  5616. 3:12:04those stuff and start from a scratch.
  5617. 3:12:06But don't worry about it. Now, now the
  5618. 3:12:07thing is if I have like a new table that
  5619. 3:12:09I would like to merge it to the table
  5620. 3:12:10customers, I go and check the cardality.
  5621. 3:12:13Like for example, we want to merge the
  5622. 3:12:14addresses with the dimension customer.
  5623. 3:12:16Right? Now you can see we have already
  5624. 3:12:17like a relationship between those two.
  5625. 3:12:19Now if I see the cardality is one to one
  5626. 3:12:22relationship between those two tables,
  5627. 3:12:24then this is really safe to merge those
  5628. 3:12:26two tables together because PowerBI
  5629. 3:12:28automatically check the values inside
  5630. 3:12:30those two tables and detect the
  5631. 3:12:32cardality. And of course this is a great
  5632. 3:12:34indicator for me to say nothing going to
  5633. 3:12:36go wrong if I go and like merge those
  5634. 3:12:38two tables together. So this is a good
  5635. 3:12:40thing. And by the way about the
  5636. 3:12:42cardality if the relationship is one to
  5637. 3:12:44many so from the addresses is one and in
  5638. 3:12:47the dimension customer is many it is
  5639. 3:12:49still safe. So this is another way to
  5640. 3:12:51check before let's say merging two
  5641. 3:12:53tables together. Let's go back to power
  5642. 3:12:54query. So now same thing let's go to the
  5643. 3:12:57dimension customer. We're going to go
  5644. 3:12:58and merge and here we're going to search
  5645. 3:13:00for the addresses. This time the ID
  5646. 3:13:03going to be the address ID as well. Here
  5647. 3:13:05address ID always left join never inner
  5648. 3:13:08join. If you have one missing address
  5649. 3:13:10then you are removing a whole customer.
  5650. 3:13:12So this is not safe. We always use lift
  5651. 3:13:14join and same things. So we're going to
  5652. 3:13:16go and expand. We just need the street
  5653. 3:13:18and the city name. So look at this.
  5654. 3:13:20Looks nice. Now of course we have to go
  5655. 3:13:22and test. So do we have 60 customers?
  5656. 3:13:24Well yes. So merging the addresses
  5657. 3:13:27didn't cause any harm any issues. Now
  5658. 3:13:29what else do we have? We have the cities
  5659. 3:13:31right? So let's go over here. Now what
  5660. 3:13:33do we have here? We have the city name
  5661. 3:13:34and the region name. But here we have
  5662. 3:13:36equality issue. You can see that the
  5663. 3:13:38first row is actually the column names
  5664. 3:13:40and not the column one and column two.
  5665. 3:13:42Now in order to fix this, this is very
  5666. 3:13:43simple. We have here in the ribon use
  5667. 3:13:45first row as headers. So probably are
  5668. 3:13:47going to go and promote the first header
  5669. 3:13:49as the column name for the table. So
  5670. 3:13:51this is very simple. Look at this. We
  5671. 3:13:52have now the city name and the region
  5672. 3:13:54name. Now again what we're going to do
  5673. 3:13:55we're going to go and merge this inside
  5674. 3:13:57our dimension customer. Again as I told
  5675. 3:13:59you you can go and check whether we have
  5676. 3:14:01a one relationship at this table. So we
  5677. 3:14:04have it over here the cities. Let's go
  5678. 3:14:06and grab it. I'm going to go and remove
  5679. 3:14:07this relationship and then try to
  5680. 3:14:10connect it to the dimension customer.
  5681. 3:14:12This of course only for test. So I'm
  5682. 3:14:13going to take the city name to the city
  5683. 3:14:15name. All right. Look at this one to
  5684. 3:14:17many relationship. So at the side of the
  5685. 3:14:19cities we have one. So I'm going to get
  5686. 3:14:21good feeling about it in order to merge
  5687. 3:14:22those two tables together. We don't have
  5688. 3:14:24many. This will not duplicate my
  5689. 3:14:26customers. So that means we're going to
  5690. 3:14:28go back to transform data. So again we
  5691. 3:14:30merge. And as you can see I'm merging
  5692. 3:14:32all the time and I will keep doing that.
  5693. 3:14:34So let's go and connect our cities. So
  5694. 3:14:36city name and the city name is somewhere
  5695. 3:14:39over here. So let's go and connect left
  5696. 3:14:41join. Now what do we need from this
  5697. 3:14:43table is actually only the region name.
  5698. 3:14:45We have already city name. So we
  5699. 3:14:47actually don't need it twice inside our
  5700. 3:14:49dimension. And we're going to go and
  5701. 3:14:50check we have 60 customers. All right.
  5702. 3:14:53Now to the last table. We have the
  5703. 3:14:54regions. Well here we have only one
  5704. 3:14:57column. We don't have like a lot of
  5705. 3:14:58context that's going to help us for the
  5706. 3:15:00dimension customer. And the region
  5707. 3:15:02information we have it already. So it
  5708. 3:15:04makes no sense to merge this table to
  5709. 3:15:06the dimension customers. This
  5710. 3:15:08information is already in our dimension.
  5711. 3:15:10So as you can see we have here the
  5712. 3:15:11regions. So actually this makes no sense
  5713. 3:15:14to merge inside our dimension customer.
  5714. 3:15:16It will not add any value or add any
  5715. 3:15:18context. And this is of course one of
  5716. 3:15:20the things that happens all the time
  5717. 3:15:21inside the data models. You're going to
  5718. 3:15:23find the same piece of information
  5719. 3:15:25multiple times in multiple tables. So
  5720. 3:15:27the region exists here and as well in
  5721. 3:15:29the cities and maybe in another table
  5722. 3:15:31that we didn't discover yet. So here we
  5723. 3:15:33have to be very careful we are not like
  5724. 3:15:35repeating the same data over and over
  5725. 3:15:37otherwise we are confusing the data
  5726. 3:15:38model. So my friends we went through the
  5727. 3:15:40six tables and we have now one gigantic
  5728. 3:15:43table that holds all the context about
  5729. 3:15:45the customers. So that was big step. We
  5730. 3:15:48have compiled now six tables into one
  5731. 3:15:50dimension customers. But we are not done
  5732. 3:15:52yet. We will not go to the second
  5733. 3:15:53dimension until we do my favorite step.
  5734. 3:15:56We have to do the housekeeping. So we
  5735. 3:15:57have to clean up, organize and make sure
  5736. 3:15:59that we are following the standards. So
  5737. 3:16:01we polish everything in order to make
  5738. 3:16:03the dimension is ready to get used in
  5739. 3:16:06the data model. So let's do that. All
  5740. 3:16:08right. So now the first step that we
  5741. 3:16:09have to do is that we have to get rid of
  5742. 3:16:11unnecessary informations unnecessary
  5743. 3:16:13columns inside the dimension. Remember
  5744. 3:16:15the rule each info each data should earn
  5745. 3:16:17its place. So that means if there is
  5746. 3:16:19something unnecessary we have to remove
  5747. 3:16:21it. Otherwise it's going to take space.
  5748. 3:16:23It going to lead to bad performance and
  5749. 3:16:25as well it going to lead to confusion as
  5750. 3:16:27you start building the reports. So that
  5751. 3:16:29means my friends now we're going to go
  5752. 3:16:30through all the columns inside our new
  5753. 3:16:32dimension and think about it should we
  5754. 3:16:34leave it or should we drop it. So the
  5755. 3:16:36customer ID for sure it's going to stay
  5756. 3:16:38the customer name the segments all those
  5757. 3:16:40informations are important for filtering
  5758. 3:16:42and slicing and building visuals. Now to
  5759. 3:16:45the address ID well my friends I believe
  5760. 3:16:48we don't need it. I can't imagine that
  5761. 3:16:50this going to be necessary for reporting
  5762. 3:16:52only for connecting things. And we have
  5763. 3:16:54decided to put everything together into
  5764. 3:16:56one dimension. We are not making
  5765. 3:16:57snowflake that's why I'm going to go and
  5766. 3:17:00drop it. So remove the account manager.
  5767. 3:17:02Okay the payment terms going to stay.
  5768. 3:17:04Now the hash keys well my friends those
  5769. 3:17:06stuffs comes from the source system and
  5770. 3:17:08I will never imagine that we're going to
  5771. 3:17:10need this for reporting. That's why
  5772. 3:17:12we're going to go remove. By the way
  5773. 3:17:13this takes a lot of space inside the
  5774. 3:17:15data model. I remember in one project we
  5775. 3:17:17had like for each table one hash key
  5776. 3:17:20where the refresh time for the data
  5777. 3:17:21model was really horrible. It took a lot
  5778. 3:17:23of time and all because those hash keys
  5779. 3:17:25they are string values and they are
  5780. 3:17:27really big and if you have millions of
  5781. 3:17:29rows imagine how much space this takes.
  5782. 3:17:31So the fix was very simple to just go
  5783. 3:17:33and drop all those hash keys and
  5784. 3:17:35suddenly we saved around I think 20% of
  5785. 3:17:37the data set. So now let's go and remove
  5786. 3:17:39the hash key. Then we have source ID.
  5787. 3:17:41This is as well some garbage from the
  5788. 3:17:43source system. We would never use this.
  5789. 3:17:45Now here we have the primary contacts.
  5790. 3:17:47Okay we have their email. Now whether it
  5791. 3:17:50is primary well this going to be always
  5792. 3:17:51true, right? We use this as a filter. So
  5793. 3:17:54that means actually this is like totally
  5794. 3:17:56useless information and we would never
  5795. 3:17:58use this. So let's go and remove it.
  5796. 3:18:01Credit limits going to stay the phone,
  5797. 3:18:03the street, the city name and the
  5798. 3:18:05region. So not that bad, right? We just
  5799. 3:18:07dropped like around four columns. All
  5800. 3:18:09right. So this is the first step that
  5801. 3:18:11we're going to do in order to clean up
  5802. 3:18:13our dimension. Now comes the naming
  5803. 3:18:15convention. As you can see, we are not
  5804. 3:18:17following the standards. Only the table
  5805. 3:18:19name is actually using the camel case.
  5806. 3:18:21But all the columns are actually
  5807. 3:18:23following another case. This we call it
  5808. 3:18:25the Pascal case where we don't have any
  5809. 3:18:27separations and the first letter is
  5810. 3:18:29capitalized. Now of course since we have
  5811. 3:18:32committed to the snake case we have to
  5812. 3:18:34go and rename all the columns or you can
  5813. 3:18:36say you know what since everything is
  5814. 3:18:37like Pascal case I'm going to go and
  5815. 3:18:39change the rules but of course you have
  5816. 3:18:40to stick to it and we're going to follow
  5817. 3:18:42the Pascal case. Well this is something
  5818. 3:18:44that you decide but I have decided for
  5819. 3:18:46the snake case and I'm going to go and
  5820. 3:18:47now rename everything to the standards
  5821. 3:18:49but of course I'm going to speed up. So
  5822. 3:18:51I'll just do it for the first column for
  5823. 3:18:53you. So this going to be the customer ID
  5824. 3:18:55and this going to be customer name right
  5825. 3:18:58like this. So now see you soon. All
  5826. 3:19:00right. So now to the last column. As you
  5827. 3:19:02can see here we have the cities dot
  5828. 3:19:04region name. We don't need the cities
  5829. 3:19:06dot because this is just comes from the
  5830. 3:19:08original table the cities. We're just
  5831. 3:19:10going to go and call it region. That's
  5832. 3:19:12it. So I'm going to say everything is
  5833. 3:19:14clean inside our dimensions. The names
  5834. 3:19:16are friendly. So the table name, the
  5835. 3:19:18column names and as well the values
  5836. 3:19:21inside the table. This is really
  5837. 3:19:22important. If you see something critical
  5838. 3:19:24technical, we have to do something about
  5839. 3:19:26it. Now I'm going to say our dimension
  5840. 3:19:28customer is ready to use. But now of
  5841. 3:19:30course before we close and go to the
  5842. 3:19:32second dimension, we have the last last
  5843. 3:19:34step where we're going to go and hide
  5844. 3:19:35all the original tables so that we don't
  5845. 3:19:37see them anymore inside the model. So
  5846. 3:19:39we're going to go through them one by
  5847. 3:19:41one. The addresses we don't need it
  5848. 3:19:42anymore. So we'll deactivate the enable
  5849. 3:19:44load. So yes, same thing for the
  5850. 3:19:47customer master. So we have to do the
  5851. 3:19:49whole thing for all six tables, the
  5852. 3:19:51cities. So deactivated the contract as
  5853. 3:19:54well here. The regions, well actually we
  5854. 3:19:56didn't merge it, but we don't need it.
  5855. 3:19:58We have this information already in the
  5856. 3:20:00dimension customer. And the last one,
  5857. 3:20:01the user details. So right click and
  5858. 3:20:04disable. Okay. So with this, we have
  5859. 3:20:06consolidated a lot of things into one
  5860. 3:20:08dimension. Let's go and close and apply.
  5861. 3:20:14Well, look at this. Everything gone and
  5862. 3:20:16I have only the dimension customer. Now,
  5863. 3:20:18I'm going to go and clean up those
  5864. 3:20:20relationships. I don't need them. So,
  5865. 3:20:22remove, remove, and last remove. So, now
  5866. 3:20:25comes the most satisfying like thing
  5867. 3:20:27that I'm going to do. We're going to
  5868. 3:20:28zoom out and look at this. Our data
  5869. 3:20:30model get reduced a little bit. And now
  5870. 3:20:32we have here one good solid dimension.
  5871. 3:20:34So, my friends, this is the first
  5872. 3:20:36dimension. And I'm going to say this is
  5873. 3:20:37the biggest dimension that we have
  5874. 3:20:38inside this row data model. We have of
  5875. 3:20:41course to keep iterating on this. And
  5876. 3:20:42the next big dimension of course in our
  5877. 3:20:45business the products. And now again the
  5878. 3:20:47same iteration we start by collecting
  5879. 3:20:48all the tables that has to do with the
  5880. 3:20:50products. We had very big table called
  5881. 3:20:53products where we have a lot of context
  5882. 3:20:55about it. So I'm going to drag it over
  5883. 3:20:56here. And the second table that actually
  5884. 3:20:58has to do with the products that was the
  5885. 3:21:00subcategories. I don't find it. Well
  5886. 3:21:02yeah it's over here. So this one going
  5887. 3:21:04to organize the products. And I think by
  5888. 3:21:06looking to this actually that's it. So
  5889. 3:21:08we have only two tables to do with the
  5890. 3:21:10products. We're going to go and try to
  5891. 3:21:12merge everything into a new dimension
  5892. 3:21:14called dem product. So let's go and do
  5893. 3:21:16that. We're going to go again to the
  5894. 3:21:18power query. All right. So now our two
  5895. 3:21:20tables are again the products and the
  5896. 3:21:22subcategories. Now of course we have to
  5897. 3:21:24start one of them as the foundations.
  5898. 3:21:26It's going to be the products of course
  5899. 3:21:27because here we have a lot of context.
  5900. 3:21:29This is the master table for our
  5901. 3:21:31dimension. So as usual so what we're
  5902. 3:21:33going to do same thing. We're going to
  5903. 3:21:34go and create a reference out of it.
  5904. 3:21:35Drag and drop it to the dimensions. Let
  5905. 3:21:38me just make this smaller and we're
  5906. 3:21:40going to go and rename it. Same thing.
  5907. 3:21:41The prefix is dimension and the name is
  5908. 3:21:44product. Okay. So now let's have a quick
  5909. 3:21:45look to our dimension products. As you
  5910. 3:21:47can see, we have a lot of columns
  5911. 3:21:49describing as well. We have a lot of
  5912. 3:21:51things that we're going to clean up at
  5913. 3:21:52the end. But of course, we have to
  5914. 3:21:53understand how many products do we have.
  5915. 3:21:55Well, same thing. We have 60 products.
  5916. 3:21:58And the last one, we have as well a
  5917. 3:22:00dummy data. So it says don't use test
  5918. 3:22:02blah blah blah. So that means this is
  5919. 3:22:04something from the source. We're going
  5920. 3:22:05to go and remove it quickly. So uncheck
  5921. 3:22:07it. And other thing that's let's make
  5922. 3:22:09sure that we don't have duplicate inside
  5923. 3:22:11the products. So we can do a quick group
  5924. 3:22:14I group by. So count rows. Okay. Now we
  5925. 3:22:17check this. Do we have any twos? Well,
  5926. 3:22:20only one. So this is clean. We don't
  5927. 3:22:22have any duplicates inside our products.
  5928. 3:22:24But now you might notice that we don't
  5929. 3:22:26have actually a product ID. We have a
  5930. 3:22:28product code. So that means the source
  5931. 3:22:30table is not providing like a unique
  5932. 3:22:32identifier in order to connect it to the
  5933. 3:22:34data model. it is using the code as like
  5934. 3:22:36a business key. This is of course a
  5935. 3:22:38tricky thing. So now we will not clean
  5936. 3:22:40anything yet. Let's go and check the
  5937. 3:22:42subcategories. So the subcategories is
  5938. 3:22:44over here. Now the first issue with that
  5939. 3:22:46we don't have the column name. So what
  5940. 3:22:48we're going to do we're going to use the
  5941. 3:22:49first row as headers. And the second
  5942. 3:22:51issue actually here we are merging two
  5943. 3:22:53informations in one column. We have the
  5944. 3:22:55category and the subcategory side by
  5945. 3:22:57side and they are separated with a pipe.
  5946. 3:23:00Now of course we have the subcategories
  5947. 3:23:02already in the dimension products. So we
  5948. 3:23:04have it over here but what is missing
  5949. 3:23:06which is very important is the category.
  5950. 3:23:08So that means we need the category in
  5951. 3:23:10order to add more context to this
  5952. 3:23:11dimension and we have somehow to grab it
  5953. 3:23:14from this column. Now of course we
  5954. 3:23:15cannot go and merge this directly to the
  5955. 3:23:17product because we don't have keys. The
  5956. 3:23:19keys are actually like piece of
  5957. 3:23:21information inside each value. That's
  5958. 3:23:23why we have to go and split this into
  5959. 3:23:25two columns. One category and another
  5960. 3:23:27one subcategory. So let's go and do
  5961. 3:23:29that. So here we have a nice function
  5962. 3:23:31called split columns by delimiter. So
  5963. 3:23:33here PowerBI get it correctly. We are
  5964. 3:23:35splitting by custom and the separator is
  5965. 3:23:38the pipe. So actually everything is
  5966. 3:23:40ready. Let's go and hit okay. Look at
  5967. 3:23:42this. Now we have the categories and the
  5968. 3:23:44subcategories. I'm going to go and
  5969. 3:23:45rename things because here it says one
  5970. 3:23:47and two. PowerBI has no idea about the
  5971. 3:23:49content. So this going to be the
  5972. 3:23:51category and the other one going to be
  5973. 3:23:53the subcategory. Now we are not there
  5974. 3:23:55yet because if you look at this you see
  5975. 3:23:57that all the subcategories all the
  5976. 3:23:59values are lowercased but if you check
  5977. 3:24:01our dimension over here you see the key
  5978. 3:24:04is not ready yet. We have it
  5979. 3:24:05capitalized. So the first letter is
  5980. 3:24:07actually an uppercase and this will not
  5981. 3:24:09work. So if I go and merge now things
  5982. 3:24:11together powerbi will not find any
  5983. 3:24:13match. So as you can see we have always
  5984. 3:24:14like to prepare the data before merging.
  5985. 3:24:16The keys must work otherwise you're
  5986. 3:24:18going to get only nulls after merging.
  5987. 3:24:20So now either we're going to make this
  5988. 3:24:21lowerased or we go over there and we
  5989. 3:24:23make the key as a capitalize. I'm going
  5990. 3:24:25to change it over here in the reports.
  5991. 3:24:27It looks way nicer if you have things
  5992. 3:24:29capitalized. So how we going to do it?
  5993. 3:24:30We're going to go to transform and here
  5994. 3:24:32we have a nice function called
  5995. 3:24:33capitalize each word. So let's do it.
  5996. 3:24:36Now our key is ready for the merge. So
  5997. 3:24:38everything now is simple. We're going to
  5998. 3:24:39go to the dimension product. As usual we
  5999. 3:24:42merge. We go and pick our table. So it
  6000. 3:24:44is the subcategories over here. And now
  6001. 3:24:47all we have to do is to just select
  6002. 3:24:48things. So subcategory with the
  6003. 3:24:50subcategory and left join. So let's go
  6004. 3:24:53and set. Okay. All right. We have it
  6005. 3:24:56here as a table. We have to expand.
  6006. 3:24:57Well, we don't need the subcategory. We
  6007. 3:24:59have it already. We just need the
  6008. 3:25:00category. So okay, now it is working. As
  6009. 3:25:03you can see, we have now the categories
  6010. 3:25:05inside our table. All right. So now with
  6011. 3:25:07this, I'm going to say that our
  6012. 3:25:09dimension now hold all the context about
  6013. 3:25:11the products in one table. We don't have
  6014. 3:25:13anything else from the other tables. Now
  6015. 3:25:15we're going to come back to this topic
  6016. 3:25:16where I said we don't have like an ID
  6017. 3:25:18from the source system. We just have
  6018. 3:25:20like a code and a name. So it's not like
  6019. 3:25:22the dimension customer we had here like
  6020. 3:25:24an ID. Now here we have like two options
  6021. 3:25:26either we're going to leave it as it is
  6022. 3:25:28or we're going to go and create a
  6023. 3:25:29surrogate key something that we create
  6024. 3:25:31inside the model not from the business
  6025. 3:25:33and we're going to use this ID in order
  6026. 3:25:35to connect it to the facts in the
  6027. 3:25:37future. So I'm going to say for now I'm
  6028. 3:25:38going to go and add it. So we're going
  6029. 3:25:40to go and add column and we just go and
  6030. 3:25:41add an index column and we start from
  6031. 3:25:43one. So we have it over here. I'm going
  6032. 3:25:45to go and rename it. So this going to be
  6033. 3:25:47not the product ID. This going to be the
  6034. 3:25:50product underscore key. We agreed in the
  6035. 3:25:52rules if you are creating any keys from
  6036. 3:25:54us. We always have the suffix underscore
  6037. 3:25:57key for it. So that I know which ids
  6038. 3:25:59come from the source and which one that
  6039. 3:26:01I created. So it looks like this and we
  6040. 3:26:03have like 60 products. Now I'm going to
  6041. 3:26:05say we are done with merging and
  6042. 3:26:07creating things. Let's go to the last
  6043. 3:26:08step where we start like cleaning up and
  6044. 3:26:10bringing standards to this dimension. So
  6045. 3:26:12that means again we're going to go
  6046. 3:26:13through all the columns one by one and
  6047. 3:26:15say whether they going to stay or leave.
  6048. 3:26:17So the code of course going to stay the
  6049. 3:26:19name, the brand, the subcategory, the
  6050. 3:26:21prices, the supplier. We could use it
  6051. 3:26:23for slicer. Now comes something that I
  6052. 3:26:26saw a lot in data models where people
  6053. 3:26:28just leave such information here. So
  6054. 3:26:30those are the big text the descriptions.
  6055. 3:26:33Now this is of course a huge text. It is
  6056. 3:26:36describing each product. And of course,
  6057. 3:26:38we have to ask ourselves, do we really
  6058. 3:26:40going to go and use such a description
  6059. 3:26:41inside our reports? In most cases, no,
  6060. 3:26:44we are not building like an operative
  6061. 3:26:46system. We are not building an interface
  6062. 3:26:48in order to show the descriptions of the
  6063. 3:26:50products. We are building analytics and
  6064. 3:26:52reports. And in most cases, we don't go
  6065. 3:26:54and use product descriptions and long
  6066. 3:26:56text in the visuals. But of course in
  6067. 3:26:58the other hand I saw a lot of people
  6068. 3:27:00that are using PowerBI in order to build
  6069. 3:27:02some kind of application let's say to
  6070. 3:27:04see all the data. Well there's like some
  6071. 3:27:06projects that are misusing PowerBI in
  6072. 3:27:08order to build interfaces but not BI
  6073. 3:27:11right. So in most cases I refuse to have
  6074. 3:27:13such informations inside the data model.
  6075. 3:27:16That means we go and drop it. So remove
  6076. 3:27:19now same thing we have here hash key the
  6077. 3:27:20source ID all those informations came as
  6078. 3:27:23garbage let's say from the source system
  6079. 3:27:25and we don't need it here. Of course,
  6080. 3:27:26there are maybe very important
  6081. 3:27:27informations in the source systems, but
  6082. 3:27:29here we don't need it. So, let's go and
  6083. 3:27:31remove it. Now, here we have our
  6084. 3:27:32category and the product ID. Now, before
  6085. 3:27:34we start like renaming everything, I
  6086. 3:27:36would like to go and sort the columns.
  6087. 3:27:38So, I would like to see the product key
  6088. 3:27:40at the start as like primary key and the
  6089. 3:27:42category. I would like to have it side
  6090. 3:27:44by side with the subcategory. Well, I'm
  6091. 3:27:46going to say subcategory and then
  6092. 3:27:48category. So, that like we have
  6093. 3:27:50hierarchy, right? The product then
  6094. 3:27:52subcategory and then category. I like to
  6095. 3:27:55have things ordered so it makes sense as
  6096. 3:27:56you are building visuals and reports.
  6097. 3:27:58And now I'm going to say we have all
  6098. 3:28:00useful informations and we can go now
  6099. 3:28:02and start renaming things again. I'm
  6100. 3:28:04going to do it now offline in order not
  6101. 3:28:05to waste time. So see you soon.
  6102. 3:28:10All right. So this is the last column
  6103. 3:28:12and with that we are following now the
  6104. 3:28:13same naming convention. Sometimes I
  6105. 3:28:15remove few things like for example the
  6106. 3:28:17subcategory name. I call it now
  6107. 3:28:19subcategory. So there is no need for the
  6108. 3:28:21name inside the column name. Now there
  6109. 3:28:24is one more thing by looking to the
  6110. 3:28:26values you can see that the subcategory
  6111. 3:28:27is actually capitalized. Same thing for
  6112. 3:28:29the product name only the category is
  6113. 3:28:32everything here lowercased and this of
  6114. 3:28:33course because it comes from another
  6115. 3:28:35table where everything is lowercased. So
  6116. 3:28:37now in order to like to bring standards
  6117. 3:28:39to the values I'm going to go and apply
  6118. 3:28:40the same function. So transform and
  6119. 3:28:43capitalize each word. So now things
  6120. 3:28:45looks like more harmonized everything
  6121. 3:28:47capitalized and maybe we can add it as a
  6122. 3:28:49rule inside our project where we say all
  6123. 3:28:51the text values inside our data model is
  6124. 3:28:53capitalized so that people once they
  6125. 3:28:55start building reports they don't have
  6126. 3:28:57to go back to the data model and start
  6127. 3:28:59like adding more functions and
  6128. 3:29:00transformations. All right so now we
  6129. 3:29:02have really nice dimension as well. The
  6130. 3:29:04last step that we're going to do we will
  6131. 3:29:05just go and deactivate the row tables.
  6132. 3:29:08So the products we will go and
  6133. 3:29:09deactivate it. Yes. Same thing for the
  6134. 3:29:12subcategory as well. It is deactivated.
  6135. 3:29:14All right. So, we are done. Let's go and
  6136. 3:29:16make sure that we save and apply. All
  6137. 3:29:18right. Now, this is our new dimension
  6138. 3:29:21over here. Let me just zoom in. We're
  6139. 3:29:22going to go and remove the
  6140. 3:29:24relationships. We don't need them. And
  6141. 3:29:25for this as well. So, now look at this.
  6142. 3:29:28Now, we have clean two dimensions are
  6143. 3:29:30waiting here on the side. And our
  6144. 3:29:32original data model is getting cleaned
  6145. 3:29:34up step by step.
  6146. 3:29:39Okay. So, now what is next? What we
  6147. 3:29:41going to do? Do we have like a third
  6148. 3:29:42dimension that we're going to go and
  6149. 3:29:43build? Of course, there will be a lot of
  6150. 3:29:45dimensions, but here we have like
  6151. 3:29:46something that we have to decide on.
  6152. 3:29:48Now, the products and the customers,
  6153. 3:29:50they were like standalone and very
  6154. 3:29:52obvious dimensions where we had like a
  6155. 3:29:55master table for them. So, we have like
  6156. 3:29:57table products and another table called
  6157. 3:29:58the customer master. So, that's why it
  6158. 3:30:00was really easy to make those dimensions
  6159. 3:30:03out of those row tables. But now the
  6160. 3:30:05thing is in all other tables that are
  6161. 3:30:07remaining in the data model, most of
  6162. 3:30:09them are events. So we don't have like a
  6163. 3:30:11master table for the third dimension.
  6164. 3:30:13Actually most of the dimensions going to
  6165. 3:30:15get like extracted out of the event. As
  6166. 3:30:17we said before in many facts there are
  6167. 3:30:19always like hidden sneaky dimensions
  6168. 3:30:21that we extract out of it. This is
  6169. 3:30:23exactly now the scenario because of this
  6170. 3:30:25now we have like two ways on how to
  6171. 3:30:27continue. Either you're going to go
  6172. 3:30:28through all the events one by one and
  6173. 3:30:30start like extracting all the dimensions
  6174. 3:30:32and once you are done once you have all
  6175. 3:30:34the dimensions then you start building
  6176. 3:30:36the facts or the other way that I prefer
  6177. 3:30:39that at the same time we take like one
  6178. 3:30:41event table and we split it into fact
  6179. 3:30:44and dimensions. So at the same time we
  6180. 3:30:46are building the fact and the dimensions
  6181. 3:30:48out of the row tables and we don't have
  6182. 3:30:50like to redisuss it and brainstorm it
  6183. 3:30:52again. So either you go all the way by
  6184. 3:30:54extracting all the dimensions and only
  6185. 3:30:57after that you build the facts or at the
  6186. 3:30:59same time you are building the
  6187. 3:31:00dimensions and facts. Well I tend to the
  6188. 3:31:03second option. So now let's go and do
  6189. 3:31:04that. All right. So now by looking back
  6190. 3:31:06to our data model we have actually a lot
  6191. 3:31:08of events. So we have the orders and
  6192. 3:31:09sales, we have the invoices, the
  6193. 3:31:12payments, the campaigns and of course
  6194. 3:31:14it's going to be really hard to think of
  6195. 3:31:16everything at the same time. That's why
  6196. 3:31:18we have to go and pick one event, go
  6197. 3:31:20deep inside it and start splitting it
  6198. 3:31:22into facts and dimensions. So that means
  6199. 3:31:24we have to go and pick an event. I'm
  6200. 3:31:25going to say we're going to start with
  6201. 3:31:27the orders and sales. This is the most
  6202. 3:31:29important one and I think this is a
  6203. 3:31:30little bit complicated. So now let's go
  6204. 3:31:32and collect all the related tables like
  6205. 3:31:34we have done in the dimensions together
  6206. 3:31:36in one place. So we have the orders 2026
  6207. 3:31:39and as well we have the same table for
  6208. 3:31:41the 2025. What else do we have? We have
  6209. 3:31:43as well the lines for the orders. So
  6210. 3:31:45this one over here, the sales target is
  6211. 3:31:48going to be the budget. So I'm going to
  6212. 3:31:49say it's not really same event. It is
  6213. 3:31:52like the planned budget for each month.
  6214. 3:31:54We're going to think about it. Maybe
  6215. 3:31:55we're going to consider it. So I'm going
  6216. 3:31:56to say this is more than enough. We have
  6217. 3:31:58a lot of things. We have the orders and
  6218. 3:31:59the lines. And here we have to have full
  6219. 3:32:01focus because we start talking about
  6220. 3:32:02facts. Facts are very sensitive topic.
  6221. 3:32:05So again we're going to go to the Power
  6222. 3:32:07Query. Let's go inside. Now the first
  6223. 3:32:08thing before we start touching anything,
  6224. 3:32:10let's have some understanding more about
  6225. 3:32:12our tables. So let's start with those
  6226. 3:32:14two orders. So 2025 and 2026. Now again
  6227. 3:32:17I'm going to ask the question of the
  6228. 3:32:18grain what each row is representing.
  6229. 3:32:21Well you can see over here each row is
  6230. 3:32:23actually one complete order. So we have
  6231. 3:32:25all the informations about the orders.
  6232. 3:32:27We have the customer name, city, region
  6233. 3:32:29looks like dimension, right? But of
  6234. 3:32:31course we have here the events, the
  6235. 3:32:32order date, the channel of the order,
  6236. 3:32:34the status, priority, total sales for
  6237. 3:32:37the order and some big notes. Now let's
  6238. 3:32:39go to the other table. The orders 2025.
  6239. 3:32:42This is very identical table. Also
  6240. 3:32:44actually here we have a split from the
  6241. 3:32:45source system. Here as well we have the
  6242. 3:32:47same grain. Each row is actually one
  6243. 3:32:49order but again the source system is
  6244. 3:32:51splitting the data maybe for some
  6245. 3:32:53reasons like archive and so on. And of
  6246. 3:32:55course we have to do something about it.
  6247. 3:32:56We cannot leave it splitted like this.
  6248. 3:32:58It just confused the data model. Now
  6249. 3:33:00let's go to the third one the order line
  6250. 3:33:02items. So now again the same question.
  6251. 3:33:04What each row here is representing? Well
  6252. 3:33:06I'm going to say each row is actually a
  6253. 3:33:08line of order. So one line is not the
  6254. 3:33:11whole order like we had it in the other
  6255. 3:33:12tables. It is one position about the
  6256. 3:33:15order and of course we can go and check
  6257. 3:33:16that by aggregating the order ID. So
  6258. 3:33:19let's just group by and say okay this is
  6259. 3:33:21the count of rows. Well by looking at
  6260. 3:33:23this you can see here we have a lot of
  6261. 3:33:24duplicates. That means for each order we
  6262. 3:33:27might have like multiple lines like here
  6263. 3:33:29for the first order we have three lines.
  6264. 3:33:31All right. So I will just go and remove
  6265. 3:33:32it. We are just testing here. So that
  6266. 3:33:34means this has like more details another
  6267. 3:33:37grain than the orders. Now my friends
  6268. 3:33:39here we have like a very classical
  6269. 3:33:41scenario with the order lines and the
  6270. 3:33:43orders. This is something that we call
  6271. 3:33:45from the transactional systems from the
  6272. 3:33:47sources the headers and the details. All
  6273. 3:33:49right friends now I can say we come to
  6274. 3:33:51the most complicated and confusing part
  6275. 3:33:54in the whole data modeling project.
  6276. 3:33:56That's why if you don't have cave yet go
  6277. 3:33:57and grab one.
  6278. 3:34:02Okay. So now we're going to talk about
  6279. 3:34:04the header and the details. This is very
  6280. 3:34:06tricky and confusing part where a lot of
  6281. 3:34:08people make mistakes in the data
  6282. 3:34:10modeling for reporting and analytics but
  6283. 3:34:12yet one of the best practices and the
  6284. 3:34:14common way on how to store transactions
  6285. 3:34:17in OLTB sources. So it is a very common
  6286. 3:34:20way on how to module the sources and
  6287. 3:34:22you're going to find it a lot in many
  6288. 3:34:24companies. So my friends, if you
  6289. 3:34:25understand this concept and you know how
  6290. 3:34:27to deal with it in the data modeling for
  6291. 3:34:29business intelligence and analytics,
  6292. 3:34:31then my friends, your life going to be
  6293. 3:34:32really easy working at companies because
  6294. 3:34:35you're going to face this data model
  6295. 3:34:36over and over. So now in order to
  6296. 3:34:38understand this, let's start with very
  6297. 3:34:40simple example. I don't know, look
  6298. 3:34:41around you. Maybe you find an order or
  6299. 3:34:43an invoice.
  6300. 3:34:44>> I found it. If not, go and check online
  6301. 3:34:46your stuff. So now here I have an order.
  6302. 3:34:48And if I look at this, this is one
  6303. 3:34:51business event. I have done an order.
  6304. 3:34:53And this business event actually has
  6305. 3:34:55like two sections a header and details.
  6306. 3:34:57The header it is like the top level
  6307. 3:34:59informations in the order. Like for
  6308. 3:35:01example I have the address, the
  6309. 3:35:03customer, the company, the order number,
  6310. 3:35:05the order state, the order dates. So all
  6311. 3:35:07those informations we have it like only
  6312. 3:35:09once for each order right and those are
  6313. 3:35:12my friends the header. Now if you look
  6314. 3:35:13below it depends if you ordered multiple
  6315. 3:35:15things you're going to find like a table
  6316. 3:35:17with more details. Like for example,
  6317. 3:35:18you're going to find the list of all
  6318. 3:35:20products that you have ordered in this
  6319. 3:35:22one order and other things like the
  6320. 3:35:23quantity, the price and as well the
  6321. 3:35:25final costs. And my friends, this setup,
  6322. 3:35:28the header and the details, you're going
  6323. 3:35:29to find it in many events in many
  6324. 3:35:31companies. So you're going to find it in
  6325. 3:35:33orders, in invoices, in shipment, in
  6326. 3:35:35delivery. Even in manufacturing, you're
  6327. 3:35:37going to have the bill of materials, the
  6328. 3:35:38production order, or if you have like
  6329. 3:35:40ticketing system, you're going to find
  6330. 3:35:42it as well in tickets. all those
  6331. 3:35:43transactions and many systems going to
  6332. 3:35:45store those informations into header and
  6333. 3:35:48details. Now of course the big question
  6334. 3:35:49is how we going to deal with those stuff
  6335. 3:35:51inside our data model for business
  6336. 3:35:53intelligence. Now one of the biggest
  6337. 3:35:54mistake that people do is that they look
  6338. 3:35:56at the header and details as two
  6339. 3:35:58different things. So they say okay the
  6340. 3:36:00header looks like a fact. So they go and
  6341. 3:36:02make like for example fact orders and
  6342. 3:36:04they see okay the details as well looks
  6343. 3:36:06as fact but this is like different
  6344. 3:36:09grains. That's why they're going to go
  6345. 3:36:10and make another fact for that. the fact
  6346. 3:36:13order line. So they make out all of this
  6347. 3:36:15like two facts. And now of course in
  6348. 3:36:16reporting you're going to need those two
  6349. 3:36:18tables in one visual in one report. So
  6350. 3:36:21that means they need two data from the
  6351. 3:36:23facts. And here people come in this trap
  6352. 3:36:25where they're going to say okay well
  6353. 3:36:27actually we have the order key in the
  6354. 3:36:29header and the details. This is actually
  6355. 3:36:30what happens in transaction systems.
  6356. 3:36:32They link the order with the header
  6357. 3:36:34using the key. And they're going to say
  6358. 3:36:36okay this is a perfect match. This is
  6359. 3:36:37the common column. I'm going to go and
  6360. 3:36:39connect those two facts together. Well,
  6361. 3:36:41yes, this might work, but this can
  6362. 3:36:42introduce only issues in the reporting.
  6363. 3:36:45This has first of all, bad performance,
  6364. 3:36:47can lead to bad numbers and as well this
  6365. 3:36:49is very confusing once you are building
  6366. 3:36:51the reports. So, this is one of the
  6367. 3:36:53biggest mistakes that people do in data
  6368. 3:36:54modeling. And now, of course, the
  6369. 3:36:56question is how we going to do it? How
  6370. 3:36:58we going to model this? Well, the rule
  6371. 3:37:00is always the same. The fact table going
  6372. 3:37:02to sit always at the level of things
  6373. 3:37:04that you are measuring. So, ask yourself
  6374. 3:37:06where the numbers come from. So if you
  6375. 3:37:07look to the header and the details
  6376. 3:37:09you're going to see that actually all
  6377. 3:37:10the numbers are stored in the details.
  6378. 3:37:12The header is just like giving us some
  6379. 3:37:14context and maybe like maximum one or
  6380. 3:37:17two numbers but the core numbers the
  6381. 3:37:19core measures are in the details. So
  6382. 3:37:21that means it is always better to build
  6383. 3:37:23a fact table that comes from the finest
  6384. 3:37:26details from the lowest level because my
  6385. 3:37:29friend we can always roll up and
  6386. 3:37:30aggregate the data pack to the header.
  6387. 3:37:32So that means in most cases we're going
  6388. 3:37:34to go and create the core fact table
  6389. 3:37:37from the details and we're going to the
  6390. 3:37:39header in order to get more context for
  6391. 3:37:42our new facts. So either we're going to
  6392. 3:37:44use it in order to generate a new
  6393. 3:37:45dimensions from the header or we're
  6394. 3:37:47going to use it as well to connect the
  6395. 3:37:49data model to our new fact from the
  6396. 3:37:52details. So this is the very common
  6397. 3:37:54pattern. We make fact from the details
  6398. 3:37:56and we use the help of the headers in
  6399. 3:37:58order to generate dimensions and to
  6400. 3:38:00connect it to our fact. And I can say
  6401. 3:38:02this going to work like 90% of the time.
  6402. 3:38:04Sometimes you have some edge cases where
  6403. 3:38:06people are storing a lot of numbers in
  6404. 3:38:08the headers. But in most cases this is
  6405. 3:38:10going to work if you follow this
  6406. 3:38:12pattern. Okay. So now with this I have
  6407. 3:38:13prepared you with the foundations. Now
  6408. 3:38:15let's go to PowerBI and try this out.
  6409. 3:38:17All right. So now what we're going to do
  6410. 3:38:18with those three tables I'm going to say
  6411. 3:38:19let's start with the easy and obvious
  6412. 3:38:21thing. We have to go and combine those
  6413. 3:38:23two orders into one single table. So
  6414. 3:38:25again if you have two tables have the
  6415. 3:38:27same grain and as well they are
  6416. 3:38:29identical. They have the same shape. we
  6417. 3:38:30go and append them. So how we going to
  6418. 3:38:32do it? It's going to be very simple.
  6419. 3:38:33We're going to go over here and say
  6420. 3:38:34append queries and I'm going to go and
  6421. 3:38:36create a new one so that we don't lose
  6422. 3:38:38let's say the row tables. So now here it
  6423. 3:38:40says two tables and the first table. I'm
  6424. 3:38:42going to start with the oldest. So first
  6425. 3:38:442025 and then 2026. All right. Let's hit
  6426. 3:38:47okay. So now we have a new table over
  6427. 3:38:49here. Let's go and rename it. So this
  6428. 3:38:51going to be the orders. Now of course
  6429. 3:38:52this going to be like an intermediate
  6430. 3:38:54table. We don't have like fact and
  6431. 3:38:55dimension. We are just like merging
  6432. 3:38:57things. Of course, if you want, you can
  6433. 3:38:59go and make another order for all the
  6434. 3:39:01temporary things, but I'm going to leave
  6435. 3:39:03it now in this stage. Now, of course, we
  6436. 3:39:04are not done. Let's have a look to the
  6437. 3:39:06append whether we have any strange
  6438. 3:39:08things here. We have some nulls and if I
  6439. 3:39:10go over here, the source file has as
  6440. 3:39:13well some nulls. So, actually there is
  6441. 3:39:15like something wrong and as well the
  6442. 3:39:17legacy reference. So, that means they
  6443. 3:39:19are not completely identical. Let's have
  6444. 3:39:21a look again. We have here the legacy
  6445. 3:39:22reference and in 2026 we don't have it.
  6446. 3:39:25So actually with the new orders we don't
  6447. 3:39:27have this legacy column. So let's go a
  6448. 3:39:29and remove it. It says as well legacy.
  6449. 3:39:31So I think we don't need it for
  6450. 3:39:32reporting. And let's go and check the
  6451. 3:39:34resource file. So over here we have it
  6452. 3:39:36in 2025 but we don't have it I think for
  6453. 3:39:392026. So again it is a legacy thing. We
  6454. 3:39:42go and remove it from our new table. So
  6455. 3:39:45you go out remove. Now here we have a
  6456. 3:39:48lot of nulls. The gift message. If I go
  6457. 3:39:50over here you can see actually we don't
  6458. 3:39:52have any value. This is garbage column.
  6459. 3:39:54So it is just taking space. Let's go and
  6460. 3:39:56remove it as well. So as you can see, we
  6461. 3:39:57are cleaning up. And since we are
  6462. 3:39:59talking about cleaning, we have here the
  6463. 3:40:00order notes as well those big text. Come
  6464. 3:40:02on, we don't need those stuff in
  6465. 3:40:04analytics and reporting. So I'm going to
  6466. 3:40:06go and remove it as well. So I think now
  6467. 3:40:08we have like complete match between
  6468. 3:40:10those two tables. We don't have any more
  6469. 3:40:12nulls. So they are completely identical.
  6470. 3:40:15Of course you might say but we lost an
  6471. 3:40:17information which record come from which
  6472. 3:40:19table. So the 2025 and 2026. Well,
  6473. 3:40:22actually we don't need this information.
  6474. 3:40:23We have it already in the order date. So
  6475. 3:40:25it will be just like an extra
  6476. 3:40:27information that we have already. But if
  6477. 3:40:28it was like another information like the
  6478. 3:40:30country or something. I would go and add
  6479. 3:40:32the source. All right. So now again our
  6480. 3:40:34orders is the header information. As you
  6481. 3:40:36can see we have here a lot of context
  6482. 3:40:38for each order. So very good candidates
  6483. 3:40:40for dimensions and the order line items.
  6484. 3:40:43Here we have all the numbers. So this is
  6485. 3:40:46the detail table for the orders. And
  6486. 3:40:48this means my friends this going to be
  6487. 3:40:50our core fact table for the topic sales
  6488. 3:40:52and orders. So now where we're going to
  6489. 3:40:54start either we create the fact table
  6490. 3:40:56now or we start extracting the
  6491. 3:40:58dimensions from the orders. I'm going to
  6492. 3:41:00say let's go to the orders and start
  6493. 3:41:01like creating new dimensions. So what do
  6494. 3:41:03we have here? We have the customer name
  6495. 3:41:05the customer city. Well we don't create
  6496. 3:41:07now another dimension called customers.
  6497. 3:41:09So we're going to leave it like here.
  6498. 3:41:10Same thing for the region. Those cities
  6499. 3:41:12going to stay over here. The date as
  6500. 3:41:14well. Now here we have something
  6501. 3:41:16interesting. We have the order channel
  6502. 3:41:18where we have like some numbers. Those
  6503. 3:41:20are technical ids. They are not
  6504. 3:41:21something that we're going to use in
  6505. 3:41:22order to aggregate. We have as well
  6506. 3:41:24status and priority. All three
  6507. 3:41:26informations are actually good
  6508. 3:41:27candidates for dimensions because we can
  6509. 3:41:29use them in order like to filter and
  6510. 3:41:31slice. Now, of course, the question is
  6511. 3:41:32what is the topic? Are they like related
  6512. 3:41:34to each others? Could we make like one
  6513. 3:41:36dimensions out of this? Well, they are
  6514. 3:41:38actually not related to each other. You
  6515. 3:41:39can see here the order channel, the
  6516. 3:41:41status, the priority. They are just like
  6517. 3:41:43confirmations for the order but they are
  6518. 3:41:45not like connected together in order to
  6519. 3:41:47make like good dimension. And of course
  6520. 3:41:49we will not go and make like one
  6521. 3:41:50dimensions for each column. This is not
  6522. 3:41:52good in this scenario. What we're going
  6523. 3:41:53to do my friends, we're going to build
  6524. 3:41:54the junk dimension. We're going to put
  6525. 3:41:56them all together in one and then
  6526. 3:41:58reference it back in the fact table
  6527. 3:42:00later. So how we going to build a junk
  6528. 3:42:01dimension? We're going to go and make
  6529. 3:42:03another reference out of this. So we're
  6530. 3:42:05going to say reference and this going to
  6531. 3:42:06be a dimension. So I'm going to drag and
  6532. 3:42:08drop it to the dimensions. Let me just
  6533. 3:42:10minimize this. All right. So right click
  6534. 3:42:12on it, rename. Well, I'm not going to
  6535. 3:42:14call it again junk. So this going to be
  6536. 3:42:16the order flags. Maybe you're going to
  6537. 3:42:18have another junk from another events.
  6538. 3:42:20That's why we will not make it like a
  6539. 3:42:22super generic. Now how we build this?
  6540. 3:42:24It's very simple. We're going to go and
  6541. 3:42:25remove all the unnecessary stuff and say
  6542. 3:42:27okay, remove. We don't need the order
  6543. 3:42:29total. This is a number. We don't need
  6544. 3:42:31it for dimension. Now the last thing
  6545. 3:42:32what we're going to do, we're going to
  6546. 3:42:33go and remove all the duplicates from
  6547. 3:42:35all three. So select all and say remove
  6548. 3:42:37duplicates. Very nice. We have only 14
  6549. 3:42:39rows. Now, of course, what is missing?
  6550. 3:42:41We need like a key for this dimension.
  6551. 3:42:43So, we're going to go and add a column,
  6552. 3:42:44an index column that starts from one.
  6553. 3:42:47Then we're going to call it so rename
  6554. 3:42:49the flag key because this is a surrogate
  6555. 3:42:52key. We just created this in our model
  6556. 3:42:55and go to the top. Okay. So, this looks
  6557. 3:42:57already good. Now, we are not done yet.
  6558. 3:42:59There is something that I really don't
  6559. 3:43:01like those order channels. So, as you
  6560. 3:43:03can see those numbers now, this can
  6561. 3:43:05confuse a lot. If you just bring it to
  6562. 3:43:06the reporting, people might go and
  6563. 3:43:08aggregate or find an average of this.
  6564. 3:43:10Those are ID for something that we don't
  6565. 3:43:13know and we cannot leave it like this.
  6566. 3:43:15We have to make something meaningful of
  6567. 3:43:16this. So now at work in order to
  6568. 3:43:18understand what those numbers are, we
  6569. 3:43:20actually go and read documentations or
  6570. 3:43:22ask the people responsible for the
  6571. 3:43:23source system. Maybe ask an expert from
  6572. 3:43:25the business or from the processes. So
  6573. 3:43:27at the end you have to find the mapping
  6574. 3:43:29between those numbers and the real
  6575. 3:43:31values so that we can show it in the
  6576. 3:43:33reports. Now let's say that I got it
  6577. 3:43:34from somewhere those informations. Now
  6578. 3:43:36the question is how we going to add it
  6579. 3:43:38to this data model because those
  6580. 3:43:39informations are not coming from the
  6581. 3:43:41source. From the source we are getting
  6582. 3:43:42only those ids. So that means this is
  6583. 3:43:44new information that I'm adding to this
  6584. 3:43:46data model and it doesn't exist from the
  6585. 3:43:49sources. And how we can do that my
  6586. 3:43:51friends we go and add a data inside our
  6587. 3:43:53data model by going to the home rippon
  6588. 3:43:56and say enter data. So this is going to
  6589. 3:43:58be very simple. We are just creating a
  6590. 3:43:59table from scratch like an Excel. So the
  6591. 3:44:02first column going to be the channel
  6592. 3:44:03code and we need another one where we
  6593. 3:44:06have the full name. So the channel name.
  6594. 3:44:10Okay. So it is just like mapping between
  6595. 3:44:12code and the name. So we make sure that
  6596. 3:44:14we cover everything from our data. We
  6597. 3:44:16have the 10 and this stands for online
  6598. 3:44:19store. Then we have 20. This is the
  6599. 3:44:22retail partner. Then the 30 this is the
  6600. 3:44:26channel of wholesale. And 40 is a filled
  6601. 3:44:30sale. So we make sure that we have
  6602. 3:44:32covered everything. So we have here
  6603. 3:44:33actually only four. Okay. So this is the
  6604. 3:44:35translation the mapping between the
  6605. 3:44:37cryptical code and the friendly name.
  6606. 3:44:40All right. So now let's go and hit okay.
  6607. 3:44:42Well now I have it here as a table. So
  6608. 3:44:43I'm going to go and rename it channels
  6609. 3:44:46and then maybe bring it back to the
  6610. 3:44:48stage because this is something like
  6611. 3:44:49intermediate, right? So now what we're
  6612. 3:44:51going to do, we're going to go back to
  6613. 3:44:52our order flags and we have to replace
  6614. 3:44:54those numbers with the new values. And
  6615. 3:44:56we can do that by merging queries. So
  6616. 3:44:58let's go and find our new table
  6617. 3:45:00channels. All right. So this is the key
  6618. 3:45:02and left join. So let's hit okay. All
  6619. 3:45:04right. Okay. So let's go and expand.
  6620. 3:45:07Remove the code. We just need the name.
  6621. 3:45:09And I'm going to move it over here. Of
  6622. 3:45:11course you can now decide whether you're
  6623. 3:45:12going to leave the code together with
  6624. 3:45:14the name. But I'm going to say actually
  6625. 3:45:16the codes are just like confusing. So
  6626. 3:45:19I'm going to go and remove it. So now my
  6627. 3:45:20friends this is what we call data
  6628. 3:45:22enhancement, data enrichment. And this
  6629. 3:45:24is very typical things that we do in
  6630. 3:45:26data modeling because in source systems
  6631. 3:45:28we're going to get a lot of cryptical
  6632. 3:45:30things that we cannot just go and
  6633. 3:45:32present it in the reports. So we have to
  6634. 3:45:34add from our site something new to the
  6635. 3:45:36data model and with this comes a really
  6636. 3:45:38great responsibility because this is
  6637. 3:45:40very typical what could happen that
  6638. 3:45:42initially going to go and start mapping
  6639. 3:45:44everything manually. So everything looks
  6640. 3:45:45perfect but now suddenly the source
  6641. 3:45:47systems are generating let's say new ids
  6642. 3:45:49new values that we didn't map yet. So a
  6643. 3:45:52typical problem happens that initially
  6644. 3:45:54we do things correct but afterward we
  6645. 3:45:56forget about it or maybe we just go and
  6646. 3:45:58switch to another project and your
  6647. 3:46:00reports can show only nulls over the
  6648. 3:46:02time because we don't have values for
  6649. 3:46:04that. So adding data manually from us
  6650. 3:46:07the humans to the data model it is
  6651. 3:46:09something critical and we have to be
  6652. 3:46:10careful for it. So if you go to another
  6653. 3:46:13project and you hand this data model to
  6654. 3:46:15someone else, make sure to inform them
  6655. 3:46:16that they have to check from the source
  6656. 3:46:18systems. If there is something new, they
  6657. 3:46:19have to go and extend this manual data
  6658. 3:46:22that we added to the data model or what
  6659. 3:46:24is way better and perfect. If you say,
  6660. 3:46:26you know what, this mapping should
  6661. 3:46:28happen in the source system and you are
  6662. 3:46:30responsible for it and provide it with
  6663. 3:46:32all other files. This is of course the
  6664. 3:46:34best option because then we don't have
  6665. 3:46:36any more the responsibility to touch the
  6666. 3:46:38data inside the data model. everything
  6667. 3:46:40going to be like fully automated. Okay.
  6668. 3:46:42So now back to our junk dimension. The
  6669. 3:46:44last step is just to polish. So that
  6670. 3:46:46mean we will just rename things the
  6671. 3:46:48channel and here we have a status. So
  6672. 3:46:50only the S and the priority.
  6673. 3:46:54Okay. So our junk dimension is ready to
  6674. 3:46:57go. Now let's go back to our orders.
  6675. 3:46:59Let's see. Okay. Again we say those
  6676. 3:47:01information is going to stay and that
  6677. 3:47:02means we just extracted one dimension
  6678. 3:47:04out of the order which is totally okay.
  6679. 3:47:07Now let's start with our fact. This is
  6680. 3:47:08going to be really interesting. Let's go
  6681. 3:47:10to the order line. This has the lowest
  6682. 3:47:12details. It makes sense. So, let's go
  6683. 3:47:14first and make a reference out of it.
  6684. 3:47:17This is going to be our first fact
  6685. 3:47:18inside the data model. Let me just uh
  6686. 3:47:20minimize all those stuff. And then let's
  6687. 3:47:23go and give it a name. I'm going to call
  6688. 3:47:24it the fact sales. All right. So, this
  6689. 3:47:27is the foundations for our fact. We have
  6690. 3:47:29enough numbers inside it. But now the
  6691. 3:47:31thing is we need the dimensions. So, we
  6692. 3:47:34have already here the product name, but
  6693. 3:47:35we need the customers. We need the junk
  6694. 3:47:37dimension. We need the order date. So we
  6695. 3:47:40need all those stuff from the header to
  6696. 3:47:42be included as well in our new facts. So
  6697. 3:47:44that means now we're going to start like
  6698. 3:47:46combining things to our new fact. And
  6699. 3:47:48here you have to be very very careful.
  6700. 3:47:49If you do one wrong merge, you're going
  6701. 3:47:51to destroy the whole facts. So now we
  6702. 3:47:53come to the rule that we have to protect
  6703. 3:47:55our numbers. So that means any changes
  6704. 3:47:57that we do to the fact table, we still
  6705. 3:47:59have to see the same numbers. And if we
  6706. 3:48:02see something else, we have of course to
  6707. 3:48:03fix before merging it to our fact. So
  6708. 3:48:06now let's try this out. and I'm going to
  6709. 3:48:08show you how I usually do it. Now, of
  6710. 3:48:09course, I will not go and start like
  6711. 3:48:11scrolling down because usually the event
  6712. 3:48:13tables are really big. So, instead I'm
  6713. 3:48:15going to go and close and apply. So,
  6714. 3:48:16just save it. All right. So, I think
  6715. 3:48:18somewhere is our new facts. But we don't
  6716. 3:48:20deal now with the data model. Let's go
  6717. 3:48:22to the report view. And now we're going
  6718. 3:48:24to go and pick like one important
  6719. 3:48:25measure from our fact in order to keep
  6720. 3:48:28tracking it for each change. So if I go
  6721. 3:48:30to the fact sales over here, we have
  6722. 3:48:32here some options like for example the
  6723. 3:48:34line total, the quantity, the cost, the
  6724. 3:48:36price. I'm going to go with the main
  6725. 3:48:38measure, this going to be the line
  6726. 3:48:40total. So let's drag and drop it to our
  6727. 3:48:42card. So my friends, this is the number
  6728. 3:48:44and we have to protect this. Anything
  6729. 3:48:46that we combine, we add to this fact
  6730. 3:48:49table, it always should result exactly
  6731. 3:48:51to this same number. If something
  6732. 3:48:52change, then we have an issue. So we
  6733. 3:48:55have to know this number by heart until
  6734. 3:48:57the end of the project. This number
  6735. 3:48:59should be correct. Okay. So now we have
  6736. 3:49:01the number. Now let's go back to power
  6737. 3:49:03query and start adding things. So back
  6738. 3:49:05to the fact sales. Now what we're going
  6739. 3:49:07to do in order to bring the other
  6740. 3:49:09dimensions to our facts, we're going to
  6741. 3:49:11go and add the header. So we do that by
  6742. 3:49:14doing a merge query. We're going to go
  6743. 3:49:15to the orders that we have prepared. It
  6744. 3:49:18is over here. And how we going to
  6745. 3:49:19combine it? By the order ID. And of
  6746. 3:49:21course very important the left outer
  6747. 3:49:23join. Okay. Now of course we have to
  6748. 3:49:25expand. And here we have a lot of
  6749. 3:49:27things. I will not now judge everything.
  6750. 3:49:29I'm just going to go and remove the
  6751. 3:49:30order ID that we just used because we
  6752. 3:49:32have it already. And let's go and add
  6753. 3:49:34all the things. We can always remove
  6754. 3:49:36later. So now we have everything from
  6755. 3:49:38the header, the order. And of course,
  6756. 3:49:40now the big question is, do we have any
  6757. 3:49:42changes for the numbers? So let's go and
  6758. 3:49:44close and apply and wait second until
  6759. 3:49:46it's loaded. So keep focusing on the
  6760. 3:49:48number. Any changes? Well, nothing
  6761. 3:49:51changed. This is perfect. We still have
  6762. 3:49:53the total sales. Of course, there are
  6763. 3:49:54like different methods on how to test.
  6764. 3:49:56Like for example, you can go and build
  6765. 3:49:57the relationship between them and see
  6766. 3:49:59whether it is one to many. So you can do
  6767. 3:50:01like different ways of testing before
  6768. 3:50:03merging. This is one of them. So that
  6769. 3:50:05was successful. Now let's go back to the
  6770. 3:50:07power query. Let's go back to the fact
  6771. 3:50:09sales. Okay. So with this we have done
  6772. 3:50:11the big merge between the details and
  6773. 3:50:12the sales safely. And now we can go to
  6774. 3:50:15the next steps. Like for example, we
  6775. 3:50:16have to go and build the keys inside the
  6776. 3:50:19fact. You know each fact has a lot of
  6777. 3:50:20keys in order to connect things to the
  6778. 3:50:22dimensions. And our fact is not ready
  6779. 3:50:25yet. So now instead of having the
  6780. 3:50:26product names, we're going to go and
  6781. 3:50:28have the product key. Same thing for the
  6782. 3:50:30customer. So let's do that. Let's bring
  6783. 3:50:32the ids and the keys and we can start
  6784. 3:50:33with the customer. Now what we going to
  6785. 3:50:35do, we call it something like lookup. So
  6786. 3:50:37that means I'm going to go and merge
  6787. 3:50:39this to the dimension only to get the
  6788. 3:50:41ids. And again, since we are merging, we
  6789. 3:50:43have to be very careful. So we're going
  6790. 3:50:45to go and merge a query again, but this
  6791. 3:50:47time we are merging with the dimensions.
  6792. 3:50:49So we're going to go over here and find
  6793. 3:50:50the dimension customer. So now this is
  6794. 3:50:53our target to get the customer ID. But
  6795. 3:50:55of course we cannot now connect using
  6796. 3:50:57ids. We have to do something scary.
  6797. 3:50:58We're going to go and use the text the
  6798. 3:51:01customer name and this can open the door
  6799. 3:51:03for many mistakes. So we have really to
  6800. 3:51:05check after that. So customer name
  6801. 3:51:06customer name join. This is my friends a
  6802. 3:51:10lookup. So let's go and hit okay. Now
  6803. 3:51:12what we going to do? How we going to
  6804. 3:51:13expand? Of course we will not go and
  6805. 3:51:15bring now all the columns from the
  6806. 3:51:16dimension. We just want one thing the
  6807. 3:51:18customer ID. So this one we need and hit
  6808. 3:51:21okay. Okay. So now what I like to do
  6809. 3:51:22next is to just bring the ID on the
  6810. 3:51:25starts so that we have a real fact
  6811. 3:51:27table. So it's going to be somewhere
  6812. 3:51:28here. Now of course before we do
  6813. 3:51:30anything else we have to go and test. So
  6814. 3:51:32I'm going to go and close and apply and
  6815. 3:51:34keep my eye on this number.
  6816. 3:51:37Well nothing changed. That was a
  6817. 3:51:39successful merge between those two
  6818. 3:51:41tables and there is no risk about it.
  6819. 3:51:43Now let's go and do the same thing for
  6820. 3:51:45the products. So let's go back to the
  6821. 3:51:48fact sales. Same thing we have here the
  6822. 3:51:50product name. We need the product ID or
  6823. 3:51:52key. So merge. And now same thing. We're
  6824. 3:51:54going to go to that dimension product
  6825. 3:51:56over here. We join my friends using the
  6826. 3:51:59product name. So it's not the product
  6827. 3:52:00code which is really scary. So let's go
  6828. 3:52:03and hit okay. And we just need a lookup.
  6829. 3:52:05So that means we need the product key.
  6830. 3:52:07Perfect. So now let's go as well bring
  6831. 3:52:09it to the starts side by side with the
  6832. 3:52:11other keys somewhere here. Now before we
  6833. 3:52:13touch anything, we have to go and test.
  6834. 3:52:15Let's close and apply. Keep our eye on
  6835. 3:52:18the numbers. Did the numbers just
  6836. 3:52:19changed? Now we have way more total
  6837. 3:52:22sales than before. Oh no, that was not
  6838. 3:52:24successful merge with the products. We
  6839. 3:52:26have something wrong and we have to
  6840. 3:52:28protect the original number. So yeah, we
  6841. 3:52:30have to do something. So let's go back
  6842. 3:52:32to power query and see what is going on.
  6843. 3:52:34So let's go back to the fact sales.
  6844. 3:52:37Well, what we can do, we can go and
  6845. 3:52:39check up actually which order have an
  6846. 3:52:41issue. So if you select those two and
  6847. 3:52:43say okay, let's go and group by. I
  6848. 3:52:45imagine those two should be unique. So
  6849. 3:52:47let's go and count the rows for that. So
  6850. 3:52:49now we see a lot of ones but we see two
  6851. 3:52:52right. So here we have an issue. You can
  6852. 3:52:53see those orders are fanning out. So we
  6853. 3:52:56are getting like duplicates. And let's
  6854. 3:52:57go and check something like for example
  6855. 3:52:59the order number 25. And then go and
  6856. 3:53:01remove this test. So now what we going
  6857. 3:53:03to do? We're going to go and search for
  6858. 3:53:04this order. It was the 25. All right.
  6859. 3:53:07Look at this. We have the same order.
  6860. 3:53:09The product name is identical but they
  6861. 3:53:12have different keys which is really bad.
  6862. 3:53:14Of course, the rest going to be like
  6863. 3:53:16identical. It is getting like fanning
  6864. 3:53:18out. So, this product has an issue. The
  6865. 3:53:20same product name but different keys.
  6866. 3:53:22And this is a typical issue. If we are
  6867. 3:53:24joining using like names and text,
  6868. 3:53:26things can go quickly wrong. So, that
  6869. 3:53:29means we have to go and check the
  6870. 3:53:30dimension products. So, it was the
  6871. 3:53:32kitchen something, right? So, let's just
  6872. 3:53:35search for it. This is the first one.
  6873. 3:53:38And look at this. We have duplicates
  6874. 3:53:41actually inside the Damian products. So
  6875. 3:53:43we have different codes for the same
  6876. 3:53:45product and if you scroll to the right
  6877. 3:53:48side you can see one of them is actually
  6878. 3:53:50have more data than the other. So here
  6879. 3:53:52we have like brand and the other row
  6880. 3:53:54doesn't have brand. Same thing for the
  6881. 3:53:56price and the supplier. Of course this
  6882. 3:53:58is a data quality issue that came from
  6883. 3:54:00the source system and here we have like
  6884. 3:54:02two options. Either we're going to go to
  6885. 3:54:03the source system and tell them hey guys
  6886. 3:54:05you have like wrong stuff you have the
  6887. 3:54:06same product twice. Go and clean up the
  6888. 3:54:08data and then everything going to be
  6889. 3:54:10fine here. or you're going to go and
  6890. 3:54:11manually start removing things. But of
  6891. 3:54:14course, this is no guarantee that later
  6892. 3:54:16we will not get any like quality issues.
  6893. 3:54:18Now, if the source system don't want to
  6894. 3:54:20clean the data and they going to leave
  6895. 3:54:21it as it is, then either you're going to
  6896. 3:54:23go and now like clean things manually or
  6897. 3:54:25what is way better, we usually build
  6898. 3:54:26like a data warehouse where we build
  6899. 3:54:29pipelines and quality gates in order to
  6900. 3:54:31detect and fix those issues. But now for
  6901. 3:54:34this project, since we don't have like a
  6902. 3:54:35lot of products, we're going to go and
  6903. 3:54:36manually remove those bad rows. So here
  6904. 3:54:38we have to decide which version should
  6905. 3:54:40stay and of course it's going to be the
  6906. 3:54:42one with more infos. So that means with
  6907. 3:54:44the nulls should be dropped out of our
  6908. 3:54:47dimension. Now of course we have to
  6909. 3:54:48detect how many other like scenarios
  6910. 3:54:51like this. So I will just remove this
  6911. 3:54:52filter select all. Now how we going to
  6912. 3:54:55do it? We're going to go and just group
  6913. 3:54:56by the product names. So we're going to
  6914. 3:54:58go and say based on the product name go
  6915. 3:55:00and count the rows and change the filter
  6916. 3:55:03to two. You can see we have the issue
  6917. 3:55:05with two products the kitchen and the
  6918. 3:55:07audio. So it is not that a big deal what
  6919. 3:55:09we're going to do. We're going to go
  6920. 3:55:11remove this test. Of course, now the
  6921. 3:55:12question is how we going to remove those
  6922. 3:55:13two rows. I will not do it like as the
  6923. 3:55:15last step inside our dimension. I'm
  6924. 3:55:17going to go way back. Maybe at this step
  6925. 3:55:19filtering the rows as we removed the one
  6926. 3:55:22bad row where the product key is equal
  6927. 3:55:24to Z zed. Now of course the question is
  6928. 3:55:26where are those stuff? Well, it is the
  6929. 3:55:28last two rows. You can see here we don't
  6930. 3:55:30have brands for them. We don't have a
  6931. 3:55:32unit price. And now I remember we had
  6932. 3:55:34like a really nice column for the source
  6933. 3:55:36ID. So you can see here we have like a
  6934. 3:55:38source ID and row identifier for each
  6935. 3:55:40one of them and we can use it in order
  6936. 3:55:42to filter the data out. So this is one
  6937. 3:55:44bad ID. I'm going to go and copy the
  6938. 3:55:46value and then use it in order to filter
  6939. 3:55:48the data. So I will check this out. Same
  6940. 3:55:52thing for the last row. So I'm going to
  6941. 3:55:54go and copy this as well and as well use
  6942. 3:55:56it in order to filter the data out. All
  6943. 3:55:58right. So as you can see now in our
  6944. 3:56:00filter we have three things. We are
  6945. 3:56:02filtering the data based on the product
  6946. 3:56:04code and based on the source ID. So now
  6947. 3:56:07let's go and check again. We have to
  6948. 3:56:09group up the data by the product name.
  6949. 3:56:11So group by insert and product name. Now
  6950. 3:56:15let's check the filter. Yes, we have
  6951. 3:56:17only one. So that means my friends, our
  6952. 3:56:19product names are actually unique. But
  6953. 3:56:21be careful now to just remove the test.
  6954. 3:56:23All right. Now we go to the last step to
  6955. 3:56:26make sure that everything is working
  6956. 3:56:27correctly. Nice. So now let's go and
  6957. 3:56:29save and check again our numbers. So
  6958. 3:56:33come on. Come on. Yes, we got back our
  6959. 3:56:35number with that we protected the number
  6960. 3:56:37and the fact and it was successful merge
  6961. 3:56:40to the product. So we can now go and
  6962. 3:56:42continue. Let's go back to the power
  6963. 3:56:44query. So where is our fact table? So
  6964. 3:56:47with this now we got the two big
  6965. 3:56:48dimensions the product key, the customer
  6966. 3:56:51ID. Now what is left is actually the
  6967. 3:56:53junk, right? So we have those three
  6968. 3:56:55columns and we have to connect the junk
  6969. 3:56:57to it. Now I see already that we have an
  6970. 3:56:59issue for the lookup. We need all those
  6971. 3:57:01three in order to join it with the
  6972. 3:57:03dimension. But we just removed the order
  6973. 3:57:05channel, right? So if I go now and
  6974. 3:57:07merge, it will not work. That means I'm
  6975. 3:57:09going to take it back and going to go to
  6976. 3:57:11the junk and I'm going to go and bring
  6977. 3:57:13the ID back. So I believe this was the
  6978. 3:57:16step. So let's go and bring it back.
  6979. 3:57:18Yes. So we need those stuff. I'm going
  6980. 3:57:21to go and rename it. This is the channel
  6981. 3:57:24code. Now let's go back to the fact
  6982. 3:57:26sales and let's do the merge with the
  6983. 3:57:28junk dimension. So we need it. It is
  6984. 3:57:31over here the order flags. Now we're
  6985. 3:57:33going to go and mark all those stuff but
  6986. 3:57:34not the channel itself because it has no
  6987. 3:57:36idea about it. It is something that we
  6988. 3:57:38added. Then we're going to go to the
  6989. 3:57:39right side and select those three. So
  6990. 3:57:42now things should work and in the
  6991. 3:57:44correct order by the way. So the order
  6992. 3:57:46channel, the status and the priority.
  6993. 3:57:48Same thing from the dimension. Left
  6994. 3:57:50join. Okay. Now the next step we're
  6995. 3:57:52going to go and expand. Since it is only
  6996. 3:57:54a lookup, we just need the key. So okay.
  6997. 3:57:57Yes, we got the junk flag. Uh let's go
  6998. 3:58:00and do it side by side with the others.
  6999. 3:58:02And of course the big question, do we
  7000. 3:58:04have issues with our number? So I'm
  7001. 3:58:06going to go and close and apply. Well,
  7002. 3:58:08look at this. It is safe. So our number
  7003. 3:58:10is protected. Let's go back. I know we
  7004. 3:58:12are jumping between but this is part of
  7005. 3:58:14the job. We have to do things like
  7006. 3:58:16carefully. All right. So with this now
  7007. 3:58:17we got all the keys, all the ids inside
  7008. 3:58:20our fact and it is ready to get
  7009. 3:58:22connected to the dimensions. And now
  7010. 3:58:24we're going to go to the next phase
  7011. 3:58:25where I like to go and drop things and
  7012. 3:58:27polish the facts in order to follow the
  7013. 3:58:29standards and the rules that we have
  7014. 3:58:31added at the beginning. So now we're
  7015. 3:58:32going to start with the first thing. Do
  7016. 3:58:34we really need all those columns inside
  7017. 3:58:35our facts? So let's do it step by step.
  7018. 3:58:37The line ID, we need the order ID as
  7019. 3:58:39well in order to count how many orders
  7020. 3:58:41inside the fact. The product name, we
  7021. 3:58:43don't need it anymore. We just used it
  7022. 3:58:45in order to build the keys. So we're
  7023. 3:58:47going to go and remove it. Then we have
  7024. 3:58:49the keys. That's of course what you
  7025. 3:58:51need. And then we have the numbers. We
  7026. 3:58:53need all that stuff in the facts. Now we
  7027. 3:58:55come to something that is really
  7028. 3:58:56important to understand. Now the thing
  7029. 3:58:58is in transactional source systems they
  7030. 3:59:00usually store the same informations over
  7031. 3:59:03and over in different tables just in
  7032. 3:59:05order to optimize the performance of
  7033. 3:59:07their UI and applications. And this is
  7034. 3:59:09of course a big issue for us because
  7035. 3:59:11then we're going to have like the same
  7036. 3:59:12information everywhere inside our data
  7037. 3:59:14model. And this is going to make a big
  7038. 3:59:16confusion on how to build the reports.
  7039. 3:59:18So that means my friends you have to
  7040. 3:59:20protect the data model by having like
  7041. 3:59:22one single point of truth for each info.
  7042. 3:59:24So that means if I have the customer
  7043. 3:59:26city inside the dimension customer I
  7044. 3:59:29don't need it somewhere else. This going
  7045. 3:59:30to be the dimension customer is the
  7046. 3:59:32single point of truth for the cities of
  7047. 3:59:34the customers. So I don't have to leave
  7048. 3:59:36it in like another dimension or to leave
  7049. 3:59:38it in the facts. So always try to reduce
  7050. 3:59:40the noise that we inherited from the
  7051. 3:59:42source systems and make a decision where
  7052. 3:59:45you going to store what but only once. I
  7053. 3:59:47said I was only going to say it once.
  7054. 3:59:49>> So that means my friends, we will not
  7055. 3:59:51leave the customer city inside our
  7056. 3:59:53facts. We have it already inside our
  7057. 3:59:55dimension. Look at this. We have here
  7058. 3:59:58the city of our customers. So that means
  7059. 4:00:00we don't need this extra noise that we
  7060. 4:00:02have in the facts. We will just go and
  7061. 4:00:04remove it. By the way, this is one of
  7062. 4:00:06the things that I have noticed a lot.
  7063. 4:00:07People going to say, you know what, we
  7064. 4:00:09might need it. So you really have to
  7065. 4:00:10take a hard decision and start removing
  7066. 4:00:12things that you don't need and keep it
  7067. 4:00:14only in one place. Same thing as well
  7068. 4:00:16for the region name. It as well belongs
  7069. 4:00:18to the customer dimension. So let's go
  7070. 4:00:21remove. And now here's something
  7071. 4:00:22interesting to what we said. We have
  7072. 4:00:24here the ship to city and pill to city.
  7073. 4:00:27This is different information than we
  7074. 4:00:29had in the dimension customer. This
  7075. 4:00:31belongs to the transaction to the order.
  7076. 4:00:33So for each order we have the city where
  7077. 4:00:35it is shipped to. And here the customers
  7078. 4:00:38might change from one order to another
  7079. 4:00:40to which city or to which location the
  7080. 4:00:42order should be delivered. So the city
  7081. 4:00:44here belongs to the transaction to the
  7082. 4:00:46event. It is not like master data of the
  7083. 4:00:48customer. So that means this has
  7084. 4:00:50different meaning than the cities that
  7085. 4:00:52we have inside the dimension. It is
  7086. 4:00:54something here transactional and could
  7087. 4:00:56change from one order to another. So
  7088. 4:00:58that's why I will not go and remove
  7089. 4:01:00those informations because this belongs
  7090. 4:01:02to the event to the transaction. So it's
  7091. 4:01:04always really important to understand
  7092. 4:01:05the business to understand the domain
  7093. 4:01:07how things works. So let's keep going.
  7094. 4:01:09The order date of course we need it. Now
  7095. 4:01:11we have a lot of things that we don't
  7096. 4:01:12need anymore because they were only here
  7097. 4:01:15in order to do a lookup. So I'm going to
  7098. 4:01:17go and remove those stuff that were
  7099. 4:01:18belonging to the junk. And now we come
  7100. 4:01:20to something really interesting. The
  7101. 4:01:22total sales in the header. So as well we
  7102. 4:01:24have to decide because now we have two
  7103. 4:01:26things. Look at this. We have the total
  7104. 4:01:28sales for the whole order. And here we
  7105. 4:01:30have like the sales for each item each
  7106. 4:01:33line in the order. Now of course if
  7107. 4:01:34everything is clean the sum of the line
  7108. 4:01:37of totals should be exactly the same
  7109. 4:01:39value that we have here from the header.
  7110. 4:01:41So that means the grain between those
  7111. 4:01:43two are different. And now here usually
  7112. 4:01:45I decide on the following where I say we
  7113. 4:01:47go and remove any pre-agregated values
  7114. 4:01:50because to be honest I don't trust it.
  7115. 4:01:52If I need the total sales for each order
  7116. 4:01:54actually I just go and summarize those
  7117. 4:01:56values. So I have the data already
  7118. 4:01:58available. I don't want to have like
  7119. 4:02:00pre-agregated things inside the data
  7120. 4:02:02model that's maybe outdated or maybe the
  7121. 4:02:05calculation is not anymore correct.
  7122. 4:02:07That's why I tend to remove any
  7123. 4:02:09pre-agregated things that I inherit from
  7124. 4:02:11the source system. Especially if I have
  7125. 4:02:14the same information from another
  7126. 4:02:16detailed measure. So that's why the
  7127. 4:02:18order total that we got from the header,
  7128. 4:02:19it is something unnecessary and I'm
  7129. 4:02:21going to go and remove it. I can always
  7130. 4:02:23get it back if it's needed. All right,
  7131. 4:02:24my friends. So with this we have removed
  7132. 4:02:26a lot of things from our fact table and
  7133. 4:02:28now things looks really good. Now I
  7134. 4:02:30would like always to order my fact like
  7135. 4:02:32this. We have always at the start all
  7136. 4:02:34the IDs and then all the dates and at
  7137. 4:02:37the end all the measures all the
  7138. 4:02:39numbers. It is not something that's very
  7139. 4:02:41important but I like to order it like
  7140. 4:02:42this. So that's why I'm going to go and
  7141. 4:02:44grab all the context to the starts and
  7142. 4:02:47just leave the numbers at the end. So
  7143. 4:02:48now look at this. We have ids
  7144. 4:02:50everywhere. Then we have the cities. We
  7145. 4:02:52have to do something about it. After
  7146. 4:02:53that we have the dates. We have only one
  7147. 4:02:56and at the end we have the bundle of all
  7148. 4:02:58measures and numbers that we have in the
  7149. 4:03:00fact. So we are almost there but to be
  7150. 4:03:02honest I'm still not happy about those
  7151. 4:03:04two. So we have the ship to city and the
  7152. 4:03:06pill to city. Now of course I can leave
  7153. 4:03:08those informations like this but we
  7154. 4:03:10could build a dimension for it. So
  7155. 4:03:12that's we have like ids instead of text
  7156. 4:03:15here which can reduce of course the size
  7157. 4:03:16of the fact table and at the same time
  7158. 4:03:18maybe I need more context to those
  7159. 4:03:20cities like for example the region or
  7160. 4:03:22the country and so on. So it's always
  7161. 4:03:25better to convert those contextes to
  7162. 4:03:27dimensions. So that means we have
  7163. 4:03:29actually to construct a new dimension
  7164. 4:03:31called dimension geo or locations or
  7165. 4:03:34whatever you want to call it. Now of
  7166. 4:03:36course the question is what is the
  7167. 4:03:37source for this new dimension? Should we
  7168. 4:03:39get it from the fact or do we have like
  7169. 4:03:41some row tables that can help us with
  7170. 4:03:43that? Well, remember we had really nice
  7171. 4:03:45row table called cities. This is
  7172. 4:03:47perfect. This is already like waiting
  7173. 4:03:49for us to build a dimension for it. We
  7174. 4:03:51just skipped it. As you can see, we
  7175. 4:03:52cannot like think of everything at the
  7176. 4:03:54start. As we progress in the data model,
  7177. 4:03:56we're going to understand, okay, we need
  7178. 4:03:57more things and we always can go back to
  7179. 4:03:59the row data and make new dimensions.
  7180. 4:04:01So, how we're going to do it? This going
  7181. 4:04:02to be very simple. We're going to go and
  7182. 4:04:04create a reference and we're going to
  7183. 4:04:05drag this reference to the dimensions.
  7184. 4:04:07We're going to go and give it a name dem
  7185. 4:04:09go. Now we have to make sure that this
  7186. 4:04:11has no duplicates. I'm not really sure
  7187. 4:04:13whether it has or not. So I'm going to
  7188. 4:04:15go and remove duplicates. Well, nothing
  7189. 4:04:17changed, but I'm going to leave it as
  7190. 4:04:18step. Maybe things changed. Of course,
  7191. 4:04:20what is missing this dimension? We need
  7192. 4:04:22an ID, right? So we're going to go and
  7193. 4:04:23add a new index that starts from one and
  7194. 4:04:26bring it to the top. So let's go and
  7195. 4:04:28rename it. This going to be geo key,
  7196. 4:04:31surrogate key. And the last thing that
  7197. 4:04:32I'm going to do just rename things. So
  7198. 4:04:34this is the city and this is the region.
  7199. 4:04:38Perfect. Now we have new dimension. Of
  7200. 4:04:40course, what is the next step? We're
  7201. 4:04:42going to go and connect it to our fact
  7202. 4:04:43sales. So over here using the city name.
  7203. 4:04:46But my friends, we're going to go and
  7204. 4:04:47connect it twice because here we have
  7205. 4:04:49like two cities, right? They are
  7206. 4:04:51different. The city for the shipment and
  7207. 4:04:52another one for the pill. So let's go
  7208. 4:04:54and do that. We're going to do it
  7209. 4:04:55quickly. We're going to go and merge and
  7210. 4:04:57then grab our new dimension. It's going
  7211. 4:04:59to be of course the city. So and then
  7212. 4:05:02hit okay. Expand. We need only the key.
  7213. 4:05:05All right. And then we're going to merge
  7214. 4:05:07again for the other column. So same
  7215. 4:05:09dimension. We need the city, but this
  7216. 4:05:11time for the pill. All right. Expand as
  7217. 4:05:13well. We need the key. Now, before we
  7218. 4:05:16forget, we're going to go and rename
  7219. 4:05:17things. So we're going to call it sheep
  7220. 4:05:19to city key. And the other one bill to
  7221. 4:05:24city key. All right. So now let's go and
  7222. 4:05:26grab them to the other keys. So we can
  7223. 4:05:29put it over here. And now we're going to
  7224. 4:05:31go and remove those two cities. We have
  7225. 4:05:33ids. So remove. Perfect. Now let's have
  7226. 4:05:36a final look. Look at this. We just have
  7227. 4:05:39numbers. Now the last step that I'm
  7228. 4:05:40going to do is that I'm going to go and
  7229. 4:05:42just rename all the columns to follow
  7230. 4:05:43our standards. The snake case. All
  7231. 4:05:45right. So now I just went through all
  7232. 4:05:46the columns and everything is renamed.
  7233. 4:05:48Look at this. Everything looks perfect.
  7234. 4:05:50We have only numbers and date. And this
  7235. 4:05:52is exactly how the fact table supposed
  7236. 4:05:54to be. If you get it, my friend like
  7237. 4:05:56this then congrats. We just built a
  7238. 4:05:58perfect core fact table for our data
  7239. 4:06:00model out of this complicated setup, the
  7240. 4:06:03header and the details. Now I'm going to
  7241. 4:06:04say the fact is ready. And now we're
  7242. 4:06:06going to go to the satisfying part where
  7243. 4:06:08we're going to go and deactivate some
  7244. 4:06:10row tables and then we're going to go
  7245. 4:06:11ahead and connect the dimensions to our
  7246. 4:06:13fact. Let's go and do that. I'm just go
  7247. 4:06:15and deactivate now the orders both of
  7248. 4:06:18them and as well the order line and then
  7249. 4:06:20close and apply. All right. So now what
  7250. 4:06:23we're going to do, let's go and make
  7251. 4:06:24like two words on the left side. It's
  7252. 4:06:27going to be this chaos. But on the right
  7253. 4:06:28side, we're going to have our new clean
  7254. 4:06:30data model, the star schema. So this is
  7255. 4:06:33our fact. And now let's go and bring our
  7256. 4:06:35dimensions. So product, the geo,
  7257. 4:06:37customers, and the junk dimension. So
  7258. 4:06:40let's form the star and make sure we
  7259. 4:06:43don't have any garbage like in our
  7260. 4:06:45model. So now let's go and zoom in. We
  7261. 4:06:47still have to do it carefully how we
  7262. 4:06:48connect the dimensions to the fact, but
  7263. 4:06:50the pattern it's always the same. So
  7264. 4:06:52we're going to grab the customer ID and
  7265. 4:06:54put it on the fact here. It's very
  7266. 4:06:56important that you see one to many
  7267. 4:06:58relationship and the filter is single.
  7268. 4:07:00So never both. Okay. So that's it. Let's
  7269. 4:07:02save. This looks good. One to many and
  7270. 4:07:05the arrow going to the fact. Same thing
  7271. 4:07:07for the product key. So drag and drop.
  7272. 4:07:09One to many single. Save. And for the
  7273. 4:07:12junk. So we need flag key is over here.
  7274. 4:07:15One to many single. And now comes
  7275. 4:07:17something of course really interesting.
  7276. 4:07:19We have only one dimension. But we have
  7277. 4:07:21to connect it twice to our fact table.
  7278. 4:07:23one for the billing and another one for
  7279. 4:07:25the shipment. Well, we're going to do
  7280. 4:07:26that. So, the geo key goes to the
  7281. 4:07:29shipment. One to many single. This going
  7282. 4:07:31to be the active one and the second one
  7283. 4:07:33going to be the billing. So, drag and
  7284. 4:07:35drop one to many and single. So, save.
  7285. 4:07:38So, with us, my friend, our dimension go
  7286. 4:07:40is actually a role-playing dimension. We
  7287. 4:07:43have two relationships to the fact
  7288. 4:07:44table. One is active that's going to be
  7289. 4:07:46used all the time and another one is
  7290. 4:07:48inactive. That's we have to use ducks in
  7291. 4:07:51order to use this relationship of
  7292. 4:07:52course. But now you might say okay this
  7293. 4:07:54is like way too more complicated than
  7294. 4:07:56before. If we had like both of them
  7295. 4:07:58inside a fact table I can just go and
  7296. 4:08:00use them inside my report. Well this is
  7297. 4:08:03a fair point. If you never need like
  7298. 4:08:05more geo informations but if you start
  7299. 4:08:07like needing the regions the countries
  7300. 4:08:09and this geo is like getting bigger and
  7301. 4:08:11bigger then it makes no sense to leave
  7302. 4:08:13it inside the fact and as well it makes
  7303. 4:08:16no sense to go and duplicate the
  7304. 4:08:17dimension twice. Those are all bad
  7305. 4:08:19designs. So now my friends, look at
  7306. 4:08:22this. If I zoom out, you can see clearly
  7307. 4:08:24the two words. On the left side we have
  7308. 4:08:26the full chaos and on the right side we
  7309. 4:08:28start having the shape of our star
  7310. 4:08:30schema our goal and things looks way
  7311. 4:08:33more better than before. So this exactly
  7312. 4:08:35my friends how we migrate from bad data
  7313. 4:08:38model to a new better model that's going
  7314. 4:08:40to deliver only correct numbers, good
  7315. 4:08:42performance and as well reduce any
  7316. 4:08:44confusion. Okay. Okay. So now we have to
  7317. 4:08:46keep going but this time I'm going to go
  7318. 4:08:47and pick something that is little bit
  7319. 4:08:49easy so that we have break. I will not
  7320. 4:08:52pick something complicated. We're going
  7321. 4:08:53to go this time with the inventories.
  7322. 4:08:55This is an easy one. So let's go and do
  7323. 4:08:58something about it. We're going to go
  7324. 4:08:59and enter the power query. So what do we
  7325. 4:09:02have here the inventories? Oh yes we
  7326. 4:09:04have here the product names and for each
  7327. 4:09:06month we have the total amount of items
  7328. 4:09:08that is planned. Well of course the
  7329. 4:09:10first question is is it a fact or
  7330. 4:09:11dimension? Well, since we have numbers,
  7331. 4:09:13we have dates, this is going to be a
  7332. 4:09:15fact. So, before we do anything, we're
  7333. 4:09:17going to go and make a reference, then
  7334. 4:09:18move it to our facts. This is our second
  7335. 4:09:21fact. I'm going to go and call it fact
  7336. 4:09:23inventory. And now we can start
  7337. 4:09:24preparing the fact. Now, the first easy
  7338. 4:09:26issue with that, the first column is not
  7339. 4:09:28promoted as a header. So, the column
  7340. 4:09:30names are weird. That's why we're going
  7341. 4:09:32to go and say use first row as header.
  7342. 4:09:34Easy win. Now, by looking to this, you
  7343. 4:09:36can see it is really nice table for us
  7344. 4:09:38for humans to read. But this is very bad
  7345. 4:09:40for data moduling because the date
  7346. 4:09:43information is stored as a column name.
  7347. 4:09:45We cannot use this of course in
  7348. 4:09:47reporting. That's why we have to convert
  7349. 4:09:49this from human ready to data module and
  7350. 4:09:51reporting. And how we can do that using
  7351. 4:09:53unpivot by turning the columns into
  7352. 4:09:56rows. It is very simple what we can do.
  7353. 4:09:58We can go to transform then select all
  7354. 4:10:00the columns. And here we have this nice
  7355. 4:10:02function unpivot. Look at this. Like
  7356. 4:10:04magic. Now all the column names are
  7357. 4:10:06values inside my table. And this looks
  7358. 4:10:09already like a fact table. And now after
  7359. 4:10:11that I think this is the data type text
  7360. 4:10:13right. So we can see here text we have
  7361. 4:10:15to go and convert this to a real date.
  7362. 4:10:17Then it's going to be easier to use in
  7363. 4:10:19the reporting. And same thing that we
  7364. 4:10:20have done before we have to go and get
  7365. 4:10:22the product key. So we need a lookup.
  7366. 4:10:24And how we going to do it? As usual we
  7367. 4:10:26go and merge with the dimension. So
  7368. 4:10:28dimension product connect the names and
  7369. 4:10:31say okay. Now after that we're going to
  7370. 4:10:33go and get only the key bring it to the
  7371. 4:10:36start and remove the product name. We
  7372. 4:10:38don't need it anymore. So remove and of
  7373. 4:10:40course my friends you have to go and
  7374. 4:10:42check things. Now I'm doing things
  7375. 4:10:43quickly but still we have to go to the
  7376. 4:10:45report make a card go and calculate all
  7377. 4:10:48the values after merging. Are we getting
  7378. 4:10:50like any duplicates? But now in order to
  7379. 4:10:51make things quicker I will not do that
  7380. 4:10:53but you have to do it at your side. I
  7381. 4:10:55would never trust that everything is
  7382. 4:10:56okay now. So now the last step in our
  7383. 4:10:58new fact I'm going to go and rename
  7384. 4:11:00things. So this is the product key and
  7385. 4:11:02this going to be I'm going to call it
  7386. 4:11:04for now month and instead of value I'm
  7387. 4:11:06going to call it units. All right
  7388. 4:11:08friends. So actually that's it. With
  7389. 4:11:09this we got our second fact and it is
  7390. 4:11:11perfect. It has an ID. It has a date and
  7391. 4:11:14as well a measure. Now before we go and
  7392. 4:11:16start connecting things I'm just going
  7393. 4:11:17to go and like deactivate so the
  7394. 4:11:19inventory will not be loaded. And
  7395. 4:11:21actually we have here few things that we
  7396. 4:11:22didn't deactivate before. So we have
  7397. 4:11:24here the orders and as well the
  7398. 4:11:26channels. So you we don't need you.
  7399. 4:11:29Okay. Okay, so now let's close and
  7400. 4:11:30apply. You can see the chaos is getting
  7401. 4:11:32reduced by the time. And here we got our
  7402. 4:11:34new fact table. Let me just zoom in and
  7403. 4:11:37have a look. Probably I done it
  7404. 4:11:38correctly. I wanted to do that. But as
  7405. 4:11:40you can see, we never connect the fact
  7406. 4:11:42tables together. So there's no direct
  7407. 4:11:44lines using the product key. We connect
  7408. 4:11:47the fact tables always using the shared
  7409. 4:11:49dimension. And this can be the dimension
  7410. 4:11:51products. Of course, a quick look. It is
  7411. 4:11:53one to many relationship. And the
  7412. 4:11:55direction is correct. As you can see, if
  7413. 4:11:56you do things correctly, PowerBI going
  7414. 4:11:58to love it and it's going to build it
  7415. 4:12:00for you correctly. So my friends, look
  7416. 4:12:01at this. We are moving from star schema
  7417. 4:12:04and now we are like building the galaxy,
  7418. 4:12:06right? Which is of course still star
  7419. 4:12:08schema. So my friends, that was a quick
  7420. 4:12:10win. All right, friends. So that was the
  7421. 4:12:12inventory. It was a little break. Now
  7422. 4:12:14let's go back to something more
  7423. 4:12:16advanced. Now we have to go and pick
  7424. 4:12:17something from our data model. So we
  7425. 4:12:19have invoices and stuff. I'm going to
  7426. 4:12:21say let's go and solve the campaign. So
  7427. 4:12:24we have the campaign log and another one
  7428. 4:12:26the campaign is cues. So it's time to
  7429. 4:12:28solve this puzzle. As usual, we're going
  7430. 4:12:30to go inside Power Query. So let's go
  7431. 4:12:32and do that. Okay. So let's go to the
  7432. 4:12:34campaign log. So again, what do you have
  7433. 4:12:36here? The campaign name, the channel,
  7434. 4:12:38the start date, and the end date of the
  7435. 4:12:39campaign, the budget date, and some nice
  7436. 4:12:43numbers. So clearly this looks like a
  7437. 4:12:45nice fact table. But still inside it, we
  7438. 4:12:48have some context about this fact. So
  7439. 4:12:50the context is my friend, the campaign
  7440. 4:12:53itself. So it looks like a clear split
  7441. 4:12:55between one dimension and one fact,
  7442. 4:12:57right? And let's have a quick look to
  7443. 4:12:58the other one. The campaign is cues. We
  7444. 4:13:00have here the campaign name and the
  7445. 4:13:02product names as a list. So this sounds
  7446. 4:13:05like the connection to the rest of our
  7447. 4:13:07star schema, the products, the product
  7448. 4:13:09code. So I think I got the full big
  7449. 4:13:11picture. Now let's go and start building
  7450. 4:13:13the dimension, the new one. All right.
  7451. 4:13:14So as usual, we're going to go and
  7452. 4:13:16create a reference out of the row table.
  7453. 4:13:18Now we're going to start with the
  7454. 4:13:19dimension. So that's why we're going to
  7455. 4:13:20bring it to the dimension folder and
  7456. 4:13:22rename it. So this is going to be the
  7457. 4:13:23dimension campaign. All right. So now
  7458. 4:13:26which columns going to stay and which
  7459. 4:13:27going to leave? Well my friends we have
  7460. 4:13:29here clear split. So all those columns
  7461. 4:13:32are actually transactional columns that
  7462. 4:13:34belongs to the fact and the rest going
  7463. 4:13:35to be the dimension. So let's get rid of
  7464. 4:13:38those. Now of course as usual we're
  7465. 4:13:40going to go and remove all the
  7466. 4:13:41duplicates from those columns. So remove
  7467. 4:13:44with this we got our six campaign that
  7468. 4:13:47we have inside our data model. And now
  7469. 4:13:48by looking to this you might say but
  7470. 4:13:50wait a second what is going on here
  7471. 4:13:53actually the fact always contains like
  7472. 4:13:55dates and numbers and this dimension
  7473. 4:13:57looks like a fact. So why we are calling
  7474. 4:14:00this a dimension campaign? Well totally
  7475. 4:14:02fair point at the start I was as well
  7476. 4:14:04confused about this topic but my friend
  7477. 4:14:06the dimensions and facts are not defined
  7478. 4:14:08by the data type of the columns. Think
  7479. 4:14:10about it a dimension is just a context a
  7480. 4:14:13description for an event and a fact
  7481. 4:14:15table it is the event itself. It is
  7482. 4:14:17transaction. It is something that keep
  7483. 4:14:19happening every day. So something that
  7484. 4:14:21grows fast. Right? So now by looking to
  7485. 4:14:23this my friends, this is not
  7486. 4:14:25transactional. This is not an event.
  7487. 4:14:27Yes, it has a start date and end date.
  7488. 4:14:29But this is actually describing the
  7489. 4:14:31campaign. It is more context, more info
  7490. 4:14:34for the campaign itself. And the number
  7491. 4:14:36budget over here, it is a fixed value
  7492. 4:14:38that as well describe how big is our
  7493. 4:14:41budget for this campaign. So yes, it
  7494. 4:14:43looks like an event, but this is not
  7495. 4:14:45transactional. Those are just describing
  7496. 4:14:47the campaign. Now in order to understand
  7497. 4:14:49what is a real transaction, just go back
  7498. 4:14:52to the original table. Look at this what
  7499. 4:14:54each row here is representing. So for
  7500. 4:14:56the first row for example, we have the
  7501. 4:14:57campaign name, the channel, the start
  7502. 4:14:59and ends, the budget. But here we have a
  7503. 4:15:02real transaction with the dates. So we
  7504. 4:15:04can see every day what is happening. So
  7505. 4:15:06in the first day what happens? We spent
  7506. 4:15:08so much, we got so much clicks and
  7507. 4:15:11impressions. What happens in the next
  7508. 4:15:12day for the same campaign? We spent less
  7509. 4:15:15but we got more clicks and so on. So my
  7510. 4:15:17friends all those columns are actually
  7511. 4:15:19transactional columns. Every day we are
  7512. 4:15:21like getting something new about the
  7513. 4:15:23campaign. And if you go to the left side
  7514. 4:15:25you're going to see those informations
  7515. 4:15:27are really static. So the budget will
  7516. 4:15:29not change the start and end will not
  7517. 4:15:31change as well. And because my friends
  7518. 4:15:33those informations are describing the
  7519. 4:15:36event itself. So the left side is not
  7520. 4:15:38changing so much. That's why it is a
  7521. 4:15:40dimension. But on the right side there
  7522. 4:15:42is a lot of transactions and movement
  7523. 4:15:44and that's why my friends those four
  7524. 4:15:46columns are effects. I hope this makes
  7525. 4:15:48sense but this is how we define
  7526. 4:15:50dimension and effect not only based on
  7527. 4:15:53the data types but as well what is going
  7528. 4:15:55on how the transaction is happening and
  7529. 4:15:57by understanding the business itself. So
  7530. 4:15:59that's why I decided on the split based
  7531. 4:16:01actually on the data. Now let's go back
  7532. 4:16:03to our dimension. We are not done yet.
  7533. 4:16:05Of course what is missing? We need an
  7534. 4:16:07ID. So start from one, move it to the
  7535. 4:16:09left side. And actually that's it. The
  7536. 4:16:11last thing that we have to do is to just
  7537. 4:16:12go and rename things. So I will just do
  7538. 4:16:14it quickly.
  7539. 4:16:16This is the key. This is the name.
  7540. 4:16:20This is the channel start date.
  7541. 4:16:27All right. So I can say our dimension is
  7542. 4:16:29ready. Now let's go and create our fact
  7543. 4:16:32table. So same thing we're going to go
  7544. 4:16:33and create a reference. As you can see
  7545. 4:16:35now our work is repetitive, right? This
  7546. 4:16:37is exactly how things works. So this
  7547. 4:16:40going to be the fact campaign but I'm
  7548. 4:16:42going to call it spend since we have the
  7549. 4:16:44spending there. All right. So now what
  7550. 4:16:46we're going to do actually we don't need
  7551. 4:16:48all those affirmations. We have them
  7552. 4:16:49already in the dimension. That means we
  7553. 4:16:51need now to do a lookup in order to get
  7554. 4:16:53the campaign key. So as usual we go and
  7555. 4:16:56merge queries with our new dimension the
  7556. 4:16:58campaign. We join with the campaign
  7557. 4:17:00name. It is unique in our dimension. And
  7558. 4:17:02then say okay. Now, since this is a
  7559. 4:17:04lookup, we just need the key. We don't
  7560. 4:17:06need all other informations. Drag it to
  7561. 4:17:08the start because we have always the
  7562. 4:17:10keys at the start. And get rid of all
  7563. 4:17:12those things. Those are in our
  7564. 4:17:14dimension. So, now what is left? We have
  7565. 4:17:16the date, impression, click spent. Looks
  7566. 4:17:18nice. The last step, we're going to go
  7567. 4:17:19and just rename things. So, I'm going to
  7568. 4:17:21do it quickly. Campaign key. And I'm
  7569. 4:17:25going to make everything lowered.
  7570. 4:17:30All right, my friends. So with this now
  7571. 4:17:32we got our third fact inside our data
  7572. 4:17:34model. Now let's go to the last table we
  7573. 4:17:36have here still the campaign skues. Now
  7574. 4:17:39before we start working on this we're
  7575. 4:17:40going to go and create a reference out
  7576. 4:17:42of it. So reference now I'm going to go
  7577. 4:17:44and put it in the facts but I'm going to
  7578. 4:17:46explain myself later. Okay just stay
  7579. 4:17:48with me. Now the first issue with that
  7580. 4:17:50we have here we don't have a column
  7581. 4:17:51names. So that's why I'm going to go and
  7582. 4:17:53promote it as a header. Now what do you
  7583. 4:17:55have here? We have like a list of
  7584. 4:17:57product codes. Uh this is of course a
  7585. 4:17:59nice thing but I cannot use it in
  7586. 4:18:00reporting right I cannot go and connect
  7587. 4:18:02it now to our model. So that's why we
  7588. 4:18:04have to do something about it and we
  7589. 4:18:06call moving a list into rows and
  7590. 4:18:08explode. So we have to explode it into
  7591. 4:18:10multiple rows and we can do that easily
  7592. 4:18:13by going to the column and say split
  7593. 4:18:16columns by delimiter because we have
  7594. 4:18:18here a comma. Let me just move it a
  7595. 4:18:19little bit. So the delimiter is actually
  7596. 4:18:21a comma. Now the thing is I will not go
  7597. 4:18:23and split by columns. I don't want each
  7598. 4:18:25value to go in separate columns. This
  7599. 4:18:27makes no sense. This time we are
  7600. 4:18:29splitting by row. So if you go to the
  7601. 4:18:31advanced settings, you can see here we
  7602. 4:18:32split by columns or rows. I'm going to
  7603. 4:18:34go with the rows. All right. So actually
  7604. 4:18:36that's it. Let's go and hit okay. Look
  7605. 4:18:37at this. Now each product code is now a
  7606. 4:18:40new row. But now before we celebrate
  7607. 4:18:42this, we have equality issue. If you see
  7608. 4:18:44like some values are shifted little bit
  7609. 4:18:46to the right side. You can understand
  7610. 4:18:48this if you go back to the original
  7611. 4:18:49steps at the start. You can see the
  7612. 4:18:51values are yes splitted by comma but
  7613. 4:18:53there's like after that a space. This is
  7614. 4:18:55just like a cosmetic thing for us in
  7615. 4:18:57order to read the list easier. But of
  7616. 4:18:58course, this is causing an issue after
  7617. 4:19:00we explode. So you see the first value
  7618. 4:19:02has no space, but all other values are
  7619. 4:19:04like moving to the right side because of
  7620. 4:19:06the white space at the start. So how to
  7621. 4:19:08solve this? It is very simple. We're
  7622. 4:19:09going to right click on it and then go
  7623. 4:19:10to transform and here we have the nice
  7624. 4:19:12trim. Look at this. Everything moved to
  7625. 4:19:14the left side and we don't have any more
  7626. 4:19:16empty space because my friends, we have
  7627. 4:19:18always to take care of the values that
  7628. 4:19:19are used for the merge later. All right.
  7629. 4:19:22So now what we going to do with this, my
  7630. 4:19:23friends? Well, this is not like a
  7631. 4:19:25dimension because it is like two
  7632. 4:19:27different entities, right? The campaign
  7633. 4:19:28and the products. And as well, you can
  7634. 4:19:30see it in our dimensions. We have a
  7635. 4:19:32dimension for the product. We have
  7636. 4:19:33dimension for the campaign. And this is
  7637. 4:19:35like just mapping between them. So, I
  7638. 4:19:37cannot go and put it in the dimension
  7639. 4:19:38product or in the dimension campaign.
  7640. 4:19:40And of course, it makes no sense to
  7641. 4:19:42create like a third dimension called
  7642. 4:19:44campaign product mapping because this is
  7643. 4:19:46not one entity. So, now in order to
  7644. 4:19:48understand more what is this, let's go
  7645. 4:19:50and convert those values to keys. as we
  7646. 4:19:53have done like in the facts. So now
  7647. 4:19:54instead of the campaign name, I'm going
  7648. 4:19:56to go and make a lookup and grab it from
  7649. 4:19:58the dimension. So campaign and we
  7650. 4:20:01connect by the campaign name. All right.
  7651. 4:20:03Now let's go and grab the key. We're
  7652. 4:20:05going to do the same thing as well for
  7653. 4:20:07the products. So let's go and merge
  7654. 4:20:09dimension product. This time we are
  7655. 4:20:11connecting using the product code, not
  7656. 4:20:13the product name. All right. Now let's
  7657. 4:20:16go and get the key, put them side by
  7658. 4:20:18side and get rid of those two
  7659. 4:20:20informations. So remove columns. Now the
  7660. 4:20:22last thing I'm just going to go and
  7661. 4:20:24replace the names. So this is the
  7662. 4:20:25campaign name and the other one is the
  7663. 4:20:28product key. Now look at this my
  7664. 4:20:30friends. If you have table that contains
  7665. 4:20:32a lot of keys and you have the feeling
  7666. 4:20:34this is like mapping or a bridge between
  7667. 4:20:36multiple dimensions. This table has no
  7668. 4:20:39numbers just like collection of keys.
  7669. 4:20:41Then my friend welcome to a new type of
  7670. 4:20:43facts. We call it the factless fact. A
  7671. 4:20:46factless fact it is like a classical
  7672. 4:20:48fact table. It has a lot of ids in order
  7673. 4:20:51to connect multiple dimensions. It has
  7674. 4:20:53as well dates. But the only difference
  7675. 4:20:56is that it doesn't contain any numbers.
  7676. 4:20:59So no measures. So that means with the
  7677. 4:21:01factless facts, we are not measuring
  7678. 4:21:03anything. So we are not interested about
  7679. 4:21:04the how much. We are only tracking
  7680. 4:21:06whether something happened or not. So it
  7681. 4:21:09is very simple. If your fact has no
  7682. 4:21:10measures, no numbers, then this is a
  7683. 4:21:12factless fact. So in this example, it is
  7684. 4:21:15little bit weird. Okay? It is not that
  7685. 4:21:17like perfect fact that we usually have.
  7686. 4:21:19We don't have a date only the keys. And
  7687. 4:21:21as well we cannot turn this into
  7688. 4:21:22dimension because this is not describing
  7689. 4:21:25actually anything. If this keeps like
  7690. 4:21:27really weird inside your data model, you
  7691. 4:21:29can go and just get rid of it. But for
  7692. 4:21:30now, we just build it. That's why I'm
  7693. 4:21:32going to go and call it the fact
  7694. 4:21:34promotion coverage. Okay. So this is our
  7695. 4:21:36weird fact. But of course, we have way
  7696. 4:21:38better fact here that you can do a lot
  7697. 4:21:40of analyzes using it. And we have our
  7698. 4:21:43new dimension. So now next what we're
  7699. 4:21:44going to do with that we're going to go
  7700. 4:21:45and deactivate things. We don't need
  7701. 4:21:47them anymore. So disable load. Yes. Same
  7702. 4:21:50thing for the campaign is cues.
  7703. 4:21:53All right. So now let's go and close and
  7704. 4:21:55apply. All right. So now we have here
  7705. 4:21:57less things on the chaos word. We are
  7706. 4:21:59moving to the right side. And here we
  7707. 4:22:01have our new stuff. So this is our
  7708. 4:22:03factless facts. Let me zoom in. This is
  7709. 4:22:06our new facts. The campaign spend. It is
  7710. 4:22:09connected correctly to the dimension
  7711. 4:22:11campaign. So one to many relationship
  7712. 4:22:13and the arrow is correct and the
  7713. 4:22:16dimension campaign it is a shared
  7714. 4:22:17dimension to the factless facts which is
  7715. 4:22:20just playing the role as a bridge
  7716. 4:22:21between the product and the campaign.
  7717. 4:22:23Look at this things are getting
  7718. 4:22:25connected. Yeah slowly. So I will just
  7719. 4:22:27move things a little bit closer. So now
  7720. 4:22:30by looking at this you can see our
  7721. 4:22:31shared dimension the product is shared
  7722. 4:22:33now by three facts. So it is a really
  7723. 4:22:35very important one of course and this is
  7724. 4:22:37of course a typical thing because in
  7725. 4:22:38each business the products are the most
  7726. 4:22:40important things. So we are
  7727. 4:22:42transitioning right? All right. Now my
  7728. 4:22:44friends, we come as well to a point
  7729. 4:22:45where it's going to get a little bit
  7730. 4:22:46heavy. But I'm going to explain it step
  7731. 4:22:48by step. So that means if you are
  7732. 4:22:50watching and you didn't take break, go
  7733. 4:22:52take fresh air, make a cafe and then we
  7734. 4:22:54continue. This is going to be a little
  7735. 4:22:56bit tricky, but we're going to see.
  7736. 4:23:00Okay, let's go. So now as I said, we
  7737. 4:23:01have now some events that we're going to
  7738. 4:23:04tackle in one go. Of course, as usual,
  7739. 4:23:06we're going to go back to the Power
  7740. 4:23:07Query in order to understand the content
  7741. 4:23:09and reshape things later. So now what
  7742. 4:23:11else that we have inside our table? We
  7743. 4:23:13have the invoices. So you can see we
  7744. 4:23:14have an invoice ID, an order ID, the
  7745. 4:23:17customer name, invoice date, amount. So
  7746. 4:23:19this is as well transactional. This is
  7747. 4:23:21an event. Now if you go to the payments,
  7748. 4:23:23you're going to have the same feeling.
  7749. 4:23:24We have the payment ID, the invoice ID,
  7750. 4:23:26customer payment day, and the amount.
  7751. 4:23:29Now if you go to the shipments, again,
  7752. 4:23:31very close shipment ID, order ID, and so
  7753. 4:23:34on. So my friends, all of those things
  7754. 4:23:36are events and somehow they are all
  7755. 4:23:38connected together. Now in order to
  7756. 4:23:39understand how to deal with this, we
  7757. 4:23:41have first to understand the process. So
  7758. 4:23:43the process is very simple like any
  7759. 4:23:45order. We have a customer which is the
  7760. 4:23:47company. They go and place an order. So
  7761. 4:23:50this is the first step. After that we're
  7762. 4:23:52going to go and ship the products to the
  7763. 4:23:54customer. So this is the second step.
  7764. 4:23:57And of course it going to follow up with
  7765. 4:23:58a delivery. So this going to be the
  7766. 4:24:00third step. So we're going to deliver.
  7767. 4:24:02And after that we're going to issue an
  7768. 4:24:04invoice. So this is number four. And the
  7769. 4:24:07last step my friends the payment is
  7770. 4:24:09going to happen. So pay this is step
  7771. 4:24:12number five. So actually this is the
  7772. 4:24:14whole process of ordering something from
  7773. 4:24:16our business. Now of course each step in
  7774. 4:24:18our process is actually a transaction.
  7775. 4:24:20So it has like a date. It has a number.
  7776. 4:24:23So how much the total sales for this
  7777. 4:24:25order. Same thing for the shipment. The
  7778. 4:24:27delivery had as well date invoice and as
  7779. 4:24:31well we have like some numbers on top of
  7780. 4:24:32it and how much the customer did pay. So
  7781. 4:24:35each one of them has their own table and
  7782. 4:24:37transactions. But everything is actually
  7783. 4:24:39my friends are connected back to the
  7784. 4:24:41order. This is the main trigger for the
  7785. 4:24:44whole event. Now of course what are our
  7786. 4:24:46options in order to build this process
  7787. 4:24:47inside our data model? Either we're
  7788. 4:24:49going to go like the source system where
  7789. 4:24:51we're going to go and build a table for
  7790. 4:24:53each step. So that means we're going to
  7791. 4:24:54go and build like one fact table for
  7792. 4:24:57each step. With that we're going to get
  7793. 4:24:59like five fact tables. We have already
  7794. 4:25:01one for the orders but for the rest we
  7795. 4:25:02have to go and build them. Well, this
  7796. 4:25:04sounds smart and reasonable things to
  7797. 4:25:06do. But now, if you have like a deeper
  7798. 4:25:08look to each of those steps, you're
  7799. 4:25:09going to find that we are talking about
  7800. 4:25:11the same money over and over. So, the
  7801. 4:25:14same number should be in the orders and
  7802. 4:25:16as well in the invoice and I hope in the
  7803. 4:25:18payments. Now, of course, the big
  7804. 4:25:19question is, do the business users
  7805. 4:25:21really want all those numbers in our
  7806. 4:25:23reports? Are there many use cases for
  7807. 4:25:25all those numbers? Well, I'm going to
  7808. 4:25:27say no. Usually the business user is
  7809. 4:25:29going to ask us okay find me the total
  7810. 4:25:31number of sales for the whole business
  7811. 4:25:33or maybe by the region or by the
  7812. 4:25:35products and for this my friends we have
  7813. 4:25:37one single point of truth for that it
  7814. 4:25:39going to be the orders so I'm going to
  7815. 4:25:41go and grab the number the money from
  7816. 4:25:44the order so I would not go and start
  7817. 4:25:45like showing all the numbers from each
  7818. 4:25:47steps because at the end it is the same
  7819. 4:25:49money so that means we will not get like
  7820. 4:25:51a lot of use cases for those numbers
  7821. 4:25:53that we're going to have inside those
  7822. 4:25:55facts but actually by looking to this
  7823. 4:25:57we're going to get better questions from
  7824. 4:25:58the business. They're going to ask
  7825. 4:26:00questions about the whole process
  7826. 4:26:01itself. So they're going to start asking
  7827. 4:26:03questions actually not about the numbers
  7828. 4:26:05but about the dates. So those
  7829. 4:26:08informations are way more interesting
  7830. 4:26:10than the numbers like for example how
  7831. 4:26:12long it takes from an order to delivery
  7832. 4:26:14or how long it takes from an order to
  7833. 4:26:17the payment. So there will be a lot of
  7834. 4:26:18questions how long from the delivery to
  7835. 4:26:20invoice or invoice payment. So that
  7836. 4:26:23means usually the business and
  7837. 4:26:24especially the process expert they going
  7838. 4:26:26to ask a lot of questions about the
  7839. 4:26:28dates. So that means what is actually
  7840. 4:26:30interesting from all those tables are
  7841. 4:26:32actually the dates for the business
  7842. 4:26:34intelligence. And now what we could do
  7843. 4:26:36instead of having like a fact for each
  7844. 4:26:38step, we're going to go and make like
  7845. 4:26:40one fact table that's going to put side
  7846. 4:26:43by side all those dates inside this fact
  7847. 4:26:46table. And once we have everything in
  7848. 4:26:47one fact table, then we can answer many
  7849. 4:26:50questions about the process. And of
  7850. 4:26:52course I'm not inventing here something
  7851. 4:26:54in business intelligence in data
  7852. 4:26:55moduling. This has a famous name. This
  7853. 4:26:58is my friend a type of fact table called
  7854. 4:27:00accumulating snapshot. So each row going
  7855. 4:27:02to represent like one event one order
  7856. 4:27:05that going to hold all the milestone
  7857. 4:27:07dates of the steps in our process. So
  7858. 4:27:10this is the accumulating snapshot fact
  7859. 4:27:12that we're going to go now and build.
  7860. 4:27:13Okay. So now since we have now special
  7861. 4:27:15type of fact, it's going to be as well
  7862. 4:27:17special how to build it. It will not be
  7863. 4:27:19like the others. Now since we're going
  7864. 4:27:21to have like the whole process in one
  7865. 4:27:23row, a lot of tables going to be
  7866. 4:27:25involved in building this fact. So this
  7867. 4:27:27going to be something special. Now how
  7868. 4:27:29to build it? We usually start with the
  7869. 4:27:30spine and usually it is the first step
  7870. 4:27:33in the process. It is the order. So that
  7871. 4:27:36means my friends this orders that we
  7872. 4:27:38build at the start where we combine
  7873. 4:27:40things together. This going to be the
  7874. 4:27:41starting point for our new facts. That
  7875. 4:27:43means I'm going to go and create a
  7876. 4:27:45reference out of it. Then we're going to
  7877. 4:27:47go and drop it in the facts. So we can
  7878. 4:27:50go and call it for example fact order
  7879. 4:27:53process or fulfillment whatever. All
  7880. 4:27:56right. So with this we have now good
  7881. 4:27:57starting point. This is the spine of our
  7882. 4:28:00fact. Each row is one order. And now the
  7883. 4:28:02question is which columns going to stay
  7884. 4:28:04and which going to leave. Now again what
  7885. 4:28:05is our purpose? We want to show for each
  7886. 4:28:07order for each customer all the steps
  7887. 4:28:10dates for the whole process. So that
  7888. 4:28:12means I don't actually need a lot of
  7889. 4:28:14things over here. I just need the order
  7890. 4:28:16dates. So that means I'm going to go and
  7891. 4:28:18remove all those stuff. Same thing for
  7892. 4:28:20the junks over here. So let's just and
  7893. 4:28:22go and remove. Actually that's all what
  7894. 4:28:24I need. So order ID, customer name, and
  7895. 4:28:26order date. This is the first step in
  7896. 4:28:29the process. Now of course instead of
  7897. 4:28:30having the customer name in order to
  7898. 4:28:32connect it to our data model, we're
  7899. 4:28:34going to go and make a lookup. So we're
  7900. 4:28:36going to go and join it with the
  7901. 4:28:37dimension customer. Customer name.
  7902. 4:28:39Customer name. And then we're going to
  7903. 4:28:41go and get our key.
  7904. 4:28:44Perfect. go to the left side and remove
  7905. 4:28:47the customer name. Perfect. Now we have
  7906. 4:28:49the first step. Now we have to go and
  7907. 4:28:51get the other steps of our process. What
  7908. 4:28:53is the next one? We have the shipments.
  7909. 4:28:56So we have the shipment ID, the order
  7910. 4:28:58ID, the mode, the date and the delivery
  7911. 4:29:00date. So actually we have here two dates
  7912. 4:29:02of the process which is exactly what do
  7913. 4:29:04we need. Now about the mode, we can
  7914. 4:29:06include it or not. But for now I will
  7915. 4:29:08not include those stuff inside our fact.
  7916. 4:29:10So I'm going to go back to that order
  7917. 4:29:11process and then merge the shipment with
  7918. 4:29:14our table. So it is somewhere over here
  7919. 4:29:17shipments. We join by the order ID and
  7920. 4:29:20hit okay. Now we have to go and expand.
  7921. 4:29:23We don't need the ids. We have it
  7922. 4:29:24already. We don't need the mode. I just
  7923. 4:29:26need the dates. Perfect. Look at this.
  7924. 4:29:28We have the shipment date and the
  7925. 4:29:30delivery. Now what is the next step? We
  7926. 4:29:32need actually the invoice. So let's have
  7927. 4:29:34a look to the invoices. So the invoice
  7928. 4:29:36ID again the order ID. This is our key.
  7929. 4:29:38We have again the customer name. We
  7930. 4:29:40don't need it. We have it already. We
  7931. 4:29:41just need the invoice dates. The amount
  7932. 4:29:43is going to be like the total sales. So
  7933. 4:29:45I'm just collecting the dates. Let's go
  7934. 4:29:47back to our process and same thing.
  7935. 4:29:49We're going to go and merge invoices.
  7936. 4:29:51Order ID. Order ID. Okay. Then we have
  7937. 4:29:53to expand. So just give me the date. So
  7938. 4:29:56now we are getting closer. Now the last
  7939. 4:29:58step in our process going to be the
  7940. 4:30:00payment, right? So over here, well, we
  7941. 4:30:02don't have the order ID. We have an
  7942. 4:30:04invoice ID. So we're going to join using
  7943. 4:30:06the invoice ID. We have it. We don't
  7944. 4:30:07need the customer name, just give me the
  7945. 4:30:09date. So let's go back to the process.
  7946. 4:30:12Now, of course, I need the invoice ID.
  7947. 4:30:14That's why I'm going to go some steps
  7948. 4:30:15back in order to expand correctly. So I
  7949. 4:30:18need the invoice and as well the dates
  7950. 4:30:21otherwise I cannot join it. So actually
  7951. 4:30:23now we have the ID and now we can do the
  7952. 4:30:25merge. So we need the payments over
  7953. 4:30:28here. This time the invoice ID with the
  7954. 4:30:30invoice ID. Let's hit okay. Then the
  7955. 4:30:33last expansion we need the payment date.
  7956. 4:30:36Now I can go and get rid of the invoice
  7957. 4:30:39ID. I don't need it anymore. So remove.
  7958. 4:30:41So now do we have everything for our
  7959. 4:30:43process? We have the order, the
  7960. 4:30:44shipment, delivery, invoice, and
  7961. 4:30:46payment. And this looks exactly like our
  7962. 4:30:48business process. So this is my friends
  7963. 4:30:50the fact that called accumulating
  7964. 4:30:52snapshots for one event. You're going to
  7965. 4:30:54get all the dates of the process. Of
  7966. 4:30:56course, I'm doing things very quickly. I
  7967. 4:30:58usually do and test a lot. Each merge I
  7968. 4:31:00check whether we have duplicates or the
  7969. 4:31:02numbers are correct. But now in order to
  7970. 4:31:04make things a little bit quicker, I'm
  7971. 4:31:05just merging like crazy. So this looks
  7972. 4:31:08really good. Now what we're going to do
  7973. 4:31:09actually with the other tables, I'm
  7974. 4:31:11going to say we're going to go and
  7975. 4:31:12deactivate them because we have now the
  7976. 4:31:15most important aspect of all those
  7977. 4:31:16tables. And of course if in the future
  7978. 4:31:18we got like more specific things and
  7979. 4:31:20more specific questions about for
  7980. 4:31:22example the invoices, then we might go
  7981. 4:31:24activate it again and build like special
  7982. 4:31:26purpose fact for it. But actually we got
  7983. 4:31:28the best of this table. So we connected
  7984. 4:31:30is with the order we have already the
  7985. 4:31:32customers the invoice dates and the
  7986. 4:31:34amount is not that important we have it
  7987. 4:31:36in the fact sales. So that's why my
  7988. 4:31:38friends I'm going to go and deactivate
  7989. 4:31:39it from the model. Same things for the
  7990. 4:31:42others. So let's go to the payments. The
  7991. 4:31:44same money is just repeating over and
  7992. 4:31:46over. So deactivate. Same thing for the
  7993. 4:31:49shipment over here. Well we can go and
  7994. 4:31:51include the mode if it's really that
  7995. 4:31:53important. But again if we get like some
  7996. 4:31:55specific use case for the shipment we
  7997. 4:31:57can go and activate it and add this
  7998. 4:31:59column. This will not be now necessary
  7999. 4:32:01for our data model. So we are
  8000. 4:32:02deactivating a lot of things. Now by
  8001. 4:32:05looking to this we still have the
  8002. 4:32:06invoice lines. This is exactly the same
  8003. 4:32:08setup like we had at the start. The
  8004. 4:32:10invoice line is the details of the
  8005. 4:32:12invoice and the invoices is the header.
  8006. 4:32:14Again if there is like special needs,
  8007. 4:32:16special use case in order to analyze the
  8008. 4:32:18invoices. We can go and always build a
  8009. 4:32:20fact tables out of those stuff. But for
  8010. 4:32:22now I don't see it as a core thing
  8011. 4:32:24inside our data model because again the
  8012. 4:32:26same money is repeating. So I'm going to
  8013. 4:32:28go and deactivate this as well. All
  8014. 4:32:30right. Now we have deactivated almost
  8015. 4:32:32like everything. So let's go and save
  8016. 4:32:34and see what do we have and look to our
  8017. 4:32:36data model. So this should get really
  8018. 4:32:38empty.
  8019. 4:32:41Oh wow. Look, we still have like four
  8020. 4:32:45tables out of the chaos. And of course
  8021. 4:32:48everything went to the new data model.
  8022. 4:32:50Now of course you might think now I'm
  8023. 4:32:52trying to rush up the project in order
  8024. 4:32:54to close things. But to be honest, this
  8025. 4:32:56is exactly the way how I work. I don't
  8026. 4:32:58go and push everything inside the data
  8027. 4:33:00model in order to have everything just
  8028. 4:33:02in case someone ask for something. I try
  8029. 4:33:05to push really hard on the data model
  8030. 4:33:07only to leave what is necessary. And I
  8031. 4:33:09can tell you after working in many
  8032. 4:33:11projects, this exactly the process. I
  8033. 4:33:13understand the business and try to bring
  8034. 4:33:15the core facts and the core dimensions
  8035. 4:33:17to the data model. And if there is like
  8036. 4:33:19one or two customers are asking very
  8037. 4:33:21specific questions about like some weird
  8038. 4:33:24tables, I would not go and destroy the
  8039. 4:33:26data model to be honest. I'm going to go
  8040. 4:33:27and build another PowerBI model just for
  8041. 4:33:30their purposes. So it's going to be
  8042. 4:33:31something quick just to make their
  8043. 4:33:33analysis and that's it and try to
  8044. 4:33:35protect the core data model from those
  8045. 4:33:38edge use cases. So this is my style on
  8046. 4:33:40how I do data modeling. But there are a
  8047. 4:33:42lot of people that go and include
  8048. 4:33:44everything inside the data model just in
  8049. 4:33:46case. Well, if you do it like this, then
  8050. 4:33:47you are including a lot of things that
  8051. 4:33:49will never be used in reporting and this
  8052. 4:33:52is really waste of space performance and
  8053. 4:33:54as well confused a lot in reporting. All
  8054. 4:33:56right, so now back to our data model.
  8055. 4:33:58Now we have like a new things. So we
  8056. 4:34:00have to be as well careful that the new
  8057. 4:34:02core data model is not getting like full
  8058. 4:34:04of chaos. So we have the order process.
  8059. 4:34:07This is the accumulating snapshot type
  8060. 4:34:09and yes it is connected with the
  8061. 4:34:11customers and that's it. So yes, we are
  8062. 4:34:13getting a lot of facts but we are making
  8063. 4:34:14sure none of the facts are connecting to
  8064. 4:34:17each others. They always go through a
  8065. 4:34:19shared dimension. Our shared dimension
  8066. 4:34:21now is the customers and the products
  8067. 4:34:23and always the relationships are
  8068. 4:34:25healthy. So we have here one to many
  8069. 4:34:27relationship and the direction is from
  8070. 4:34:29the dimension to the facts. So this is
  8071. 4:34:31not chaotic. This is very healthy. Okay.
  8072. 4:34:33So now we are getting very close to end
  8073. 4:34:36the migration. Look at this sneaky table
  8074. 4:34:38at the ends. Let's go ahead and put it
  8075. 4:34:39here. So what do we have here? We have
  8076. 4:34:41five tables yet to go. Now let's go to
  8077. 4:34:43power query and start like investigating
  8078. 4:34:45those stuff. Now I'm going to start with
  8079. 4:34:46the very obvious one. Remember the sheet
  8080. 4:34:49one. It is a complete duplicate of the
  8081. 4:34:51shipment. So they are like identical
  8082. 4:34:53tables. Think this is an import problem
  8083. 4:34:55that happens maybe from the source
  8084. 4:34:56system or in the Excel. Of course
  8085. 4:34:58happens a lot in real projects where you
  8086. 4:35:00import stuff that are actually not
  8087. 4:35:02necessary inside the model. So what you
  8088. 4:35:04going to do? We're going to go and just
  8089. 4:35:05delete it. Not enable. So we remove it
  8090. 4:35:08completely physically from our model. It
  8091. 4:35:10is not something that we're going to
  8092. 4:35:12need later. Okay, so let's keep going.
  8093. 4:35:13We have the exchange rate. Well, I'm
  8094. 4:35:15thinking about this. We don't have like
  8095. 4:35:17any relevance for this inside our data
  8096. 4:35:19model. It is something transactional
  8097. 4:35:20maybe important for the interfaces in
  8098. 4:35:22the source system. But for reporting,
  8099. 4:35:24why do we need those informations? And
  8100. 4:35:26actually, I cannot go and connect it to
  8101. 4:35:27our data model. That's why I'm going to
  8102. 4:35:29say this is a standalone table that
  8103. 4:35:32actually will not help us at all. So,
  8104. 4:35:34I'm going to go actually and deactivate
  8105. 4:35:35it. I will not like physically remove
  8106. 4:35:37it. Maybe there is like use case for it.
  8107. 4:35:39We cannot connect this anywhere. So
  8108. 4:35:41deactivate. Now what else we have here?
  8109. 4:35:43The sales target. So here we have the
  8110. 4:35:45target revenue and the period. So
  8111. 4:35:47someone is like actually planning the
  8112. 4:35:49target for each month. Well, this is
  8113. 4:35:51like mini transactional table. This is
  8114. 4:35:53not a dimension. That's why I'm going to
  8115. 4:35:55say let's go and make small fact out of
  8116. 4:35:57this. It will not hurt. So we're going
  8117. 4:35:59to go and bring it to the facts. Rename
  8118. 4:36:01it of course. So rename fact. I'm going
  8119. 4:36:04to stay call it the sales targets. And
  8120. 4:36:06what else we could do? We just go and
  8121. 4:36:08maybe rename things to follow our
  8122. 4:36:09standards. So the date and the target
  8123. 4:36:12revenue. So actually that's it. It is a
  8124. 4:36:14mini one that don't have really any like
  8125. 4:36:16IDs to customers or dimensions. Only has
  8126. 4:36:19a date and a measure. So that's it.
  8127. 4:36:21Let's go and deactivate this one.
  8128. 4:36:22Disable load. Now what else do we have?
  8129. 4:36:25We have the security. And as well we
  8130. 4:36:27have a dimension order. This is of
  8131. 4:36:30course completely garbage table. So here
  8132. 4:36:32we have just like a list of all orders
  8133. 4:36:34and this makes no sense. We have already
  8134. 4:36:36better tables for this. So I'm going to
  8135. 4:36:38say I'm going to go and remove this
  8136. 4:36:40completely physically from our data
  8137. 4:36:41model. So delete we will not deactivate.
  8138. 4:36:44Perfect. Now the last thing that is left
  8139. 4:36:46is the security. Of course my friends we
  8140. 4:36:48cannot leave the data model as it is. We
  8141. 4:36:51have to make it secure following the
  8142. 4:36:52standards. And here we have a very
  8143. 4:36:54helpful table to let us know which user
  8144. 4:36:56is allowed to see which region. But of
  8145. 4:36:58course we're going to do this in the
  8146. 4:36:59last phase. So now what I'm going to say
  8147. 4:37:01actually we have covered everything. So
  8148. 4:37:03let's go and close and apply and have a
  8149. 4:37:05look. Yes, it is empty. I know we have
  8150. 4:37:07the security. We can do this later. I'm
  8151. 4:37:09going to bring it near to our data model
  8152. 4:37:11here. And my friends, I can say the
  8153. 4:37:13nightmare data set just got cleaned up.
  8154. 4:37:16So, we have here a healthy star schema.
  8155. 4:37:19Just enjoy this view. Have a look to
  8156. 4:37:21this. We have a healthy data model. I
  8157. 4:37:24think my camera gave up. So, back now.
  8158. 4:37:26Look at this my friends. We don't have
  8159. 4:37:28anything anymore from the old spider
  8160. 4:37:30web, the nightmare data set. Everything
  8161. 4:37:32is migrated to a clean star schema of
  8162. 4:37:35course a galaxy one. So everything is
  8163. 4:37:37connected using the best practices and
  8164. 4:37:40we have here only one fact table that
  8165. 4:37:42stands alone and the security table. So
  8166. 4:37:44just sit back and look at this. This is
  8167. 4:37:46really satisfying. But of course we are
  8168. 4:37:47not done yet. We still have the [music]
  8169. 4:37:49last phase.
  8170. 4:37:54All right friends. Now the next phase
  8171. 4:37:55it's all about polishing the data model.
  8172. 4:37:57So we're going to finalize our data
  8173. 4:37:59model. We're going to make it
  8174. 4:38:00trustworthy before handing it over for
  8175. 4:38:02the next phases. So, we're going to do
  8176. 4:38:03things like for example, we're going to
  8177. 4:38:04go and check again our standards, our
  8178. 4:38:06rules and check whether all the tables
  8179. 4:38:08and the columns are following it like
  8180. 4:38:10the snake case, like the prefixes,
  8181. 4:38:12suffixes, the keys and so on. The second
  8182. 4:38:14step that I usually do is that I go and
  8183. 4:38:16create the dimension date. It is a
  8184. 4:38:18special dimension that actually going to
  8185. 4:38:20be needed almost in all our facts. So,
  8186. 4:38:23we have to create it and connect it in
  8187. 4:38:24the data model. This is one of the
  8188. 4:38:26things that I do at and after that we're
  8189. 4:38:28going to build like a collection of
  8190. 4:38:30measures. So we're going to make like
  8191. 4:38:31set of very obvious measures that's
  8192. 4:38:33going to be needed on top of this model.
  8193. 4:38:35And after that we're going to make sure
  8194. 4:38:36that our data model is secure. That
  8195. 4:38:38means we're going to apply on this model
  8196. 4:38:40the role level security is like almost
  8197. 4:38:42standards in any project. And after that
  8198. 4:38:44we do the final testing. So we go to the
  8199. 4:38:47report level and we go and check only
  8200. 4:38:48the big numbers and whether the
  8201. 4:38:50dimensions are working correctly to make
  8202. 4:38:52sure that everything is correct before
  8203. 4:38:54handing over this data model for the
  8204. 4:38:56others. Usually the last step is I go
  8205. 4:38:58and make a meeting and talk to the
  8206. 4:38:59others, show them the start schema and
  8207. 4:39:01make a guide on how to use it for
  8208. 4:39:03reporting. All right, my friends. Now
  8209. 4:39:05let's deep dive in this phase.
  8210. 4:39:06>> Okay, let's do it.
  8211. 4:39:08>> Okay, so now let's start with the first
  8212. 4:39:09step where we're going to go and check
  8213. 4:39:10whether our data model is following the
  8214. 4:39:12standards and rules. I'm pretty sure
  8215. 4:39:14that I have forgotten something during
  8216. 4:39:16the building phase. We are at end human
  8217. 4:39:18and we might forget things. So now how I
  8218. 4:39:20usually do it is that I go to the table
  8219. 4:39:21view over here and have a quick check on
  8220. 4:39:23the right side. So I can see that
  8221. 4:39:25everything is sorted correctly using the
  8222. 4:39:27prefix. So we have the dimensions and
  8223. 4:39:29the facts and the last one is the
  8224. 4:39:31security. So by looking to this I can
  8225. 4:39:32say all the names of our tables are
  8226. 4:39:34following the standards. Then we go just
  8227. 4:39:36quickly through all the tables one by
  8228. 4:39:38one just to have a quick look. Well
  8229. 4:39:40everything looks so far fine. Well,
  8230. 4:39:43seems that I have followed all the
  8231. 4:39:45rules. Well, not everywhere. [laughter]
  8232. 4:39:48So, I have to fix here the naming
  8233. 4:39:49conventions for this fact table. So, we
  8234. 4:39:52have to do it quickly to go to the power
  8235. 4:39:54query. Okay. The fact order. So,
  8236. 4:39:57customer ID, order dates,
  8237. 4:40:02ship date.
  8238. 4:40:04Okay, looks good. So, I'm going to go
  8239. 4:40:06and close and apply. All right, so we
  8240. 4:40:08are following the standards over here.
  8241. 4:40:10Let's go and keep going. Looks good as
  8242. 4:40:13well. Good. The security going to be at
  8243. 4:40:14the end. Okay. So that means we are
  8244. 4:40:16following all the rules for the table
  8245. 4:40:18names and as well for the columns. Now
  8246. 4:40:20there is another thing that I do that I
  8247. 4:40:22go and check the date format. Well, you
  8248. 4:40:24can see here that in our dates we are
  8249. 4:40:26using the full name, the full month.
  8250. 4:40:28This looks really weird in reporting. If
  8251. 4:40:30you have a lot of dates, it's going to
  8252. 4:40:31take a lot of space in the report level.
  8253. 4:40:33So what I usually do is that I decide on
  8254. 4:40:35one like smaller format and I stick to
  8255. 4:40:37it for the whole data model. So now what
  8256. 4:40:39I'm going to do, I'm going to go and
  8257. 4:40:41first decide on the formats. So if you
  8258. 4:40:42go over here to the column tools, you
  8259. 4:40:44can see that we have format for the
  8260. 4:40:46dates and in PowerBI we have a lot of
  8261. 4:40:48formats. I'm going to say the standards
  8262. 4:40:49is going to be this one. So the year,
  8263. 4:40:51then the month and day depend of course
  8264. 4:40:54on the region. But this one is compacted
  8265. 4:40:56and small. Look at this. It is not
  8266. 4:40:57taking so much space. So that means this
  8267. 4:41:00is going to be the standards on how to
  8268. 4:41:02show the format inside the data model.
  8269. 4:41:04Now we're going to do very annoying task
  8270. 4:41:06where I'm going to go through the whole
  8271. 4:41:08data model and make sure that all the
  8272. 4:41:09dates are using this format. Now of
  8273. 4:41:11course you can pause the video and do
  8274. 4:41:13it. I'm going to now fast forward just
  8275. 4:41:14to make sure this video don't explode.
  8276. 4:41:16So I'm going to do this pretty fast. So
  8277. 4:41:19let's go.
  8278. 4:41:29So that was the last fact in our data
  8279. 4:41:31model and with that we have now the same
  8280. 4:41:32format for the whole data model. Now
  8281. 4:41:34there is another thing that I usually do
  8282. 4:41:36in this phase as well since we are now
  8283. 4:41:37going through all tables. When PowerBI
  8284. 4:41:39sees a column as a number it going to
  8285. 4:41:41make it automatically like aggregatable.
  8286. 4:41:43So that means if you use it inside your
  8287. 4:41:45report PowerBI going to automatically
  8288. 4:41:47like summarize all the values. This is
  8289. 4:41:49of course nice thing but sometimes we
  8290. 4:41:51have numbers where it makes no sense to
  8291. 4:41:53summarize. So it's really nice if you
  8292. 4:41:55clean this in the data model before
  8293. 4:41:57going to the next phase so that people
  8294. 4:41:59don't make any mistakes. So now what
  8295. 4:42:00we're going to do, we're going to go
  8296. 4:42:01through all the tables one by one and
  8297. 4:42:03always keep your eye on this icon. That
  8298. 4:42:05means this column could be aggregated.
  8299. 4:42:08For example, here the budget can see
  8300. 4:42:09here the summarizations it is sum. If
  8301. 4:42:11you don't want it to get summarized,
  8302. 4:42:13you're going to go over here and say
  8303. 4:42:14don't summarize. So now you have to make
  8304. 4:42:16decisions almost for all your numbers.
  8305. 4:42:18I'm going to say for the budget it makes
  8306. 4:42:19sense of course to make maybe an
  8307. 4:42:21average. So I'm going to leave it as it
  8308. 4:42:23is. For the customers, well I'm going to
  8309. 4:42:25say maybe makes sense to make an average
  8310. 4:42:27out of this. So this is okay. So let's
  8311. 4:42:29go through all the dimensions. Same
  8312. 4:42:31things for the products. So that was the
  8313. 4:42:33last table, the last column and with
  8314. 4:42:35that all dates inside my data model is
  8315. 4:42:37following the same format. All right. So
  8316. 4:42:39that's what the first step. We made sure
  8317. 4:42:40that we are following the rules and the
  8318. 4:42:42standards on the format and everything.
  8319. 4:42:44Now we're going to go to the next step
  8320. 4:42:46that I usually do with that. I go and
  8321. 4:42:47create the dimension date. There are
  8322. 4:42:50many different ways on how to create
  8323. 4:42:51this. I usually do that in the back end.
  8324. 4:42:54So if I have a database or data bricks,
  8325. 4:42:56I go and create the dimension there. But
  8326. 4:42:58since now we are just doing PowerBI, I'm
  8327. 4:43:00going to show you a way on how to create
  8328. 4:43:02it directly in your data model. Uh there
  8329. 4:43:04is a really nice way. I'm going to say
  8330. 4:43:05very smart way actually from PowerBI.
  8331. 4:43:07Now I will not go and give you like a
  8332. 4:43:09CSV file or text with all dates inside
  8333. 4:43:12it and say hey this is your dimension
  8334. 4:43:14but this time we're going to go and
  8335. 4:43:15create it by getting inspired from the
  8336. 4:43:17data model. So how we going to do it?
  8337. 4:43:19You're going to go over here to the home
  8338. 4:43:21and here in the ribon we have something
  8339. 4:43:22called new table. So what we are doing
  8340. 4:43:24here we are like creating a new table
  8341. 4:43:27inside the data model and we're going to
  8342. 4:43:29go and call it since this is the
  8343. 4:43:31dimension dimension dates. Now there is
  8344. 4:43:33a very cool function in PowerPI called
  8345. 4:43:35calendar auto. So read this. It returns
  8346. 4:43:38a table with one column of dates
  8347. 4:43:40calculated from the model automatically
  8348. 4:43:42and this exactly what it does. It go and
  8349. 4:43:44scan the whole data model understand the
  8350. 4:43:47range of our business. So understand
  8351. 4:43:49what is the earliest date and what is
  8352. 4:43:51the latest date and just create one
  8353. 4:43:53column based on that. Very very cool. So
  8354. 4:43:56actually that's it. We don't have to
  8355. 4:43:57give it any arguments and hit enter.
  8356. 4:43:59Amazing things. So look at this. The
  8357. 4:44:01earliest date is the 1st of January 2025
  8358. 4:44:04and the latest date is the end of 2026.
  8359. 4:44:07And of course this my friends going to
  8360. 4:44:09expand automatically as the business
  8361. 4:44:11grow. So that means if the data sets
  8362. 4:44:13like grow over the time and you have
  8363. 4:44:142027, you don't have to deal with the
  8364. 4:44:17dimension date because it going to grow
  8365. 4:44:19automatically. So suddenly you're going
  8366. 4:44:20to have as well in the dimension date
  8367. 4:44:222027. I can tell you this is magic
  8368. 4:44:24really. In my old days as I done
  8369. 4:44:26business intelligence with other tools
  8370. 4:44:28that was one of the biggest struggles
  8371. 4:44:30where I had like a manual table and I
  8372. 4:44:32have to always add a new years and stuff
  8373. 4:44:34like that. And I can tell you many
  8374. 4:44:36people forget to update their dimension
  8375. 4:44:38dates and of course this cause a lot of
  8376. 4:44:40problems in the report because almost on
  8377. 4:44:42each report you are doing like analyzes
  8378. 4:44:44over the time and you will be using this
  8379. 4:44:46dimension. So this is one of the most
  8380. 4:44:48important dimension compared to the
  8381. 4:44:50others and if you don't make sure it is
  8382. 4:44:52always up to date it's going to be
  8383. 4:44:54catastrophic. But now we don't have to
  8384. 4:44:55deal with all this chaos. PowerBI did
  8385. 4:44:57solve this and everything now is
  8386. 4:44:59automatic. Just some trauma from my old
  8387. 4:45:01days. All right. So now what do we have?
  8388. 4:45:02We have only like one column right now.
  8389. 4:45:04What you can do, you can go of course
  8390. 4:45:06and change the format to our format. So
  8391. 4:45:08we need only the date. We don't need the
  8392. 4:45:10hours and time. And of course the next
  8393. 4:45:12step if you want to go and expand this
  8394. 4:45:14dimension to add more columns like for
  8395. 4:45:16example the year, the month, the day,
  8396. 4:45:18the full name of the day, the full name
  8397. 4:45:20of the month. So you can add a lot of
  8398. 4:45:22things to this dimension by just going
  8399. 4:45:24and adding like a new column. Like for
  8400. 4:45:26example, if I would like to get only the
  8401. 4:45:28year, I'm going to do something like
  8402. 4:45:29this year equal and then use the
  8403. 4:45:31function year and specify here the
  8404. 4:45:33column. So this going to be our
  8405. 4:45:35dimension date and that's it. So with
  8406. 4:45:38that we have the column called year and
  8407. 4:45:40I can do the same thing. So I'm going to
  8408. 4:45:42go and duplicate it. So that we have the
  8409. 4:45:44years. We can go and create another one
  8410. 4:45:46for the month. Same story. So month
  8411. 4:45:48equal the function month in order to
  8412. 4:45:50extract this part our column. So my
  8413. 4:45:52friends, we have a lot of date functions
  8414. 4:45:54that we could add in order to expand
  8415. 4:45:56this dimension, but I'm going to leave
  8416. 4:45:57it like this. Now, of course, the big
  8417. 4:45:59question is how we going to connect this
  8418. 4:46:01new dimension to our data model. So we
  8419. 4:46:03have it over here and there are like
  8420. 4:46:05many places where we could connect this.
  8421. 4:46:07Almost all our facts has dates right
  8422. 4:46:10now. The thing is we have a lot of fact
  8423. 4:46:12tables inside our data model that have a
  8424. 4:46:14lot of date fields and this dimension
  8425. 4:46:17date can play a very important role in
  8426. 4:46:19order to make the bridge between all
  8427. 4:46:21those facts. This going to be shared
  8428. 4:46:23dimension that going to help us in order
  8429. 4:46:25to compare all those numbers from
  8430. 4:46:27different facts. So this is going to be
  8431. 4:46:28our biggest shared dimension in the
  8432. 4:46:31whole model. So how we do it? It's very
  8433. 4:46:33simple. We're going to go through the
  8434. 4:46:34facts one by one and start connecting it
  8435. 4:46:37to our dimension. So here we have the
  8436. 4:46:39fact sales target. We grab the date and
  8437. 4:46:41connect it to our dimension date. Okay.
  8438. 4:46:44Same thing. We go to the next one. We
  8439. 4:46:46have as well date. So we connected our
  8440. 4:46:48dimension. All right. So now we have
  8441. 4:46:49like a shared dimension between those
  8442. 4:46:51two. And we can go and compare now the
  8443. 4:46:53numbers between those two facts. Now we
  8444. 4:46:55have here this factless fact. It is a
  8445. 4:46:57little bit weird. We don't have a date.
  8446. 4:46:58So that's why we will not connect
  8447. 4:46:59anything here. Let's go to the next one.
  8448. 4:47:01Here we have a month as well. We can go
  8449. 4:47:03and connect it to our dimension. Let's
  8450. 4:47:05go. And of course the most important one
  8451. 4:47:07over here we have the fact sales. So we
  8452. 4:47:10have the order date. We go and connect
  8453. 4:47:12it and say save. And the last fact table
  8454. 4:47:15here we have a lot of dates. So for
  8455. 4:47:17example I'm going to go and grab the
  8456. 4:47:18order date to the dimension. So now look
  8457. 4:47:21at this. Our dimension date is actually
  8458. 4:47:23a big shared dimension between a lot of
  8459. 4:47:25facts. Now this is amazing because now
  8460. 4:47:28we can do a lot of analyzes side by side
  8461. 4:47:30from all those facts. Let me just show
  8462. 4:47:32you an example. Let's go to the report
  8463. 4:47:34view. Don't know how we're going to do
  8464. 4:47:35it now. Very important as usual in order
  8465. 4:47:37to build the visual we start first from
  8466. 4:47:40the dimension. So the dimension date
  8467. 4:47:42this is going to build the axis for our
  8468. 4:47:44visual. And then after that we start
  8469. 4:47:46picking the measures from the different
  8470. 4:47:47facts like for example the fact sales.
  8471. 4:47:50We can go and now grab the total sales
  8472. 4:47:52and put it in the view. Perfect. Now we
  8473. 4:47:54can go to another one. For example the
  8474. 4:47:56fact sales target. This one going to be
  8475. 4:47:58on the month level. So the visual going
  8476. 4:48:00to looks weird but we can fix it if we
  8477. 4:48:02just remove the day from our date so
  8478. 4:48:04that everything is on the month level.
  8479. 4:48:07Now we can go to a third fact like for
  8480. 4:48:09example the inventories. Let's go and
  8481. 4:48:11drop the stocks or the units. This is
  8482. 4:48:14exactly my friends the power of the
  8483. 4:48:15dimension dates. We can go now and visit
  8484. 4:48:18all the facts and compare things side by
  8485. 4:48:20side very easily without losing the
  8486. 4:48:22numbers. Like you can see here the total
  8487. 4:48:24sales is always protected and you can do
  8488. 4:48:27now a lot of correlations and
  8489. 4:48:29comparison. So this is the main job of
  8490. 4:48:31the dimension date inside our data
  8491. 4:48:33model. Now of course what else we can do
  8492. 4:48:35with the dimension date? We can use it
  8493. 4:48:36in order to do roleplaying dimension.
  8494. 4:48:39Like for example we have here a huge
  8495. 4:48:40fact table with a lot of dates. Right?
  8496. 4:48:43So we have the order date, the invoice
  8497. 4:48:45date, the pay date. Now we can go and
  8498. 4:48:47connect our new dimension multiple times
  8499. 4:48:49to this fact. Let me show you how to do
  8500. 4:48:51it. So let me just bring this fact here.
  8501. 4:48:53And now we just grab the date to the
  8502. 4:48:56different columns. Like for example here
  8503. 4:48:58the pay date of course this going to be
  8504. 4:49:00inactive. Then one more time for the
  8505. 4:49:02ship date and another one for the
  8506. 4:49:04invoice date. And I think the last one
  8507. 4:49:06going to be the delivery date. So look
  8508. 4:49:08at this. Our dimension date is playing
  8509. 4:49:10five different roles for this fact. But
  8510. 4:49:12of course you're going to do this only
  8511. 4:49:14if you really need it. Otherwise this
  8512. 4:49:16going to looks really ugly. So don't go
  8513. 4:49:18randomly like connecting the date for
  8514. 4:49:20every column. Sometimes we don't really
  8515. 4:49:22need it like for example if I'm just
  8516. 4:49:24like analyzing the sales I don't really
  8517. 4:49:27always to go and get the dimension date
  8518. 4:49:29so actually I can go and build the
  8519. 4:49:31visual completely based on the fact
  8520. 4:49:33sales I have there the order date I have
  8521. 4:49:35everything so if your analyzis is based
  8522. 4:49:37only on one fact table then we don't
  8523. 4:49:39really need the dimension date but only
  8524. 4:49:41if you are like comparing multiple fact
  8525. 4:49:44then we go to the dimension of course
  8526. 4:49:46and with that my friends means we don't
  8527. 4:49:48have to go crazy and connect the
  8528. 4:49:49dimension date every single single date
  8529. 4:49:51column that we have in the data model
  8530. 4:49:53only if it's needed and if you create
  8531. 4:49:55something like this then you have to go
  8532. 4:49:56and start like building DAX calculations
  8533. 4:49:59for each inactive relationship so that
  8534. 4:50:01you can use it actually in your reports
  8535. 4:50:03but if it is not needed then don't go
  8536. 4:50:06and create all those relations now our
  8537. 4:50:08dimension date looks crazy and this is
  8538. 4:50:10usually how this dimension looks like at
  8539. 4:50:13the end so my friends this is the topic
  8540. 4:50:14of the dimension date I usually do it at
  8541. 4:50:16the end just to have a big picture first
  8542. 4:50:18about all my fact tables and only then
  8543. 4:50:21at the end I go and connect the
  8544. 4:50:23dimension date. Okay. So now we come to
  8545. 4:50:24very important step in data moduling
  8546. 4:50:26that a lot of people actually skip at
  8547. 4:50:28this phase. We have to go and create the
  8548. 4:50:29measures. Now the thing is yes we have a
  8549. 4:50:31good star schema we have good structure
  8550. 4:50:34everything is connected correctly the
  8551. 4:50:35filter direction and all those stuff.
  8552. 4:50:37But now if you go and hand this over to
  8553. 4:50:39your project team and everyone start
  8554. 4:50:41like building on top of it reports and
  8555. 4:50:43visuals. Now what could happen is that
  8556. 4:50:45multiple people going to go and start
  8557. 4:50:46creating multiple versions of
  8558. 4:50:48calculations that actually are
  8559. 4:50:50calculating the same thing over and over
  8560. 4:50:52and nobody going to know which one is
  8561. 4:50:54the right one for the data model. Now
  8562. 4:50:56another thing that might happen is that
  8563. 4:50:58people that are working with the data
  8564. 4:50:59model they might not yet develop like
  8565. 4:51:02understanding of the grains of your
  8566. 4:51:04facts. So for example they might go to
  8567. 4:51:05the fact sales and say you know what I
  8568. 4:51:07have to go and calculate the total
  8569. 4:51:09number of orders. So they go and create
  8570. 4:51:10calculation where they're going to count
  8571. 4:51:12the order ids which is totally wrong.
  8572. 4:51:14The green there is the line of order. So
  8573. 4:51:17in order to do it correctly they have to
  8574. 4:51:19do count distinct on the order ID. That
  8575. 4:51:21means this going to lead to wrong number
  8576. 4:51:23even if the data model is perfect. So
  8577. 4:51:25that means in this phase our job is not
  8578. 4:51:27only to structure and build a perfect
  8579. 4:51:29star schema but as well we have to go
  8580. 4:51:31and prepare the measures side by side
  8581. 4:51:34with our data model just to make sure
  8582. 4:51:36that we reduce the confusion. And of
  8583. 4:51:38course I'm not saying here we have to go
  8584. 4:51:39and now create all the measures for
  8585. 4:51:42everything that we have in the data
  8586. 4:51:43model. We just have to go and create the
  8587. 4:51:45core measurements but think that we are
  8588. 4:51:47sure it's going to be reused over and
  8589. 4:51:49over in many reports. And by the way not
  8590. 4:51:51everyone is working in teams. If you are
  8591. 4:51:53solo data analyst this is as well good
  8592. 4:51:55for you. I'm pretty sure over the time
  8593. 4:51:56you're going to have like multiple
  8594. 4:51:57PowerBI projects and you're going to
  8595. 4:51:59forget about the grains and the data
  8596. 4:52:00model. So you protect yourself making
  8597. 4:52:03different versions of calculations and
  8598. 4:52:05as well making wrong calculations. So my
  8599. 4:52:07friends this is exactly what we have to
  8600. 4:52:08do now. We have to go and create a
  8601. 4:52:10bundle of measures. All right. So now
  8602. 4:52:12how we going to do it? There's like two
  8603. 4:52:13ways. Either you're going to go to each
  8604. 4:52:15fact and inside them you're going to
  8605. 4:52:16start create the individual measures or
  8606. 4:52:19there is like another way that I like to
  8607. 4:52:20do and many others as well is to go and
  8608. 4:52:23bundle let's say the major measurements
  8609. 4:52:25inside one fake table. Let me show you
  8610. 4:52:28how to do it. So we're going to go over
  8611. 4:52:29here and say okay new table. Now I'm
  8612. 4:52:31going to call it underscore in order to
  8613. 4:52:33have it at the top. Then measures equal
  8614. 4:52:36nothing. With this we got like an empty
  8615. 4:52:38table here on the top. And now inside it
  8616. 4:52:40we're going to go and start creating all
  8617. 4:52:42the measures of the data model. So
  8618. 4:52:44that's during creating the reports
  8619. 4:52:45you're going to have it all in one place
  8620. 4:52:47and it's going to be easy to go and drag
  8621. 4:52:48and drop stuff. And if you want to
  8622. 4:52:50update your measures, you go directly
  8623. 4:52:51here and start updating. So now this is
  8624. 4:52:53our new measure that we have. Of course
  8625. 4:52:55we will not connect it to anything. I'm
  8626. 4:52:57just going to go and move it here side
  8627. 4:52:58by side with the security so that we can
  8628. 4:53:01see okay this is my star schema and
  8629. 4:53:02those are the let's say the add-ons on
  8630. 4:53:04top of it. Now let's go to the maybe
  8631. 4:53:07report view and create a new tab. I'll
  8632. 4:53:09just start now and create like few major
  8633. 4:53:11measures inside our data model. So let's
  8634. 4:53:14start with the fact sales like for
  8635. 4:53:15example here it's very obvious that's
  8636. 4:53:17one of the major measures it is the
  8637. 4:53:19total sales right. So how we going to do
  8638. 4:53:21it? We're going to go to the measures
  8639. 4:53:22over here and right click on it and say
  8640. 4:53:24new measure. Then we just create like
  8641. 4:53:26very simple DAX calculations. So for
  8642. 4:53:27example total sales equal to the sum of
  8643. 4:53:31the fact table sales and now you pick
  8644. 4:53:34the column. So line total and actually
  8645. 4:53:36that's it. Now what we do actually after
  8646. 4:53:39that we decide like on the format of
  8647. 4:53:41this measure like for example I'm going
  8648. 4:53:42to have the thousand like separator.
  8649. 4:53:44Actually I don't want it as a decimal
  8650. 4:53:46number. So I just want it always to be a
  8651. 4:53:48whole number so that everything is
  8652. 4:53:50formatted and is ready in order to be
  8653. 4:53:52used in my reports. So now by just drag
  8654. 4:53:54and drop from this measure I'm going to
  8655. 4:53:55get the total sales without worrying
  8656. 4:53:58about how this is calculated. So that
  8657. 4:54:00was an obvious thing. Then we have to
  8658. 4:54:02keep thinking okay what could we
  8659. 4:54:03measure? Well very important the total
  8660. 4:54:06number of orders. So we're going to go
  8661. 4:54:07and create a new measure total orders
  8662. 4:54:10equal. Now we want to count how many
  8663. 4:54:12orders that we have in the business. So
  8664. 4:54:14we're going to say okay count but again
  8665. 4:54:16since the grain is line of total we're
  8666. 4:54:17going to go and use the distinct count
  8667. 4:54:20and we're going to say okay fact sales
  8668. 4:54:22the order ID. So actually that's it. Now
  8669. 4:54:24of course we can think about how we're
  8670. 4:54:26going to format it. So it's going to be
  8671. 4:54:27as well the thousand's going to be
  8672. 4:54:29separated and it is a whole number which
  8673. 4:54:31is correct. So if I go drag and drop
  8674. 4:54:33same thing I got that total number of
  8675. 4:54:35orders which is correct. So as you can
  8676. 4:54:37see this is the whole job. We're going
  8677. 4:54:38to go through all the facts one by one
  8678. 4:54:39and we start creating those measures.
  8679. 4:54:42But we have just to focus on the main
  8680. 4:54:43things that we are sure that's going to
  8681. 4:54:45be used in many reports. Like for
  8682. 4:54:47example, we can go and count the total
  8683. 4:54:49number of active customers. So there is
  8684. 4:54:51like a difference between all the
  8685. 4:54:52customers that we have inside the data
  8686. 4:54:54model. For that we can go and count it
  8687. 4:54:56from the dimension customer. But if you
  8688. 4:54:58want to know how many customers are
  8689. 4:55:00actually ordering things, then you have
  8690. 4:55:02to go to the fact sales. So we can go
  8691. 4:55:04over here and say okay new measure total
  8692. 4:55:06active customers equal as well distinct
  8693. 4:55:10count because we're going to go to the
  8694. 4:55:12fact table. So fact sales and here we
  8695. 4:55:15need the customer ID. So this is the
  8696. 4:55:18count from the fact. Now we can go and
  8697. 4:55:20create another one that is actually
  8698. 4:55:22counting from the dimension. So base
  8699. 4:55:25maybe total customers equal. This time
  8700. 4:55:28we can just go and use the count for the
  8701. 4:55:30dimension because we don't have
  8702. 4:55:31duplicates. dimension customer and here
  8703. 4:55:34we pick as well the ID over here same
  8704. 4:55:36thing if you have a lot of customers you
  8705. 4:55:38can go and start like separating things
  8706. 4:55:39with a th00and now what else we can do
  8707. 4:55:42we can go to another fact like for
  8708. 4:55:43example here we have the fact order
  8709. 4:55:45process we can go and calculate the
  8710. 4:55:47average number of days from the first
  8711. 4:55:49step to the last step so now how we
  8712. 4:55:51going to do this measure first we have
  8713. 4:55:53to go and create maybe a column let me
  8714. 4:55:55just go back over here to the table view
  8715. 4:55:57so look at this we have all the steps
  8716. 4:55:58and I would like to go and calculate how
  8717. 4:56:00many days that we have between in the
  8718. 4:56:02first step the order date and the last
  8719. 4:56:04step the pay date and with that we're
  8720. 4:56:05going to get like a new measure for this
  8721. 4:56:07fact and in top of it we're going to go
  8722. 4:56:09and create a new calculation. So let's
  8723. 4:56:11go and do that. First of all we need a
  8724. 4:56:12new column because we need calculation
  8725. 4:56:14on the row level. So for example this
  8726. 4:56:17going to be order to pay. Now we just
  8727. 4:56:19want to find the differences between two
  8728. 4:56:21dates. So there is a function called
  8729. 4:56:23date diff. The first date is the order
  8730. 4:56:25date. The second one is the last one. So
  8731. 4:56:27it's going to be the pay date. And what
  8732. 4:56:29is the difference? We are calculating
  8733. 4:56:30how many days not month or year. So this
  8734. 4:56:33is the part that we are interesting in.
  8735. 4:56:35And actually that's it. So look at this.
  8736. 4:56:37Now we are getting the total number of
  8737. 4:56:39days that it took from the order to the
  8738. 4:56:41payment. Now the next step is very
  8739. 4:56:43simple. We're going to go and create a
  8740. 4:56:44new measure in our collection where
  8741. 4:56:46we're going to say like for example
  8742. 4:56:48average order to pay equal average. Then
  8743. 4:56:52we just go and pick our new measure. So
  8744. 4:56:54it is the order to pay. So look at this.
  8745. 4:56:56Now we have another measure based on
  8746. 4:56:58another fact. But everything now
  8747. 4:57:00together. So now if you are building a
  8748. 4:57:01report, all what you have to do is to
  8749. 4:57:03just go and open this one and start
  8750. 4:57:04browsing all the measures of this data
  8751. 4:57:07model. But of course again you don't
  8752. 4:57:08have to go and sit and think about each
  8753. 4:57:10single detail. Just create the obvious
  8754. 4:57:13one. Okay. Now I'm going to say for now
  8755. 4:57:14I'm going to stick with this. This is a
  8756. 4:57:16good collection of measures that we can
  8757. 4:57:18hand over together with the data model.
  8758. 4:57:25[music] All right friends, now we are
  8759. 4:57:26getting very close. We have now the last
  8760. 4:57:28step in the last phase. We have to make
  8761. 4:57:30sure that our data model is secure. So
  8762. 4:57:32that means we have to go and apply the
  8763. 4:57:34role level security mechanism on top of
  8764. 4:57:36our data model. Let's go and do that.
  8765. 4:57:38Okay. So now again we have our star
  8766. 4:57:40schema. We have those measures and the
  8767. 4:57:43last add-on that we have to add is the
  8768. 4:57:45security. Now first of all to make sure
  8769. 4:57:47that the security is ready we have to go
  8770. 4:57:49back to the power query and make sure
  8771. 4:57:51that everything there is ready and
  8772. 4:57:53clean. Okay. So this going to be our
  8773. 4:57:55last table inside the stage the
  8774. 4:57:57security. Now quickly by looking to this
  8775. 4:57:59you can see the header informations are
  8776. 4:58:01not correct. So this should be the
  8777. 4:58:03columns and yes we still have to follow
  8778. 4:58:05the naming convention. So I'm going to
  8779. 4:58:06go and rename things. This is the user
  8780. 4:58:09email and this is my friend the region.
  8781. 4:58:12All right. Now the last step is that I'm
  8782. 4:58:13going to go and grab it actually to the
  8783. 4:58:15other supports. So with that I don't
  8784. 4:58:17have anything more in the stage that I
  8785. 4:58:19have to work on. Look at this. We have
  8786. 4:58:20here the dimensions. We have the facts
  8787. 4:58:22and the support going to be the security
  8788. 4:58:24table since it doesn't belong to those
  8789. 4:58:26two. All right, let's close and apply.
  8790. 4:58:28All right, now look at this. It start
  8791. 4:58:30connects to our data model. But I have
  8792. 4:58:32to make sure that it is correct. So
  8793. 4:58:34let's go and just remove it. So we
  8794. 4:58:36didn't need this relationship. And about
  8795. 4:58:38this one is actually correct. So now
  8796. 4:58:40again let's first understand the
  8797. 4:58:42security that we have here. So let's
  8798. 4:58:43just talk about it. This is the
  8799. 4:58:45security. Look at this. Here we have the
  8800. 4:58:47user email addresses. Those are the
  8801. 4:58:49employees of our business. and it looks
  8802. 4:58:51like they are assigned to specific
  8803. 4:58:52regions. Now, of course, in order to
  8804. 4:58:54build this, we have to talk to the
  8805. 4:58:56security officers of our company and
  8806. 4:58:58understand how the security works. They
  8807. 4:59:00might say, you know what, each employee
  8808. 4:59:02in our company is allowed to see only
  8809. 4:59:04specific region. Like for example, Nora
  8810. 4:59:06can see only the North America. She is
  8811. 4:59:08not allowed to see the sales that are
  8812. 4:59:10happening in Europe or Middle East. Same
  8813. 4:59:13thing for hands. Hans can see only
  8814. 4:59:14Europe sales. So, we have to understand
  8815. 4:59:16the security requirements before we
  8816. 4:59:18start like connecting things. So we
  8817. 4:59:20cannot go blindly like making a security
  8818. 4:59:22concept for the data model and only
  8819. 4:59:24after understanding then we can start
  8820. 4:59:26connecting things together and then of
  8821. 4:59:28course the next step is to think okay
  8822. 4:59:30where are the region informations in
  8823. 4:59:32which facts in which dimensions we can
  8824. 4:59:34see that of course it is very obvious if
  8825. 4:59:36you go to the dimension customers you're
  8826. 4:59:38going to find over here the region
  8827. 4:59:39information. So this is a very good
  8828. 4:59:41starting point. Of course the question
  8829. 4:59:43is how we going to connect this security
  8830. 4:59:45to our data model and we usually do it
  8831. 4:59:48on top of dimensions because dimensions
  8832. 4:59:50anyway go and filter the fact tables and
  8833. 4:59:52the security table going to be filtering
  8834. 4:59:54this dimension. Now it's very obvious
  8835. 4:59:56that we have the dimension customer
  8836. 4:59:58where we have the region over here. So
  8837. 5:00:00this is a perfect candidate where we're
  8838. 5:00:01going to connect our security on top of
  8839. 5:00:03this so that the user can see only
  8840. 5:00:06specific customers and this will be
  8841. 5:00:08filtering as well our facts. So this is
  8842. 5:00:11one way on how to create the security.
  8843. 5:00:13There is another way on how to do it is
  8844. 5:00:15to go to the geographic dimension as
  8845. 5:00:17well. Here we have regions and this one
  8846. 5:00:19is connecting as well directly to our
  8847. 5:00:21fact which is really as well good
  8848. 5:00:23candidate that we could use in order to
  8849. 5:00:25filter our data model based on the
  8850. 5:00:27security. Now how we going to decide on
  8851. 5:00:28this? Usually I do it like this. I go
  8852. 5:00:30back to the data model and look to those
  8853. 5:00:32two dimensions. So I can see here for
  8854. 5:00:34example let me zoom in. This is the geo
  8855. 5:00:36dimension and you can see it is
  8856. 5:00:38connected to the fact sales. So now if I
  8857. 5:00:40put the security on top of this it going
  8858. 5:00:42to go and filter only one fact table.
  8859. 5:00:45But now the other one the dimension
  8860. 5:00:47customer it is actually connected to two
  8861. 5:00:49facts. The fact sales and the fact order
  8862. 5:00:52process. So if I connect the security on
  8863. 5:00:54top of this, I'm going to benefit in
  8864. 5:00:55order to secure actually two facts,
  8865. 5:00:57which is of course a nice thing. So I'm
  8866. 5:00:59going to go and decide actually on
  8867. 5:01:01connecting the security on top of the
  8868. 5:01:03dimension customers just because it
  8869. 5:01:05secures more facts for me. But again
  8870. 5:01:07based on the requirements we have to do
  8871. 5:01:09those stuff and now I saw like some
  8872. 5:01:11weird scenarios where people go and say
  8873. 5:01:13you know what I want to secure the whole
  8874. 5:01:15data model without any reason. So they
  8875. 5:01:17start like forcing somehow the data
  8876. 5:01:19model to use the security table on top
  8877. 5:01:21of each facts. So they start like doing
  8878. 5:01:24crazy things like by merging the facts
  8879. 5:01:26just in order to get the region column
  8880. 5:01:29inside each fact and they destroy the
  8881. 5:01:31grain because of this just to add the
  8882. 5:01:33security at the end. Maybe this is
  8883. 5:01:35totally unnecessary. So always
  8884. 5:01:37understand the security requirements and
  8885. 5:01:39only apply it when it's needed. You
  8886. 5:01:40don't have to secure every single
  8887. 5:01:42dimension and fact. Like for example, is
  8888. 5:01:44it really bad to show the dimension
  8889. 5:01:46products for all our employees? I think
  8890. 5:01:48it is no harm if they see the whole
  8891. 5:01:50data. So that means for our project,
  8892. 5:01:52let's say that we're going to apply the
  8893. 5:01:53security on top of those two facts, the
  8894. 5:01:56sales and the orders. So now how we
  8895. 5:01:58going to do it? It's going to be very
  8896. 5:01:58simple. We're going to go and build a
  8897. 5:02:00relationship between the security and
  8898. 5:02:02the dimension. So we're going to go over
  8899. 5:02:03here and say, okay, region by region,
  8900. 5:02:06one to many relationship, and the filter
  8901. 5:02:08is single direction. We have to make
  8902. 5:02:10sure it is going in the right direction,
  8903. 5:02:12of course. Well, yes. Look at this. The
  8904. 5:02:14filter direction of the security is
  8905. 5:02:16going to the dimension and the filter
  8906. 5:02:18direction of the customers is going to
  8907. 5:02:20both the fact sales and the fact order
  8908. 5:02:22process. So this looks perfect for
  8909. 5:02:24security. Of course the next step is
  8910. 5:02:26that we're going to go and start
  8911. 5:02:27creating the manage rules. Otherwise
  8912. 5:02:30this will not work. So it's going to be
  8913. 5:02:31very simple. We're going to go and
  8914. 5:02:32create a new role. Let's go and call it
  8915. 5:02:34regional access. And of course in which
  8916. 5:02:36table we are building the security. It's
  8917. 5:02:38going to be on the dimension customer.
  8918. 5:02:40and we're going to write a DAX
  8919. 5:02:41calculation in order to secure it. So
  8920. 5:02:43we're going to go and switch to DAX.
  8921. 5:02:45Okay. So this is going to be very
  8922. 5:02:46simple. We are just writing the DAX
  8923. 5:02:48filter expression where we're going to
  8924. 5:02:49say okay I want to show only the rows
  8925. 5:02:52where the region is matching the user
  8926. 5:02:54region. So that means it has to go and
  8927. 5:02:56find up what is the region for our
  8928. 5:02:59current user. So it is inside the
  8929. 5:03:01security table the region. then it
  8930. 5:03:03should match the email address that we
  8931. 5:03:05have in the security with the user
  8932. 5:03:07whoever is opening the PowerBI reports
  8933. 5:03:10and for that we have a nice function the
  8934. 5:03:12user principle name. So very simple
  8935. 5:03:14thing so it is not that hard we are
  8936. 5:03:16saying just check each row and ask this
  8937. 5:03:19question does the region belong to the
  8938. 5:03:21person that is looking at the report if
  8939. 5:03:24yes then keep the row otherwise go and
  8940. 5:03:26drop it. So it is just a filter
  8941. 5:03:28expression that going to help us to
  8942. 5:03:29filter the rows based on the region. Of
  8943. 5:03:32course actually that's it. Let's go and
  8944. 5:03:34save it. Very important that we are
  8945. 5:03:35getting green. Now let's go and close
  8946. 5:03:37it. All right. So with this we have
  8947. 5:03:38applied the role of the security on top
  8948. 5:03:40of our data model. But of course we
  8949. 5:03:42don't trust until we test. So how we
  8950. 5:03:44going to test it? I need one email like
  8951. 5:03:46one of the employees. So for example
  8952. 5:03:48Nora I'm going to go and copy its value.
  8953. 5:03:50Then go back to the model. And now we
  8954. 5:03:52can try to view the model as Nora is
  8955. 5:03:54opening the report and seeing it. How to
  8956. 5:03:56do it? We can go over here and say view
  8957. 5:03:59as then we have to specify the rule that
  8958. 5:04:01we just created. So the regional access
  8959. 5:04:03and we want to see it as another user
  8960. 5:04:06not as par because otherwise it's going
  8961. 5:04:07to take the informations of my users but
  8962. 5:04:09we want to see it as Nura. Okay. So
  8963. 5:04:12let's set okay. Then you can see we're
  8964. 5:04:13going to get like a warning. The
  8965. 5:04:15original access is activated and we are
  8966. 5:04:17viewing the object as Nora email. So now
  8967. 5:04:19let's go and test. Look at this. We are
  8968. 5:04:22already seeing like less details than
  8969. 5:04:24before. So the total sales is not
  8970. 5:04:26anymore the total number of sales of the
  8971. 5:04:28whole data model and we are seeing only
  8972. 5:04:30the total sales that is based on their
  8973. 5:04:33Nora's region. Of course we can test
  8974. 5:04:34this as well by going to the dimension
  8975. 5:04:37customer and let's go and grab the
  8976. 5:04:39region. So you can see we are seeing
  8977. 5:04:40only the North America. So my friends
  8978. 5:04:42that means the dimension is working. The
  8979. 5:04:44fact table is as well working and of
  8980. 5:04:46course the last test. Let's go and
  8981. 5:04:48remove this effect. So if I stop
  8982. 5:04:50viewing, look at this. Suddenly I'm
  8983. 5:04:52going to see the total sale for
  8984. 5:04:54everything and as well I'm going to see
  8985. 5:04:55all the regions. Of course now you can
  8986. 5:04:57go and pick another email and test that.
  8987. 5:04:59But for me it is already working and we
  8988. 5:05:01have applied the roll security on top of
  8989. 5:05:04our data model. All right friends, oh my
  8990. 5:05:06god I can say that we are done. We made
  8991. 5:05:08it. Just sit back, look at this and
  8992. 5:05:10enjoy it because this is awesome. And
  8993. 5:05:13remember at the very beginning I showed
  8994. 5:05:14you this beautiful chaos and the
  8995. 5:05:16nightmare data model where we had the
  8996. 5:05:18many to many relationships everywhere.
  8997. 5:05:20The filters are going from one table to
  8998. 5:05:22another just in all directions. No star
  8999. 5:05:25schema nothing makes sense full chaos.
  9000. 5:05:28But now look back to this. We have clean
  9001. 5:05:30healthy star schema or let's say galaxy
  9002. 5:05:32where we have fact tables and surrounded
  9003. 5:05:34with dimensions. Every relationship and
  9004. 5:05:37every filter is going to the right
  9005. 5:05:38direction. The numbers are protected and
  9006. 5:05:41everything is friendly and easy to read.
  9007. 5:05:43And I can tell you this one was not an
  9008. 5:05:45easy one. That was a really hard project
  9009. 5:05:47and complicated. And if you stayed until
  9010. 5:05:49the end and you build exactly this data
  9011. 5:05:51model with me, then my friend, you
  9012. 5:05:53should be proud of yourself. And I can
  9013. 5:05:54say welcome to the club with this, you
  9014. 5:05:56went with me through the journey exactly
  9015. 5:05:58like I do in my projects in my
  9016. 5:06:00companies. And I can tell you over all
  9017. 5:06:02projects I just met like only few people
  9018. 5:06:04that have this kind of skills where they
  9019. 5:06:07can turn a chaos data model into a clean
  9020. 5:06:09one because most people actually don't
  9021. 5:06:11know how to do data modeling and they
  9022. 5:06:13skip it. But my friends, we are not one
  9023. 5:06:15of them. We are the expert that can
  9024. 5:06:17build a real data model and this is
  9025. 5:06:19really a rare skill that many companies
  9026. 5:06:21need. So what I really recommend you is
  9027. 5:06:23to go and make this project as your
  9028. 5:06:25portfolio project. Of course feel free
  9029. 5:06:27to use it as your project. So go and
  9030. 5:06:29share it as well with the others in
  9031. 5:06:30LinkedIn and you can tag me if you want.
  9032. 5:06:32But what is way more important than
  9033. 5:06:34this, if you are searching for job and
  9034. 5:06:35you got interviewed, make sure to talk
  9035. 5:06:37about this project because this is
  9036. 5:06:39really rare. It going to makes you
  9037. 5:06:40quickly stand out the crowd. And if you
  9038. 5:06:42got hired or you are already at the
  9039. 5:06:44company and you joined a new project
  9040. 5:06:46where they have exactly the data model,
  9041. 5:06:48the chaos that I showed you at the
  9042. 5:06:49start, what's going to happen this time?
  9043. 5:06:51You will not panic. You're going to look
  9044. 5:06:52at it and smile because you're going to
  9045. 5:06:54remember exactly this project and you
  9046. 5:06:56know what to do. So now before we close
  9047. 5:06:58this project I would like to go through
  9048. 5:07:00all the most important points that we
  9049. 5:07:02have learned during the data modeling.
  9050. 5:07:04So let's recap the first point before
  9051. 5:07:06you build anything always take time to
  9052. 5:07:09analyze explore and understand. You have
  9053. 5:07:11to understand the business the processes
  9054. 5:07:13the data. The more you invest in
  9055. 5:07:15exploring the data and understanding the
  9056. 5:07:17business the easier things going to be
  9057. 5:07:19during building the data model. Then the
  9058. 5:07:21second point, always understand the
  9059. 5:07:23grain of your tables, dimensions and
  9060. 5:07:25facts and say it loudly what each row is
  9061. 5:07:27representing. Once you know that you
  9062. 5:07:29will not make mistakes as you are
  9063. 5:07:31connecting tables. Third point, always
  9064. 5:07:33set rules and standards before you start
  9065. 5:07:35the projects and always follow them
  9066. 5:07:37until the end. All the naming
  9067. 5:07:38conventions, the prefixes and so on.
  9068. 5:07:40Rule number four, always remove the
  9069. 5:07:42unnecessary data from the data model.
  9070. 5:07:45This is very important. Always ask, do
  9071. 5:07:47we really need those informations for
  9072. 5:07:49reporting? Is it really necessary? Never
  9073. 5:07:51be the person that's going to leave
  9074. 5:07:53things just in case. And the next one,
  9075. 5:07:55our goal is always to build the star
  9076. 5:07:57schema. All BI projects love that.
  9077. 5:07:59You're just going to make your life
  9078. 5:08:00easier with the calculations. And of
  9079. 5:08:02course, always avoid connecting fact
  9080. 5:08:04tables together. Just use a shared
  9081. 5:08:05dimension in between. And the filter
  9082. 5:08:07directions are always from the
  9083. 5:08:09dimensions to the facts. So my friends,
  9084. 5:08:11that's it. Yes, this is the whole
  9085. 5:08:12project. I really enjoyed making this
  9086. 5:08:14project. For a while, I thought that I'm
  9087. 5:08:16working at a company. I'm not recording
  9088. 5:08:18a video and I'm talking to a colleague.
  9089. 5:08:20I really had a lot of fun making this
  9090. 5:08:22project. I really enjoyed it. Now it's
  9091. 5:08:24time for you. So you have to go and
  9092. 5:08:25practice on your own. Maybe go and grab
  9093. 5:08:27any data model or your own data. Try to
  9094. 5:08:30make a healthy data model out of it. So
  9095. 5:08:32that's it my friends. I hope you enjoyed
  9096. 5:08:34this project with me. If yes, then
  9097. 5:08:36support the channel by subscribing,
  9098. 5:08:37liking, and commenting. Share it with
  9099. 5:08:39the others in order to reach nice people
  9100. 5:08:41like you. And I'm going to say thank you
  9101. 5:08:43so much for watching and I'm going to
  9102. 5:08:44see you in the next project. Bye-bye. At
  9103. 5:08:46you later, warehouse. See you on the
  9104. 5:08:49flippity flip.

About this transcript

This page contains the full transcript of Data Modeling in Power BI Full Course for Beginners (5 Hours) – From Zero to Hero by Data with Baraa, generated from the public captions YouTube serves with the video. The transcript has 67,962 words across 9,104 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.