Power BI DAX #1: The Magic of CROSSJOIN

Power BI DAX #1: The Magic of CROSSJOIN

No alt text provided for this image

Last week I facilitated a training where the participants were staff of a leading FMCG firm. After my usual prepared practice, we delved into making the types of reports they need. 

One of the reports had a very interesting twist that CROSSJOIN was perfect for. For confidentiality, I won't tell you the exact situation we had regarding the said report but I have created a simpler and easier to relate with example that I will use to show you the magic of CROSSJOIN.

CROSSJOIN is a DAX formula that generates the cartesian product of all the rows in tables inputted into the formula argument. You can go through Microsoft's official documentation on it at https://docs.microsoft.com/en-us/dax/crossjoin-function-dax 

CASE STUDY

ABC Limited has five branches across Nigeria and sells four products. Each product has same target across all the branches.

No alt text provided for this image
No alt text provided for this image

You are to generate a new table that will combine these two tables into one -- having all four products with assigned targets showing for all the five branches.

No alt text provided for this image

So how do we achieve this?

ANSWER: CROSSJOIN

If you want to follow along and recreate this tutorial, just launch Power BI. And under Home menu, click on Enter Data. Copy paste or type in the Branch table data.

No alt text provided for this image

Repeat same steps for Product table.

No alt text provided for this image

And to the magic step: under Modeling menu, click on New Table and type CrossJoin Table = CROSSJOIN('Branch Table','Product Table')

No alt text provided for this image

And voila! You are done.


BONUS: What if you needed to do this in Excel?

You will have to use PowerQuery's Unpivot, and maybe more than once if both tables have more than 2 columns of relevant data.


You can watch the YouTube tutorial: https://youtu.be/A_2GM4Ig24k 

Enjoy!

And to join our training class, visit https://www.urbizedge.com/powerbi

要查看或添加评论,请登录

Michael Olafusi的更多文章

社区洞察

其他会员也浏览了