YouTube2Text

Learn 80% of DAX in an Hour (with FREE sample file) — Transcript

by Chandoo · 10,663 words · 1,470 segments · language en · Watch on YouTube

Full transcript

  1. 0:00one of the most frustrating things when
  2. 0:02it comes to learning powerb is
  3. 0:04understanding and effectively using the
  4. 0:06Dax
  5. 0:08language this is a problem that I had
  6. 0:10when I started learning powerbi many
  7. 0:12years ago so in this video let me
  8. 0:16distill the 80% of the Practical Dax
  9. 0:19when it comes to data analysis and
  10. 0:21business intelligence reporting work
  11. 0:24these are all the concepts that we are
  12. 0:26going to cover in this video and by the
  13. 0:28end of this video you will be able to
  14. 0:32understand what Dax is how to use it to
  15. 0:35problem solve given a business
  16. 0:37requirement towards the end of this
  17. 0:40video I'm also going to talk about a
  18. 0:43proprietary almost trademarked ACM Buu
  19. 0:47Aku approach of using Dax more on that
  20. 0:52later let's go here is my powerbi
  21. 0:54workbook I have provided a copy of this
  22. 0:57file as well as the blank data set if
  23. 0:59you want to build the whole data model
  24. 1:01yourself I explained how this data model
  25. 1:04is constructed in the previous video
  26. 1:07essentially this is a data model for a
  27. 1:09madeup chocolate company called awesome
  28. 1:12chocolates and here we have got five
  29. 1:14tables let me show you the semantic or
  30. 1:16the data model
  31. 1:18quickly so here is the data model that
  32. 1:21we are using we have got chocolate
  33. 1:22shipments in the fact table at the
  34. 1:24center of this model and we have got
  35. 1:27four dimensions neatly laid out in the
  36. 1:31star schema pattern here normally for
  37. 1:34the Str sake of laying things out you
  38. 1:36may want to set them up like this kind
  39. 1:38of a octopus or a star schema setup but
  40. 1:42more from a maintenance perspective it
  41. 1:44might be just a good idea to keep all
  42. 1:47the dimension tables on one side of the
  43. 1:49screen like up
  44. 1:51top and move the fact tables to the
  45. 1:54bottom this way if you have if your
  46. 1:56model ever gets too big you will always
  47. 1:58know what is a d Di menion and what is a
  48. 2:00fact dimensions are always up
  49. 2:03top and fact is at the bottom and from
  50. 2:06the dimension the filters move to fact
  51. 2:09that's why the arrows always Point
  52. 2:11towards the fact so you can see that if
  53. 2:13you were to filter for example by a
  54. 2:15specific
  55. 2:16salesperson their details are shown here
  56. 2:19in the shipments table more on this
  57. 2:22later but for now this is how our model
  58. 2:25looks like again a quick reminder a copy
  59. 2:28of this file is a aailable in the video
  60. 2:30description the blank file download it
  61. 2:33and follow along with me as you practice
  62. 2:36taxs as this video can get pretty
  63. 2:38intense I highly recommend setting some
  64. 2:40time aside to go through this whole
  65. 2:42thing in one setting for best
  66. 2:44results now let's go and add a new page
  67. 2:47this page is something that we built in
  68. 2:49the previous exercise where I explained
  69. 2:51how we have constructed that particular
  70. 2:53data
  71. 2:54model so here we're going to start our
  72. 2:57concepts with essential data
  73. 3:03Dax what is Dax Dax is the language that
  74. 3:07is used to calculate things in powerbi
  75. 3:10or more importantly in power pivot Dax
  76. 3:14stands for data analysis Expressions you
  77. 3:17might think why doesn't it call why
  78. 3:20don't they call it D Dae because data
  79. 3:23analysis Expressions but I don't know
  80. 3:26they went and called it
  81. 3:28Dax just as the
  82. 3:30acronym is confusing some of the Dax
  83. 3:32logic and measures and the way we work
  84. 3:34with it is also a little bit confusing
  85. 3:36especially when you start learning it so
  86. 3:39that's why it is important to get the
  87. 3:40fundamentals right and that's my purpose
  88. 3:42of making this
  89. 3:44video so we have got all of these tables
  90. 3:47here and in this previous page here we
  91. 3:50were able to see for example how much is
  92. 3:53the total amount by a product to do this
  93. 3:56what we did is we put product onto this
  94. 3:59axis of the column chart and amount into
  95. 4:02this area or vertical axis or Y axis of
  96. 4:05the thing as amount is a numeric column
  97. 4:08if I look at my shipments table I have
  98. 4:10seen that amount is a number column the
  99. 4:13moment I put that into the y axis here
  100. 4:17powerbi automatically did a sum of
  101. 4:19amount that means it is summing it up we
  102. 4:22could for example click on this here and
  103. 4:24use this summarization option there to
  104. 4:28change it from sum to minimum maximum
  105. 4:31count or average or
  106. 4:33median this does offer you a quick and
  107. 4:37easy way to customize some of the
  108. 4:39calculations but the problem with this
  109. 4:41is this is quite limited and you can't
  110. 4:43really do much when you actually want to
  111. 4:46analyze the data and produce some sort
  112. 4:48of a business intelligence or deep
  113. 4:50insights into your data and that is
  114. 4:53where Dax offers a structured framework
  115. 4:56to talk to your data ask business
  116. 4:59questions and get the results so it
  117. 5:01gives you a language and a framework to
  118. 5:03do all of this we are going to do that
  119. 5:05from now on so the calculations that are
  120. 5:08produced by Dax they're usually called
  121. 5:10as measures and we are going to write
  122. 5:14our first measure and eventually
  123. 5:15everything starts to click in so our
  124. 5:17first measure is to pretty much
  125. 5:19replicate what we are seeing here we
  126. 5:21want to understand what is the total
  127. 5:23amount some amount and then be able to
  128. 5:25see it at a product level so I'm going
  129. 5:28to go to a new page doesn't matter
  130. 5:30whether you do it in that page or here
  131. 5:32but uh we going to keep it clean by
  132. 5:34building it in this page to create a new
  133. 5:36measure you can go and click on many
  134. 5:38places in the screen it is kind of right
  135. 5:40in your face uh you can right click on
  136. 5:42the shipments table you will find new
  137. 5:44measure option here as this is quite an
  138. 5:47important feature powerbi also puts this
  139. 5:49button right there on the screen in the
  140. 5:52home ribbon and there is a whole
  141. 5:54modeling ribbon available where you will
  142. 5:57have replica of that button plus many
  143. 5:59other activities that we can do with Dax
  144. 6:02so it is always there and if that is not
  145. 6:05enough they have now added a Dax query
  146. 6:08view into powerbi this is I think uh
  147. 6:11still a preview feature I'm not really
  148. 6:12sure but it is also there through which
  149. 6:15you can kind of systematically code more
  150. 6:18Dax queries and other things we will go
  151. 6:20there uh towards the end of this video
  152. 6:23but for now I'm just going to this is my
  153. 6:25favorite way of doing I'll right click
  154. 6:26and then use the new measure
  155. 6:29and it will add a formula bar up top
  156. 6:32here this is where you usually write the
  157. 6:34measures and uh when you are done you
  158. 6:36click on this tick mark to commit that
  159. 6:39measure you can also press enter and
  160. 6:41that gets activated as the measure
  161. 6:43whenever you are typing the measure you
  162. 6:45will also see a special ribbon called
  163. 6:47measure tools get activated this is only
  164. 6:49available to you when you are either
  165. 6:51writing or editing a measure so you
  166. 6:53can't you won't see it when you're
  167. 6:54outside and through this you will be
  168. 6:56able to adjust some of the settings for
  169. 6:59that me
  170. 7:00you can also go to the model view and do
  171. 7:02that customization there uh we will go
  172. 7:05there in a minute but for now our first
  173. 7:07goal is to get the total amount so a
  174. 7:11measure will have two parts name of the
  175. 7:13measure equal to sign and then the
  176. 7:15business rule or the logic for creating
  177. 7:17that measure let me just expand the text
  178. 7:20area here to expand you can hold on the
  179. 7:22control and use the scroll wheel on your
  180. 7:24mouse to kind of make it bigger or
  181. 7:26smaller so here the measure name name
  182. 7:29would be total amount and equal to and
  183. 7:34we just want to look at the shipments
  184. 7:38table this amount column here and then
  185. 7:42add it up so the way this works is you
  186. 7:44just write Su of shipments table you can
  187. 7:50type everything you can also use this
  188. 7:51Auto suggest to pick what you want so
  189. 7:53for example I'm using my arrow keys here
  190. 7:56to pick the amount and once I select I
  191. 7:57can hit the Tab Key to fill that for me
  192. 8:01so sum of shipments amount is my total
  193. 8:03amount and we will get the total value
  194. 8:05once it is done you can either hit enter
  195. 8:07or you can click on this commit button I
  196. 8:10like to just hit enter because usually
  197. 8:12at this point I'm on my keyboard it'll
  198. 8:14be done once a measure is
  199. 8:16added it will go and sit in the table on
  200. 8:22which you right clicked and created the
  201. 8:23measure so in this case shipments is the
  202. 8:25table on which I right clicked so my
  203. 8:27total amount is also attached to the
  204. 8:30thing there measures will have this
  205. 8:32little special symbol next to it it's
  206. 8:34the calculator symbol because they're
  207. 8:37doing
  208. 8:38calculation a measure will not only have
  209. 8:41if you select this measure here you can
  210. 8:42see that a measure has a couple of
  211. 8:44things a measure has a name the
  212. 8:47definition of the measure the business
  213. 8:49rule or the logic here the rule or the
  214. 8:51logic is go to the shipments table take
  215. 8:53the amount column and sum it up that's
  216. 8:56the logic that we are writing apart from
  217. 8:58these two things a measure can also have
  218. 9:01display behaviors so here you have got a
  219. 9:03whole formatting tab that is currently
  220. 9:06set to Auto so if you don't do anything
  221. 9:08it'll be automatically formatted based
  222. 9:10on what powerbi thinks this value is but
  223. 9:12you can set it because many times when
  224. 9:14we create this measure on the screen I
  225. 9:16may want to see it in a certain way so
  226. 9:18for example as this is an amount I'm
  227. 9:20going to go into my format area here
  228. 9:22from General I'm going to switch to
  229. 9:25currency and I'm going to say I don't
  230. 9:27want any decimal points so I'll say zero
  231. 9:30decimal points there so now that the
  232. 9:32measure is created I can click on the
  233. 9:34white space to go back to my canvas and
  234. 9:36I can see this measure normally when I'm
  235. 9:39learning or explaining Dax to others I
  236. 9:41like to use either a table or Matrix
  237. 9:44visual because these are just numbers
  238. 9:46and I can see the numbers I can kind of
  239. 9:48connect the dots better so we going to
  240. 9:50use a table Visual and here in the
  241. 9:54shipments table I have got total amount
  242. 9:56first I want to see how much is that
  243. 9:57amount per product so I can go to the
  244. 9:59product table bring
  245. 10:02product and then bring the
  246. 10:04amount so here you will see how that
  247. 10:07amount is for each product it
  248. 10:09automatically calculates what that
  249. 10:11amount is and at a total level it also
  250. 10:13tells you what that amount is so this is
  251. 10:16how a measure works if you see these are
  252. 10:19the numbers coming through my total
  253. 10:21amount column if I were to now take just
  254. 10:23the amount column and put it into the
  255. 10:26table it will also do a sum of am amount
  256. 10:29autoc calculation this is how
  257. 10:32our column chart created by the way and
  258. 10:36you'll see that the numbers match
  259. 10:39$380
  260. 10:40$380,500 and it's the same value here we
  261. 10:44don't have the decimal points here we
  262. 10:46have decimal points but exactly same and
  263. 10:48at a grand total level also you can see
  264. 10:50everything adds up nicely so both of
  265. 10:53them the total amount and the sum of
  266. 10:55amount which is autoc calculated by
  267. 10:56powerbi are doing the same thing
  268. 11:00and this is one of the things that kind
  269. 11:01of frustrates the new Learners or people
  270. 11:04who haven't used powerbi much but come
  271. 11:08from let's say some other tools and then
  272. 11:10start using it and saw some demos they
  273. 11:13might be thinking okay this looks like
  274. 11:16it's giving me the same answer with a
  275. 11:18lot of work why do I even need to learn
  276. 11:20Dax when I could get the answers already
  277. 11:23and that is a fair point the problem is
  278. 11:26like I said earlier this thing the sum
  279. 11:29of amount which is autoc
  280. 11:31calculated is a restrictive option it
  281. 11:34doesn't give you many choices you can
  282. 11:36either sum average count Etc
  283. 11:40whereas our total amount column the one
  284. 11:44that we explicitly calculated gives us
  285. 11:47so much more freedom to begin with at a
  286. 11:50very simple level I can write the words
  287. 11:52that I want to call it for example I can
  288. 11:54say total amount instead of sum of
  289. 11:56amount total amount makes so much more
  290. 11:58business sense than and uh the kind of
  291. 12:00AI sounding sum of amount word on top I
  292. 12:04can assign some formatting to it so the
  293. 12:06moment I put it in my report it
  294. 12:08automatically formats but these are kind
  295. 12:10of like very trivial benefits the real
  296. 12:12benefit and the real power of Dax lies
  297. 12:15in the fact that it lets you build your
  298. 12:18own calculations based on your business
  299. 12:21rules and policies so from here on out
  300. 12:24we are going to explore the powerful
  301. 12:26side of the Dax and get more interesting
  302. 12:29and Innovative with our learning into
  303. 12:32Dax so I want to conclude this segment
  304. 12:35with one extra note which is the names
  305. 12:38that we use especially once you start to
  306. 12:40learn and get technical with this is
  307. 12:43these are called explicit
  308. 12:45measures and these are called implicit
  309. 12:49measures what it means is in in this
  310. 12:52case here we are just dragging the
  311. 12:54amount and dropping and powerbi
  312. 12:56automatically implicitly creates that
  313. 12:58calculation for us whereas here we are
  314. 13:02explicitly calculating things so
  315. 13:04normally once you start your journey
  316. 13:06into powerbi and you learn the basics
  317. 13:08and you move on to the Dax stages you
  318. 13:10will pretty much use only explicit
  319. 13:12measures so here on not make a promise
  320. 13:14to me pause the video and say it out
  321. 13:17aloud I will not make any more implicit
  322. 13:21measures no matter how convenient they
  323. 13:23are I will not make them so say the
  324. 13:25Pledge I will not make any more implicit
  325. 13:27measures and it sounds corny but this is
  326. 13:30an important thing to keep in mind if
  327. 13:32you want to grow your powerb skills and
  328. 13:35improve your Dax
  329. 13:40understanding all right so now that we
  330. 13:43have the total amount and we see that in
  331. 13:44the table here one other thing that kind
  332. 13:47of tips people off is okay I see this in
  333. 13:51the
  334. 13:52table doesn't mean this also exists in
  335. 13:55the
  336. 13:56data and when you go to the data View
  337. 13:59go to the data and select the shipments
  338. 14:01table you don't see any columns here
  339. 14:05there is no total amount column added
  340. 14:08whereas if you see here in the fields
  341. 14:10list you'll see all these fields and
  342. 14:13then you'll see the total amount as
  343. 14:14another button here where is this one
  344. 14:17way to think about this is if your
  345. 14:20shipment table is this hand this first
  346. 14:22store hand and total amount is this
  347. 14:25extra calculation that we built it
  348. 14:28doesn't belong in the hand but it acts
  349. 14:30on the hand so it can kind of take the
  350. 14:33hand and twist it and turn it to tell
  351. 14:36you what the value is for each product
  352. 14:38or at a grand total level but this hand
  353. 14:41is not part of that hand it's just that
  354. 14:43they are laid out for the sake of
  355. 14:45Simplicity on the screen in the same
  356. 14:47table but the column or so the measure
  357. 14:50total amount never really belongs in the
  358. 14:52table it is just something that acts on
  359. 14:55top of the table so this is something
  360. 14:57that you want to put put in your mind
  361. 14:59find and refer to that analogy every
  362. 15:01time you see a measure a measure just
  363. 15:04acts on the table it's not part of the
  364. 15:09table just as we could do total amount
  365. 15:12you could also do averages counts and
  366. 15:14other things to demonstrate those I'm
  367. 15:16going to take out the sum of the amount
  368. 15:18the implicit measure and just use the
  369. 15:20total amount now we can again write
  370. 15:23click here and write a new
  371. 15:25measure and this measure would be for
  372. 15:27example number of shipments each row in
  373. 15:31the shipment table is one shipment so I
  374. 15:33just want to count how many shipments
  375. 15:34are there in total so we can call this
  376. 15:37measure as shipment count and here the
  377. 15:40function that we are using is Count
  378. 15:42row count row accepts a table name so
  379. 15:45count rows of
  380. 15:47shipments and again that will give you
  381. 15:49shipment count while we are in the
  382. 15:51measure tools I can apply a thousands
  383. 15:53formatting for that and then I can add
  384. 15:57that to my table to see how many
  385. 15:59shipments we are doing by individual
  386. 16:00products so we have done a total of
  387. 16:037,95 shipments and this is how it looks
  388. 16:06at a product level as we are writing
  389. 16:09these measures you might see oh these
  390. 16:11kind of look like how I would write my
  391. 16:14Excel functions in Excel we have got
  392. 16:16some function in Excel we have got
  393. 16:18countif function they follow the similar
  394. 16:20syntactical pattern you have got a
  395. 16:21function name Open Bracket and either
  396. 16:24columns or
  397. 16:25values so another big mistake and this
  398. 16:28is a mistake that I have
  399. 16:31made in early stages of my learning of
  400. 16:34powerbi and power pivot is we think oh
  401. 16:38this looks just like Excel so it is
  402. 16:40Excel then what happens is in our mind
  403. 16:43every time we want to write a measure or
  404. 16:47build some logic we're trying to use our
  405. 16:50Excel mind to solve the problem and
  406. 16:52that's not going to work in powerbi
  407. 16:54World think of this like this the alphab
  408. 16:58bet that is used by Dax and Excel
  409. 17:02functions is same they follow the same
  410. 17:04syntactical pattern which is you have
  411. 17:06got a function Open Bracket parameters
  412. 17:10close bracket kind of a notation so in
  413. 17:13Excel we have got some function in
  414. 17:16powerbi we have got some function they
  415. 17:18look same because they share that kind
  416. 17:20of a syntactical pattern the grammar of
  417. 17:23the language and the alphabet of the
  418. 17:25language but they are two different
  419. 17:27things one way of thinking about this is
  420. 17:30imagine you know English very well now
  421. 17:34you take a plane and you go to
  422. 17:36France you'll see all the road signs all
  423. 17:40the building signs all the messages and
  424. 17:42metros and everything in pretty much
  425. 17:45English alphabet I mean French has some
  426. 17:47extra letters but the alphabet largely
  427. 17:49looks like
  428. 17:50English so you might think to your mind
  429. 17:53that oh this looks like English let me
  430. 17:55try and read it like English and
  431. 17:57understand like English
  432. 17:59you it wouldn't make any sense you
  433. 18:01wouldn't be able to even order a cup of
  434. 18:03coffee if you use your English mind this
  435. 18:06is because they share that kind of the
  436. 18:08alphabet but they're two different
  437. 18:13things p p great okay
  438. 18:19faster so it's the same way with the Dax
  439. 18:22and Exel functions they kind of look
  440. 18:24same simply because it is a convenient
  441. 18:26choice for the developers to make when
  442. 18:28are designing this
  443. 18:30language but they're two different
  444. 18:32things so from here on out discard all
  445. 18:35your Excel knowledge when you are
  446. 18:37looking at Dax don't try to think back
  447. 18:40and try to connect the dots with Excel
  448. 18:42instead approach this as a fresh new
  449. 18:44language that way you'll be able to
  450. 18:46learn better and you don't have to carry
  451. 18:48this extra baggage with you everywhere
  452. 18:51hope that helps now let's go and look at
  453. 18:54shipment count closely it has a special
  454. 18:57function called count row you can see
  455. 18:59that here this countr function doesn't
  456. 19:01even exist in Excel Excel doesn't have
  457. 19:03such a function but powerbi does so Dax
  458. 19:05language has hundreds of functions some
  459. 19:09of them like sum and count and average
  460. 19:11share the same name as Excel functions
  461. 19:14but they're just because that's an
  462. 19:16obvious thing to do but Dax offers
  463. 19:18different set of functions and the
  464. 19:19behavior is almost always
  465. 19:24different when you write a function
  466. 19:26whether it is total amount or count rows
  467. 19:29here you just specify what you want you
  468. 19:33don't go into all the specifics you only
  469. 19:35specify the business rule or the
  470. 19:37behavior for example shipment count is
  471. 19:39how many shipments are how many rows are
  472. 19:41there in the shipment table that is the
  473. 19:43business
  474. 19:44rule when you apply the measure into a
  475. 19:47specific visual here I have got a table
  476. 19:50visual with product name in each row the
  477. 19:54shipment count will be calculated for
  478. 19:57that product automatically
  479. 19:59using a concept called evaluation
  480. 20:02context this is where whenever you have
  481. 20:05a measure when you create you just
  482. 20:07create the definition of it so whether
  483. 20:09it is shipment count or total amount we
  484. 20:11just specify the Bare Bones naked
  485. 20:14version of that definition and we don't
  486. 20:16go into any specifics but when the
  487. 20:19measure is laid out on the screen
  488. 20:22depending on what the purpose of that
  489. 20:24visual is what is there on that Visual
  490. 20:27and what else is there on the scre
  491. 20:28screen power bi well technically power
  492. 20:31pivot automatically calculates the value
  493. 20:34using that evaluation context so for
  494. 20:37example here the evaluation context for
  495. 20:39that number 86 is product column of
  496. 20:43product table is 50% Dark Bites so
  497. 20:46behind scene what happens is if you go
  498. 20:48to the date model this is where the
  499. 20:50model is really helpful if you look at
  500. 20:52it the shipments
  501. 20:55table has the shipments count so here is
  502. 20:57my measure
  503. 20:59but this count is defined as number of
  504. 21:01rows in the shipments table but at the
  505. 21:04time of calculating that particular
  506. 21:06number on the screen we have already
  507. 21:09looked at a specific product so the
  508. 21:11product has been selected here 50% Dark
  509. 21:14Bites and once that product is
  510. 21:17selected that means the product table is
  511. 21:19filtered down to just one row it doesn't
  512. 21:22really have all the rows it is only
  513. 21:23looking at that product and look at this
  514. 21:25line here this line says if the product
  515. 21:28table is
  516. 21:29filtered the filter should go and apply
  517. 21:32on the shipments table as well so that's
  518. 21:34what the direction refers so once this
  519. 21:36is going here here shipment table get
  520. 21:39also filtered down just to product that
  521. 21:42first product's number of rows and at
  522. 21:44that point it just counts how many
  523. 21:46values are there how many rows are there
  524. 21:48and then comes back as shipment count
  525. 21:51this is why in the definition of the
  526. 21:53measure we don't really think about how
  527. 21:55to do this for a product specific value
  528. 21:58even though the business requirement
  529. 22:00might say I want to see how many
  530. 22:01shipments we are doing by product you
  531. 22:03don't really have to worry about the
  532. 22:05product thing here you just write count
  533. 22:07shipments there alone once that is there
  534. 22:10I can use it in the context of this
  535. 22:12visual to see how many shipments are
  536. 22:14there for that product I can move this
  537. 22:17and in this space here for example I can
  538. 22:20put a column chart and in this column
  539. 22:23chart I can put our geography on x-axis
  540. 22:27and add shipment count on y axis and
  541. 22:29then now I'm seeing how many shipments
  542. 22:31we're doing at a country level here the
  543. 22:34evaluation context is count is UK so
  544. 22:38automatically this Geo column is set to
  545. 22:41UK and locations table from six rows it
  546. 22:44shrinks down to just one row and then
  547. 22:47the filter will go into shipment table
  548. 22:49because there is a model connection
  549. 22:51there shipments table will also shrink
  550. 22:53down to just the UK's corresponding
  551. 22:55shipments and then the count shipment
  552. 22:58count will execute just for the row in
  553. 23:00that shipment table at that point in
  554. 23:02time every little thing that you do on
  555. 23:05the screen will impact this so for
  556. 23:07example see what happens the moment I
  557. 23:09click on
  558. 23:10UK you'll see that here this count is no
  559. 23:14longer the earlier number it is now down
  560. 23:16to 15 this is because the evaluation
  561. 23:19context has changed earlier we are just
  562. 23:22looking at 50% AR bites but now we are
  563. 23:24interested in what is the value of UK
  564. 23:28for 50% AR bites in terms of shipment
  565. 23:30count so the evaluation context for this
  566. 23:33number is now it has to filter the
  567. 23:36product it has to also filter the UK if
  568. 23:39there is any other filter so for example
  569. 23:41if I have got a slicer on my team
  570. 23:44members names or if I've got a filter on
  571. 23:46my dates or
  572. 23:48anything all of that those will get to
  573. 23:51decide what the evaluation context is
  574. 23:54and this is why when you look at any
  575. 23:55number on the screen it is important to
  576. 23:58understand and what is going on on the
  577. 24:00screen to interpret and understand that
  578. 24:03number so that what is going on on the
  579. 24:06screen is pretty much referred to as
  580. 24:08evaluation
  581. 24:09context all right so we have got total
  582. 24:12amount shipment count and I can add
  583. 24:15other things as well if you right click
  584. 24:17and say new measure you will be able to
  585. 24:20for example do something like total
  586. 24:23boxes and this is nothing but some of
  587. 24:25the boxes column in the shipment tables
  588. 24:29some shipments
  589. 24:30boxes and we can put this into thousands
  590. 24:34with zero decimals and I can add this
  591. 24:38and I can see 3.78 for
  592. 24:44million so the next concept that we're
  593. 24:47going to explore is while you could do
  594. 24:49sums counts averages and other things
  595. 24:51I'm not going to go into individual
  596. 24:53little things like how to build an
  597. 24:54average measure or how to do minimum or
  598. 24:56how to do maximum because those are are
  599. 24:58fairly obvious so I'm not bothering with
  600. 25:00that but the next concept that is kind
  601. 25:03of important to understand and explore
  602. 25:05the Dax betteries for the sake of that
  603. 25:08I'm just going to delete this visual uh
  604. 25:10we have more screen space for this
  605. 25:13is combining or reusing measures so
  606. 25:17right now think of these measures as a
  607. 25:20little assets that you're
  608. 25:24building so we've got three assets we
  609. 25:27have got uh shipment count we have got
  610. 25:29total amount and we have got total
  611. 25:32boxes on a standalone basis they just
  612. 25:34tell you what is happening for them but
  613. 25:37now think of actual business requirement
  614. 25:40where I want to know which products have
  615. 25:42more boxes per shipments that means the
  616. 25:45shipments might be fewer but we'll
  617. 25:47actually send more boxes of chocolates
  618. 25:49in those shipments so I want to analyze
  619. 25:52that this measure we can think of it as
  620. 25:55boxes per shipment and the logic for
  621. 25:58this is we take this number and we
  622. 26:01divide it with that number that's pretty
  623. 26:04much it so how do we develop this this
  624. 26:07is where the ReUse concept comes in
  625. 26:09because we have already built these
  626. 26:10three assets total amount shipment count
  627. 26:12and total
  628. 26:13boxes I can create a new measure right
  629. 26:16click new measure and then I can call
  630. 26:18this as boxes per
  631. 26:23shipment and here we already have both
  632. 26:26of them so I can say total boxes so you
  633. 26:28open the square brackets and then you
  634. 26:29say total boxes divide
  635. 26:32sign with shipment
  636. 26:36count and you can click okay to add that
  637. 26:40so now that measure is added I can
  638. 26:42select the visual and I can put that on
  639. 26:44there and I can see boxes for shipment
  640. 26:47how we are doing so in terms of for
  641. 26:50example our data here this is how it
  642. 26:52looks if I'm seeing just the total
  643. 26:53amount I'm going to sort this in
  644. 26:55ascending order you'll see that 50% Dark
  645. 26:58Bites is our lowest selling product
  646. 27:00380,000
  647. 27:02but if I'm looking at boxes per
  648. 27:05shipment you'll see that EES is actually
  649. 27:08our lowest product because we only ship
  650. 27:10152 boxes of EES per shipment whereas
  651. 27:1450% Dark Bites is further down it is in
  652. 27:16the fourth place with
  653. 27:18295 so this kind of a composite
  654. 27:20calculation exposes interesting and
  655. 27:23useful information about your data and
  656. 27:26we can build all of these is by simply
  657. 27:29reusing the measures that are earlier
  658. 27:31defined you don't have to write the
  659. 27:32whole thing again if you look at this we
  660. 27:35are just saying get that number get this
  661. 27:37number divide one with another so we
  662. 27:39don't have to write the whole sum and
  663. 27:41count logic again we just point to those
  664. 27:44things and boxes per shipment is a
  665. 27:47generic measure so I can use it in the
  666. 27:49context of product or I can add a page
  667. 27:53and in this page if I I may want to
  668. 27:55explore what is happening at our person
  669. 27:58level so I can go to people table put
  670. 28:00sales person and then see what is the
  671. 28:03boxes per shipment at a person level and
  672. 28:07then I can even Analyze This to see uh
  673. 28:10who is doing more boxes per shipment so
  674. 28:12for example rodie wone juu they're all
  675. 28:15doing 500 plus boxes per shipment
  676. 28:17whereas further down here we have got
  677. 28:19meline van and gigy doing around 400 per
  678. 28:23shipment again this sort of an
  679. 28:25interesting Insight is easily achievable
  680. 28:28simply by combining those two
  681. 28:34measures you might be having one nagging
  682. 28:37question at this point which is if you
  683. 28:39look at the way we defined boxes per
  684. 28:41shipment we are saying total boxes
  685. 28:43divided by total shipment count now
  686. 28:46let's take a look at another measure
  687. 28:48like total boxes in case of this we are
  688. 28:51using shipments boxes if you carefully
  689. 28:54observe this we're saying table name
  690. 28:58column name this is the notation that we
  691. 29:00are following to refer to a specific
  692. 29:02item how come we are not following that
  693. 29:06convention when we are doing
  694. 29:09this this is because if you remember my
  695. 29:11earlier example where I said a measure
  696. 29:14doesn't really belong in the table it is
  697. 29:17just laid out in the table for the sake
  698. 29:19of Simplicity that comes back to us now
  699. 29:23the measure total boxes or shipment
  700. 29:26count is technically not in any table it
  701. 29:29is just laid out here for the sake of
  702. 29:31visual uh Simplicity and finding it
  703. 29:34there that it is in that table but it
  704. 29:36doesn't really matter which table it is
  705. 29:38it is always going to come up with the
  706. 29:40same value so a measure technically
  707. 29:43doesn't belong to a table it belongs to
  708. 29:45the entire data or semantic model so
  709. 29:48measure is part of the semantic model
  710. 29:50and when you refer to the measure you
  711. 29:52don't have to have the table name you
  712. 29:54can put the table name it won't bother
  713. 29:56about it but you you don't have to do it
  714. 30:00and the second idea here is as a best
  715. 30:02practice you don't want to put table
  716. 30:05name ever in front of the measure just
  717. 30:08always refer to measures by themselves
  718. 30:10this way if I'm looking at some complex
  719. 30:13piece of Dax code and it refers some
  720. 30:15measures and some table columns imagine
  721. 30:18these are simple on line ones but pretty
  722. 30:20soon you will write like 20 line Dax
  723. 30:23measures and there could be multiple
  724. 30:25things multiple table columns being used
  725. 30:27as well as measures when you are looking
  726. 30:29at that jumble anytime you see a format
  727. 30:32like this table column you know that oh
  728. 30:35this is a table column and anytime you
  729. 30:38see just square brackets without the
  730. 30:41table name you automatically know that
  731. 30:43oh that is just a measure so this is
  732. 30:46actually a best practice that will help
  733. 30:48you later when you are developing more
  734. 30:50complicated things so for that reason we
  735. 30:53don't have to use it going back to this
  736. 30:55table here let's use the reusability
  737. 30:57concept ccept once more this time to
  738. 30:59Define amount per shipment so we doing
  739. 31:021881 shipments $713,000 of business here
  740. 31:06$713,000 what would be the amount per
  741. 31:09shipment again we can create a new
  742. 31:13measure and this is called amount per
  743. 31:17shipment and instead of using the Divide
  744. 31:20sign directly powerbi also offers a safe
  745. 31:24divide function called divide what this
  746. 31:26does is it will try to divide but should
  747. 31:29there ever be a divide by zero scenario
  748. 31:31because you have filtered down or
  749. 31:33narrowed down the datas to a level where
  750. 31:35there is not many options it will give
  751. 31:37due by zero error if you just do a hot
  752. 31:40divide so this basically does a safe
  753. 31:42division you just specify numerator and
  754. 31:45denominator and it will do the div
  755. 31:47division for you so numerator here is my
  756. 31:49total amount and denominator is shipment
  757. 31:54count and you can also pass an alternate
  758. 31:57result normally I don't do it if you
  759. 31:59don't say anything it'll just blank out
  760. 32:01on the screen so here I'll hit enter and
  761. 32:05we can add that to our table and again I
  762. 32:09can see what is the amount per shipment
  763. 32:11we are doing again you can apply measure
  764. 32:13tools formatting to it for example I can
  765. 32:15say it should be in currency with the
  766. 32:18zero decimal points and I'll see that
  767. 32:21and I can apply sort orders and all of
  768. 32:23that needless to say once you have these
  769. 32:26kind of composite measures that reuse
  770. 32:28the concepts from earlier you can just
  771. 32:31keep these two alone and take out all of
  772. 32:34them they'll still work we have actually
  773. 32:36seen it here I'm directly seeing boxes
  774. 32:39per shipment per person without seeing
  775. 32:41the individual bits and you can use the
  776. 32:44rest of the other good things here as
  777. 32:46well so for example this is my data now
  778. 32:49if I have got a bar chart here with my
  779. 32:52geographical breakdown of
  780. 32:55shipments so I'm looking at this and I
  781. 32:57may want to understand what is the
  782. 32:59amount per shipment in UK looking like
  783. 33:01if I click on this automatically all of
  784. 33:03this will update and I'll see what is
  785. 33:05the product with more amount per
  786. 33:07shipment in UK so it is organic choco
  787. 33:09syrup but if I go to Canada it's $8,000
  788. 33:13for Alman chako because again we have
  789. 33:16implemented the sort order as soon as I
  790. 33:18click on Canada the numbers change and
  791. 33:20the sort order kicks in again so this
  792. 33:22opens doors for some really interesting
  793. 33:25and Powerful analysis of your data
  794. 33:27simply because we have created three
  795. 33:30base measures these three are our base
  796. 33:33measures and two composite measures one
  797. 33:36is doing this divided by that and
  798. 33:38another is doing this divided by that
  799. 33:40again if you look at this data for
  800. 33:42example you might be exatic thinking oh
  801. 33:44$8,000 per shipment we should ship more
  802. 33:47of this Alman choco to Canada and then
  803. 33:49you come to the actual shipment count
  804. 33:51there was only one shipment so it's
  805. 33:53basically an outlier rather than a trend
  806. 33:56and more interesting patterns are
  807. 33:57somewhere down here where we are doing
  808. 33:5940 or 30 shipments and these numbers are
  809. 34:02a bit more reliable and at this point
  810. 34:04you can actually see the power of power
  811. 34:06pivot already Dax already it lets you
  812. 34:08build these kind of things which are not
  813. 34:11possible with the implicit measures if
  814. 34:12I'm just adding sums and counts and
  815. 34:14averages I would never be able to go in
  816. 34:17this
  817. 34:19direction the next concept that we are
  818. 34:22going to explore is probably the most
  819. 34:25game-changing and most useful most
  820. 34:28applicable Concept in all of Dax and it
  821. 34:30is the ability to change the filtering
  822. 34:34or the evaluation context I'm going to
  823. 34:37add a new page for this and let's
  824. 34:39explore a typical business problem let's
  825. 34:42say I'm looking at a table here and I
  826. 34:46want to see what is happening at our
  827. 34:48product and then how much is the total
  828. 34:52amount so two simple things and one of
  829. 34:55our employees bar fon I'm going to just
  830. 34:58bring them up here if I go into people
  831. 35:02table you'll see that
  832. 35:04Baron one of our employees and their ID
  833. 35:07is
  834. 35:08sp01 I responsible for Baron he's one of
  835. 35:11my sales members so as I'm looking at
  836. 35:14this I know that 50% AR bites total
  837. 35:17amount is 380,000 I would want to know
  838. 35:20what is the amount that bar fonny is
  839. 35:23bringing I like to call this as bar
  840. 35:25amount how do I go about this because if
  841. 35:29I'm looking at this and if I'm
  842. 35:31interested in bar Fon amount I could for
  843. 35:33example theoretically add a slicer and
  844. 35:36then put my
  845. 35:38salesperson into this slicer and then I
  846. 35:41can click on bar Fon as soon as I click
  847. 35:44I'll see 50% Dark Bites for bar bar Fon
  848. 35:47is 46,000 but I also lose the context of
  849. 35:50what was the original amount in order to
  850. 35:53go there I'll have to unclick and then
  851. 35:55see original amount is 380,000 so this
  852. 35:57is like a flicking a switch I can either
  853. 35:59have it on or off so this sort of a
  854. 36:01thing is not what I want instead what I
  855. 36:04want is I would want to keep these
  856. 36:06values as they are but add another
  857. 36:08column here and call it as bar amount
  858. 36:11and see what that number is for each of
  859. 36:13the products and maybe add it as a
  860. 36:17percentage so what was the bars amount
  861. 36:19as a percentage and then do some
  862. 36:22exploratory analysis on it I I want to
  863. 36:24understand uh which products heavy r on
  864. 36:28bar maybe he's planning on going on a
  865. 36:303-month trick and we want to know what
  866. 36:32impact this would have on our sales so
  867. 36:34how do we go about this this is where
  868. 36:38powerbi power pivot introduces a really
  869. 36:41powerful and extremely versatile
  870. 36:43function called
  871. 36:45calculate what it does is it can take
  872. 36:48control of the situations that are
  873. 36:50happening on the screen and it can kind
  874. 36:52of override them it's very tricky to
  875. 36:55explain because it is kind of like a
  876. 36:57Swiss army knife of the functions it can
  877. 36:59do a lot of things so there is no one
  878. 37:02easy way of explaining it other than
  879. 37:04showing it to you so let me show that
  880. 37:06we're going to write a new measure and
  881. 37:09call this as bar amount and the purpose
  882. 37:13of this is calculate the total amount
  883. 37:15just for bar F so here this is how the
  884. 37:18Syntax for this is we say calculate and
  885. 37:21you write an expression here this
  886. 37:23expression is usually an existing
  887. 37:25measure in the model but you could also
  888. 37:27type the whole thing here so we'll say
  889. 37:29total amount and then we specify the
  890. 37:32filter criteria that you want to apply
  891. 37:34so we want to calculate total amount as
  892. 37:37if we are looking at bar foring so this
  893. 37:39is where we'll say people salesperson is
  894. 37:42equal to and then within double codes
  895. 37:45bar F GN my f close bracket and commit
  896. 37:51this let's apply currency formatting
  897. 37:53with zero decimals and let's see the
  898. 37:56puppy so here is my bar amount you'll
  899. 37:59see that I have 380,000 I have 46,000 as
  900. 38:02well both of them visible to me all the
  901. 38:04time so I can see both numbers and I
  902. 38:07could make an informed decision so 44
  903. 38:09million 3.6 million is brought in by bar
  904. 38:12Fon while looking at this just pause
  905. 38:15here and think what would happen if you
  906. 38:17click on the slicer and then select bar
  907. 38:20foron all right let me show you so if I
  908. 38:22click on Baron now you'll see that both
  909. 38:25of these match because this column here
  910. 38:28pays attention to the slicer and then it
  911. 38:31says oh you want total amount just for
  912. 38:33Baron I'm going to show that the bar
  913. 38:36amount is kind of self-explanatory it
  914. 38:37will be same as what this is now imagine
  915. 38:40what would happen if I click on someone
  916. 38:43else for example if I go to chess bonell
  917. 38:46so if I click on chess can try and pause
  918. 38:48here and think what would
  919. 38:51happen if you click on chess you'll see
  920. 38:54that the total amount column here
  921. 38:57reflect CS the values for chess bonnel
  922. 38:59so all of these are for this little dude
  923. 39:01here what about these numbers they are
  924. 39:05stuck with bar foring this is what
  925. 39:07calculate does it overwrites what is
  926. 39:10happening on the screen so the screen is
  927. 39:12saying show me chess bonel and the First
  928. 39:15Column respects that because that
  929. 39:17measure doesn't have calculate on it it
  930. 39:19simply just does the calculation for
  931. 39:21whatever is on the screen but the second
  932. 39:23measure this bar amount we're going to
  933. 39:26change color of this for that this bar
  934. 39:29amount is a special one it is using the
  935. 39:31calculate so it is saying calculate the
  936. 39:34value as if I'm looking at bar for so
  937. 39:37even though the screen is saying get me
  938. 39:39chest bonel this calculat comes in and
  939. 39:42it's like a boxer it punches out chess
  940. 39:44bonnel knocks him out and then goes to
  941. 39:47Baron to get the value of that little
  942. 39:50guy and then print that there so that's
  943. 39:53really what a calculate does it
  944. 39:55overwrites it takes control of the
  945. 39:57evaluation context so that you can
  946. 39:59calculate things in a new light you can
  947. 40:02calculate anything it doesn't have to be
  948. 40:04total amount it could be boxes per
  949. 40:06shipment it could be amount per shipment
  950. 40:08or it could be something else that you
  951. 40:09have come up with whatever it is
  952. 40:11calculate can do that for you that is
  953. 40:14why I said it is kind of like a very
  954. 40:15versatile and Swiss Army kind of knife
  955. 40:18kind of function it can do a lot of
  956. 40:20things so it's trickier to explain and
  957. 40:24it does look kind of very naive and
  958. 40:26simple but once you understand the power
  959. 40:28of it you can start to see ooh I could
  960. 40:31do this I could do that I could build
  961. 40:33these kind of calculations and that's
  962. 40:35opens many many doors for you so like I
  963. 40:37said I can do total amount bar amount
  964. 40:40and then I could also calculate bar
  965. 40:44amount as a percentage so for example
  966. 40:46here I can say bar amount
  967. 40:49PCT is equal
  968. 40:51to divide bar amount with total amount
  969. 40:58and apply a percentage formatting with
  970. 41:01one
  971. 41:03decimal and then I can put that there I
  972. 41:05can see what is the percentage of bar
  973. 41:07foron for each product and then I can
  974. 41:09kind of sort this to see for example
  975. 41:12which products have a heavy Reliance on
  976. 41:15bar for example these three products
  977. 41:17have almost four products here all have
  978. 41:20about 10% of Reliance on bar F so if he
  979. 41:23goes on that 3month long track these
  980. 41:26products are going to take a big hit uh
  981. 41:28whereas further down here um not so much
  982. 41:31Reliance still pretty high but not a
  983. 41:33very high proportion and needless to say
  984. 41:37you can just have this column you don't
  985. 41:38even have to have any of these columns
  986. 41:40and the numbers will still calculate so
  987. 41:42for example if I just take out those
  988. 41:45guys you'll see this will come up here
  989. 41:48the only caveat here is if you're seeing
  990. 41:51this and if you now have this slicer for
  991. 41:53whatever reason and if you select for
  992. 41:55example someone like gigy bowling
  993. 41:57you'll see the percentages are
  994. 42:00calculated as of bar against gig's
  995. 42:03values so now you're doing a comparison
  996. 42:06between this and that so normally here
  997. 42:08that's not the intention but we had to
  998. 42:10put the slicer there so I could
  999. 42:12demonstrate how calculate can punch out
  1000. 42:15one person and move the context to bar
  1001. 42:18forny we could add more than one
  1002. 42:20condition so here if we look at bar
  1003. 42:22amount we just looking at bar foring if
  1004. 42:25you look at our uh product I'm going to
  1005. 42:27go into the table view here and quickly
  1006. 42:29switch to products you'll see that we
  1007. 42:32have different products but they are
  1008. 42:35categorized into a few categories we
  1009. 42:38have essentially three categories we
  1010. 42:39have got bars we have got bytes and we
  1011. 42:42have got other category so I want to
  1012. 42:45know what is the amount that bar Fon
  1013. 42:48brings in just from the bars category I
  1014. 42:52call this as bar bar amount let's go and
  1015. 42:56build that to build this again we make a
  1016. 42:58new
  1017. 42:59measure we'll just call this as bar bar
  1018. 43:03amount here the criteria is twofold or
  1019. 43:06the filtering needs to be twofold the
  1020. 43:08first filter needs to be on bar Fon the
  1021. 43:10second filter needs to be on bar
  1022. 43:13scategory so again we can say calculate
  1023. 43:16Open Bracket total amount people
  1024. 43:19salesperson is equal to bar on the next
  1025. 43:22one you just comma and then write the
  1026. 43:24next one product product is bars
  1027. 43:28so we close the bracket we can as you
  1028. 43:30start writing longer Dax Expressions you
  1029. 43:33might realize that writing everything in
  1030. 43:35one line is a bit of pain you can also
  1031. 43:37go place your cursor anywhere and then
  1032. 43:39press Alt Enter to get into the new line
  1033. 43:42and then you can press tab to neatly
  1034. 43:44indent that so you'll see people doing
  1035. 43:47this sort of a thing they start writing
  1036. 43:49these kind of multiple line code so now
  1037. 43:53calculate function broken down into
  1038. 43:55three lines it's essentially the same
  1039. 43:56thing but you can see what is the thing
  1040. 43:58that it is calculating what the first
  1041. 44:01criteria is and what the second criteria
  1042. 44:03is you can pretty much put any number of
  1043. 44:05criteria I don't want to call them as
  1044. 44:07criteria they're actually filters so the
  1045. 44:09first filter is people salesperson
  1046. 44:11should be bar fony second thing is
  1047. 44:13products product should be bars and the
  1048. 44:16intention here is we want to calculate
  1049. 44:17what is the amount for bar fonny in the
  1050. 44:21bars
  1051. 44:22category and I'm going to commit this
  1052. 44:26and uh we'll add this as a currency
  1053. 44:28formatting with the zero
  1054. 44:29decimals let's just see that on the
  1055. 44:32screen unfortunately we are not getting
  1056. 44:34the result what do you think
  1057. 44:37happened the problem was we are using
  1058. 44:39the product column instead of category
  1059. 44:41column so it should be category and the
  1060. 44:45moment you fix it you'll get the numbers
  1061. 44:49here you can see that this is how that
  1062. 44:51looks bar bar amount you might again say
  1063. 44:54oh what happened why is he not doing
  1064. 44:56these products
  1065. 44:57these products are not bars category
  1066. 44:59they're actually byes category so
  1067. 45:01obviously a bite category wouldn't have
  1068. 45:03bar amount because they're mutually
  1069. 45:06exclusive and that's why that's not
  1070. 45:08working but once this is there in this
  1071. 45:11context here when I'm looking at this
  1072. 45:14probably my criteria wouldn't be product
  1073. 45:16I'm not really looking at a product
  1074. 45:18perspective I might want to look at this
  1075. 45:19information from a geographical
  1076. 45:21perspective so I'm going to duplicate
  1077. 45:23this page because I want to keep this
  1078. 45:24for your reference and here I'll just
  1079. 45:28change the product to
  1080. 45:30geography and then I can see in each
  1081. 45:33geography what is happening for bar so
  1082. 45:37I'll rearrange these things I'm going to
  1083. 45:38move them like
  1084. 45:41that so Canada total amount 2.6 million
  1085. 45:45250 1,000 comes from bar which is
  1086. 45:4899.5% and 141,000 comes from bars bar
  1087. 45:54sale so that's bar bar amount
  1088. 45:57this much you can kind of add more
  1089. 46:00filters into it for example what was the
  1090. 46:03amount for bar bar in the month of March
  1091. 46:07and you can see that as well another
  1092. 46:09thing that you may want to do with
  1093. 46:10calculate especially when you're
  1094. 46:12building filters like this is let's say
  1095. 46:14you're looking at bar amount this is
  1096. 46:16fine but if I want to do a special
  1097. 46:18analysis where I want to look at four
  1098. 46:21people Baron B muet I'm just going to
  1099. 46:25highlight them here you can see bar Aron
  1100. 46:28bever I want to look at Donnie I also
  1101. 46:30want to look at Hussein these four
  1102. 46:32people I want to know what is
  1103. 46:36happening then you could build a complex
  1104. 46:39calculate function here with all the
  1105. 46:41four people or you could also use a
  1106. 46:44simpler operator so I'm going to show
  1107. 46:46you how these work so we are going to
  1108. 46:48call this as total amount my team V1
  1109. 46:52we're going to do two versions of this
  1110. 46:54measure so V1 for the first version and
  1111. 46:56the first one is calculate total
  1112. 47:00amount and then in the next line I'm
  1113. 47:03going to say sales
  1114. 47:05person is bar Fon now we not just
  1115. 47:11stopping at bar Fon we would like to do
  1116. 47:13this for all the four and then together
  1117. 47:15calculate what the total amount is so
  1118. 47:17this is where the r condition comes in
  1119. 47:19because we are trying to do the check on
  1120. 47:21the same person again so here we use two
  1121. 47:24pipe symbols to indicate our criteria
  1122. 47:27and then put the rest of them so the
  1123. 47:30second one is bever Mett third one is
  1124. 47:32chess bonell and the fourth one is
  1125. 47:33Hussein AAR so this two pipe symbols
  1126. 47:36indicate R criteria and when you apply
  1127. 47:40this it'll create a measure that looks
  1128. 47:42at any of these four people let's add
  1129. 47:45this to our table here so 44 million
  1130. 47:49total sales my team brings in $8.9
  1131. 47:53million so this is version one of this
  1132. 47:55we're going to do two versions I'm going
  1133. 47:57to take out this slicer so we have more
  1134. 47:58space to play with these values here the
  1135. 48:01second version is when you have multiple
  1136. 48:03people it's a bit of pain to write these
  1137. 48:06each thing once and then put the pipe
  1138. 48:09symbol so we could also use in Clause
  1139. 48:12just like how you can use in clause in
  1140. 48:14SQL to do these kind of things so we
  1141. 48:17will copy
  1142. 48:19this and make a new measure paste it
  1143. 48:22there change it to
  1144. 48:24V2 and equal to
  1145. 48:27instead of equal to we'll say in and
  1146. 48:30then open curly brackets and comma
  1147. 48:33separate all the
  1148. 48:37four so in is basically just like SQL in
  1149. 48:41you specify all the four values in the
  1150. 48:43curly brackets and you put them in the
  1151. 48:46double codes if they're text otherwise
  1152. 48:48if they're numbers you just type them
  1153. 48:50out whenu select uh and complete that
  1154. 48:53it'll go and you can kind of uh see the
  1155. 48:57values again the values do match its
  1156. 48:59same numbers it's just one of them uses
  1157. 49:02in clause which is a bit more convenient
  1158. 49:04and another one uses this kind of a long
  1159. 49:08or operators one after another so that
  1160. 49:11is another way of using calculate
  1161. 49:13especially if you have got a filter
  1162. 49:16where you want to look at multiple
  1163. 49:18people in one
  1164. 49:21go another crucial aspect of Dax and
  1165. 49:24pretty much any kind of coding or or
  1166. 49:27logic Building Systems is conditional
  1167. 49:29logic to demonstrate that let's say you
  1168. 49:32have got a simple table like this where
  1169. 49:34you're looking at salesperson and what
  1170. 49:37is the amount they are bringing in this
  1171. 49:39is fine but let's say you are have an
  1172. 49:42upcoming budget meeting or you are doing
  1173. 49:44a performance review and you want to
  1174. 49:46know which salese have met their targets
  1175. 49:49there is a target of $2 million per
  1176. 49:51salesperson in our organization so I
  1177. 49:54want to know who has met the target and
  1178. 49:57who hasn't met the targets so in this
  1179. 50:00case we want to do a conditional logic
  1180. 50:02where I want to take this number compare
  1181. 50:04that with 2 million and then print an
  1182. 50:07outcome here that could be like yes you
  1183. 50:09have met the targets so this is where
  1184. 50:11the conditional logic functions come in
  1185. 50:13very handy once you understand them and
  1186. 50:15once you get the basics of how to build
  1187. 50:17the base measures and how to use
  1188. 50:19calculate that alone will take you
  1189. 50:22really far in terms of analyzing data
  1190. 50:24and producing actual meaningful out
  1191. 50:27outcomes from your data so here to do
  1192. 50:29that I will add a measure we could kind
  1193. 50:32of hardcode everything but I thought
  1194. 50:34this would be a better approach so the
  1195. 50:35first measure that I'm creating is
  1196. 50:37called sales sales Target and this is
  1197. 50:40simply hardcoded to 2 million what this
  1198. 50:43does is it gives you a flexible way to
  1199. 50:45adjust the number if your business
  1200. 50:47requirements change later if you put the
  1201. 50:502 million directly into the conditional
  1202. 50:52formulas then changing it becomes a pain
  1203. 50:54so we have got a sales Target which is a
  1204. 50:56measure that that just always comes up 2
  1205. 50:58million and I can see that in the table
  1206. 51:00as well if I put that for everybody it's
  1207. 51:022 million including at a grand total
  1208. 51:04level now the next measure that we want
  1209. 51:06to do is Target comparison V1 we are
  1210. 51:11going to do four versions or three
  1211. 51:13versions of this measure so we'll do
  1212. 51:14this with V1 first and here we can use
  1213. 51:17the IF function if and if you have used
  1214. 51:20if in Excel python or Tableau or any
  1215. 51:23other systems it's exactly same logic if
  1216. 51:26if and you build a condition logical
  1217. 51:28test The Logical test here is I want to
  1218. 51:30see if your total amount is more than
  1219. 51:32the target so total
  1220. 51:35amount greater than sales Target if so I
  1221. 51:40want to say yes else I want to say no so
  1222. 51:44if you look at the nature of this
  1223. 51:45measure it is printing the word yes or
  1224. 51:47no depending on how that comparison is
  1225. 51:49and once I add that I can just print
  1226. 51:53that here you can see I'm doing yes no
  1227. 51:55comparison a lot of people have yes but
  1228. 51:58we also have some people not meeting the
  1229. 52:01targets and they're all having no
  1230. 52:02because their values are under 2 million
  1231. 52:05so this is one way of
  1232. 52:09doing here a key thing that you want to
  1233. 52:12remember is let me just flash this again
  1234. 52:14we using the IF function to compare two
  1235. 52:17things so the comparison between two
  1236. 52:19things need to be just two individual
  1237. 52:22values they can be numbers dates text
  1238. 52:24values it doesn't really matter but they
  1239. 52:26have to to be two individual values more
  1240. 52:29technical way of referring this is they
  1241. 52:31have to be scalar values a scalar is
  1242. 52:33nothing but just a single value so it
  1243. 52:35has to be a single value and usually in
  1244. 52:39business situations like this they will
  1245. 52:40be measures what happens is if you do
  1246. 52:44this comparison wrong or if you compare
  1247. 52:46with a table column one column versus
  1248. 52:48another then you will get into some
  1249. 52:49trouble so for example um not that you
  1250. 52:53will write like this but it is likely
  1251. 52:55that uh in you might actually end up
  1252. 52:57doing this sort of a mistake in early
  1253. 52:59stages so we'll do this target
  1254. 53:04comparison V V2 and here if and instead
  1255. 53:10of picking a scalar value I'm going to
  1256. 53:12pick a table column so if I'm going to
  1257. 53:14say shipments table in fact it won't
  1258. 53:16even let me do it uh in newer versions
  1259. 53:18of powerbi but um you could kind of
  1260. 53:22write this one way or another if you're
  1261. 53:25using power pivot in Xcel or an older
  1262. 53:27version of powerbi so if I'm saying
  1263. 53:30sales shipments table amount column now
  1264. 53:33you can see that the auto suggest is not
  1265. 53:35even giving me that option it is saying
  1266. 53:36you have to pick a measure here it's
  1267. 53:38only going to work with scalar values
  1268. 53:40but somehow I brute force my way into
  1269. 53:43this and I'm saying if shipment amount
  1270. 53:45column uh is greater than sales
  1271. 53:51Target already red lines are coming in
  1272. 53:53here indicating we have a trouble but
  1273. 53:55let's push ahead with this I'm going to
  1274. 53:57say yes
  1275. 54:00no close bracket hit enter it's just not
  1276. 54:04going to work you can see the red line
  1277. 54:05is already there and the dreaded error
  1278. 54:08comes in
  1279. 54:10here it will give you this sort of an
  1280. 54:12error a single value for the column
  1281. 54:14amount in the table shipments cannot be
  1282. 54:16determined this can happen when a
  1283. 54:18measure formula refers to a column that
  1284. 54:20contains many values without specifying
  1285. 54:22an aggregation such as minimum maximum
  1286. 54:24Etc so it wants a scalar value an
  1287. 54:27aggregation basically you can't do one
  1288. 54:30column versus another column kind of a
  1289. 54:32comparison with this function there are
  1290. 54:34other functions where you could do this
  1291. 54:36but if function switch function which is
  1292. 54:38another way of doing these kind of
  1293. 54:40logical tests they are equipped to do
  1294. 54:43one-on-one comparisons pretty much every
  1295. 54:46time a measure whether it is any formula
  1296. 54:49or any other kind of measure that you're
  1297. 54:51building a simple let P test for that
  1298. 54:54measure has to be it has to come up with
  1299. 54:58a single value right it cannot return a
  1300. 55:01bunch of values it has to be a single
  1301. 55:03value so the measure is usually an
  1302. 55:05aggregation process it just takes all
  1303. 55:07the values and sums it up or it Compares
  1304. 55:10One value with another and comes up with
  1305. 55:11the third value whatever may be that
  1306. 55:13process uh it has to always come up with
  1307. 55:16single value and if it doesn't work then
  1308. 55:18internally this sort of a mistake might
  1309. 55:19have
  1310. 55:21happened anyhow this doesn't work I'll
  1311. 55:23leave that there in the model just in
  1312. 55:25case you want to refer to to that and we
  1313. 55:27will do another
  1314. 55:30measure just as you can print yes no you
  1315. 55:33can also come up with some interesting
  1316. 55:36or innovative ways of doing this so for
  1317. 55:38example our Target comparison I can get
  1318. 55:42this spelling right that'll be good okay
  1319. 55:45Target comparison version three and this
  1320. 55:47time we going to say if total amount is
  1321. 55:50greater than sales Target if so instead
  1322. 55:54of yes no you may want to print a thumbs
  1323. 55:57up or thumbs down kind of a symbol and
  1324. 56:00for this you can use Emoji this is one
  1325. 56:02of my favorite early tricks and dags
  1326. 56:05that I like to teach people and it kind
  1327. 56:07of Lights them up so hopefully it helps
  1328. 56:09you as well so open double codes and
  1329. 56:11then press windows and Dot key together
  1330. 56:14this opens up the Emoji keypad on your
  1331. 56:16computer again the keystroke is Windows
  1332. 56:18and the period or dot key together from
  1333. 56:22here you can pick any Emoji so I'm going
  1334. 56:24to go in and uh find the thumbs up emoji
  1335. 56:28I think it's somewhere here yeah here so
  1336. 56:32if they have met the target then we give
  1337. 56:34them a thumbs up that reminds me if
  1338. 56:36you're enjoying this video maybe you
  1339. 56:37also want to give thumbs up
  1340. 56:40and else thumbs
  1341. 56:42down we can add that and in the table I
  1342. 56:45can add it and you can see that as a
  1343. 56:49indicator as well so again this is a
  1344. 56:52very simple cool way of looking at the
  1345. 56:54targets and then seeing it obviously
  1346. 56:56viously in a business reporting you may
  1347. 56:58want to be a little bit more gentle with
  1348. 57:00these emojis you don't want to have
  1349. 57:01laughing out loud kind of an emoji there
  1350. 57:04because probably it doesn't make sense
  1351. 57:06but again it all depends on what the
  1352. 57:08context is and who is seeing the reports
  1353. 57:10so that is how you can do the if if kind
  1354. 57:12of a comparison if only lets you do
  1355. 57:15oneon-one comparisons but if you have
  1356. 57:17got multiple comparisons to do like you
  1357. 57:19don't have a single sales Target you
  1358. 57:22have a sliding scale of sales Target so
  1359. 57:25you have a target of two million 1.5
  1360. 57:27million 1 million and then you want to
  1361. 57:29see where people have met their target
  1362. 57:31some people have more than 2 million
  1363. 57:33some people have more than 1.5 some have
  1364. 57:35more than 1 million so I want to give
  1365. 57:37them different symbols or different
  1366. 57:39messages in that case you can use the
  1367. 57:44switch function what it does let you is
  1368. 57:47it will let you kind of do multiple
  1369. 57:50comparisons using a kind of a ladder
  1370. 57:52structure you can also use the IF
  1371. 57:55function and kind of Nest one IF
  1372. 57:57function in another just like how you
  1373. 57:59could have done this in Excel or other
  1374. 58:01Solutions even VBA or coding systems
  1375. 58:04just put one if inside another and that
  1376. 58:06also lets you build that I'm leaving
  1377. 58:11this as a homework assignment for you
  1378. 58:13print different symbols or different
  1379. 58:15messages and people are more than 2
  1380. 58:17million 1.5 1
  1381. 58:21million so now that you have understood
  1382. 58:24the 80% of the important vital and
  1383. 58:27essential Dax Concepts let me conclude
  1384. 58:30by giving you five tips for writing
  1385. 58:33better Dax I call this as ACM Buu or
  1386. 58:37ammo it's a lousy acronym but a great
  1387. 58:39technique let's take a look at
  1388. 58:42this a stands for acquire business
  1389. 58:45knowledge you can't write good DXs if
  1390. 58:48you don't understand the underlying
  1391. 58:50business and what your users need so any
  1392. 58:54good kind of data analysis business
  1393. 58:56intelligence project must begin by
  1394. 58:59acquiring proper knowledge about the
  1395. 59:01underlying data sets what your users
  1396. 59:04needs are how they plan to use the
  1397. 59:07reports how often data is updated and
  1398. 59:09all of that so spend quite a bit of time
  1399. 59:13doing this phase correctly if you get it
  1400. 59:15wrong everything else is just going to
  1401. 59:17be useless so understand what your users
  1402. 59:20need understand what your data is able
  1403. 59:22to provide and then build from there C
  1404. 59:26stands for cleaning the data if you
  1405. 59:28don't have clean data you cannot solve
  1406. 59:31the problem easily using Dax so Dax
  1407. 59:35should not be the fix to your lousy data
  1408. 59:37problems so spend quite a bit of time
  1409. 59:40cleaning the data making sure that it is
  1410. 59:42in the right shape size and quality
  1411. 59:46before you start thinking about modeling
  1412. 59:48and analyzing the
  1413. 59:50data M start for model for the needs you
  1414. 59:54might have the same data but depending
  1415. 59:57on user a needs you may have to create
  1416. 1:00:00one kind of model and user B's needs you
  1417. 1:00:03may have to create a different model so
  1418. 1:00:05keep that in mind your data can always
  1419. 1:00:08be there but your model should reflect
  1420. 1:00:10the underlying business needs of what
  1421. 1:00:13your audience wants and this is where
  1422. 1:00:15the thing is in Step by-step progression
  1423. 1:00:17you have to have good knowledge of what
  1424. 1:00:19your users need and then clean the data
  1425. 1:00:22accordingly and model it accordingly you
  1426. 1:00:25can't have in many proper bi situations
  1427. 1:00:28one fixed solution for everything I mean
  1428. 1:00:31the data sets and majority of the
  1429. 1:00:32concepts can be same but some of the
  1430. 1:00:34modeling needs to change depending on
  1431. 1:00:37what is happening for your users how
  1432. 1:00:39they expect to see the
  1433. 1:00:42results and b stands for blocks not
  1434. 1:00:45Black Box what I mean by this is think
  1435. 1:00:48of your Dax as individual blocks that
  1436. 1:00:52you can stack one on top of another to
  1437. 1:00:54build a massive Cathedral you don't want
  1438. 1:00:56to write a 300 line Dax piece just to
  1439. 1:00:59solve one problem instead construct it
  1440. 1:01:02in a more logical manner just like how
  1441. 1:01:04we have done earlier we have got these
  1442. 1:01:07individual things but we used smaller
  1443. 1:01:09chunks to individually build out the
  1444. 1:01:11logic and then combine them to come up
  1445. 1:01:13with amount per shipment or boxes per
  1446. 1:01:16shipment so think of it like that don't
  1447. 1:01:19write complex logic in one go instead
  1448. 1:01:21break it down to smaller segments and
  1449. 1:01:23build it in a way so yeah I call this as
  1450. 1:01:26blocks not
  1451. 1:01:28blackbox and U stands for using
  1452. 1:01:31variables and using Dax query view when
  1453. 1:01:34you got stuck we haven't covered either
  1454. 1:01:36of these Concepts in this video as these
  1455. 1:01:38are slightly more advanced but once you
  1456. 1:01:40start building the knowledge you will be
  1457. 1:01:42able to come to a place where you'll
  1458. 1:01:44find that if you write your Dax in such
  1459. 1:01:47a way that you're using variables and if
  1460. 1:01:49you are getting stuck using that Dax
  1461. 1:01:52query view can help you a lot so those
  1462. 1:01:55are my five practical tips I call them
  1463. 1:01:58as Abu acquire business knowledge clean
  1464. 1:02:01data model for the needs build blocks
  1465. 1:02:05instead of black box and using variables
  1466. 1:02:08and Dax query View and other features to
  1467. 1:02:11understand and explore your data better
  1468. 1:02:14when you get stuck all the best in your
  1469. 1:02:16Dax Journey I'll catch you in another
  1470. 1:02:19video bye

About this transcript

This page contains the full transcript of Learn 80% of DAX in an Hour (with FREE sample file) by Chandoo, generated from the public captions YouTube serves with the video. The transcript has 10,663 words across 1,470 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.