Producing Relationship Based on Several Areas in Energy BI Making Use Of TREATAS DAX Function


Producing Relationship Based on Several Areas in Energy BI Making Use Of TREATAS DAX Function

TreatAs is useful for filtering, plus it does not filter just considering one column, it could filter predicated on as much as columns you prefer. One of several challenges in Power BI relationships is creating a relationship according to numerous industries, we have formerly explained a technique you can make use of to produce a compound key and use that for the relationship. Another technique is to utilize TreatAs. Let’s see how TreatAs might help for the reason that situation.

This will be for Training, Not Advice

Because i acquired plenty of concerns from my very first article about TreatAs, i do want to make clear one thing right here before we begin;

Although we explained in the earlier post that you could produce a digital relationship making use of TreatAs, as well as in this post, i will be describing how exactly to produce a relationship centered on numerous industries making use of TreatAs, These particular usage cases shouldn’t be regarded as my suggestion. I recently cita budista explain these for the true purpose of TRAINING. You can find, of course, usage cases to utilize TreatAs, nonetheless, this post together with previous post is simply going to explain the way the function works, therefore I adhere to easy, and easy to comprehend examples.

Test Model

The test model that we have contains to tables, one for Rating of films, and something for product sales of films, there isn’t any relationship between your two tables. This is because why these two tables must be associated centered on two industries: Title and 12 months in each dining table;

I usually suggest in situations such as this to generate a shared dimension and employ that for filtering both tables, like the thing I explained right here. one more thing that i will suggest is to utilize ingredient secrets to produce a relationship like the things I explained right here. But also for this example, let’s put recommendation aside, and speak about the side that is learning of function.

The reason will be have a relationship similar to this:

TreatAs Function with Multiple Columns

We explained the fundamentals of TreatAs function when you look at the past article, and you also discovered that TreatAs calls for a dining table phrase and a listing of columns.

TreatAs( , , …)

The dining table phrase should get back precisely the exact same quantity of columns that you want to reference in TreatAs. I really do require the dining table phrase to come back the 2 columns Title and Rating through the Rating table, and then make use of the two columns Title and Rating through the product sales dining table as parameters of TreatAs columns.

Before utilizing TreatAs, I will get something like below if I filter the Lifetime Gross field in the Sales table by the Title and Year from the Rating table;

Everbody knows, since there is no relationship to filter the Sales dining table, it shows the sum total value whatever the Title and 12 months. We have to state that the Title and columns of the Rating table, can filter the Title and Year columns of the Sales table year.

I am able to write a measure like below, nonetheless it won’t work;

Rating table includes both Title and columns that are year nonetheless, in addition it includes a couple of other columns while you see below:

Therefore the Rating as a dining table expression comes back four columns, but i recently require two; one for Title, plus one for Year.

Table Expression with all the exact same Column’s count and exact same purchase of Columns

You will find numerous methods for you to compose a DAX dining table phrase that returns just the two columns you’ll need through the Rating table, SelectColumns is an method that is easy that;

The above expression will just get back a table with two columns; Title and 12 months. this dining table may be used while the dining table phrase of TreatAs function like below;

To comprehend exactly how this ongoing works, i’ve explained it through the form below;

The SelectColumns phrase returns a dining table with just two columns: Title and Year. Then your values with this dining table are acclimatized to filter the values of subsequent columns of Title and from the Sales table year. Your order of columns ought to be the exact same. You simply cannot have a table Title that is returning, and then filter the season, Title along with it. You almost certainly won’t get any outcomes with that combination. The title for the columns is certainly not essential, the values in each line are.

Caused by the phrase below can be as below:

And even though there is absolutely no relationship involving the two tables, making use of TreatAs we created that relationship because of this measure making use of the two columns; Title and 12 months. The thing is some values that are blank the end result, that is really because its not all film this is certainly when you look at the Rating table exists into the product sales dining table.

Therefore I sum up the educational for this post for your needs:

The dining table expression should get back a dining table using the precisely the number that is same of columns with the exact same purchase associated with the columns which can be found in record of columns for the TREATAS function.

If you prefer to understand the fundamentals of TreatAs function, read my web log article right here. Lastly, this post ended up being describing a functionality of TREATAS for learning, it isn’t recommended though to generate a relationship such as this; i usually suggest situations such as this to create a shared dimension and employ that for filtering both tables, like the things I explained right here. one more thing I explained here that I recommend is to use compound keys to create a relationship like what.

Comments 0

Producing Relationship Based on Several Areas in Energy BI Making Use Of TREATAS DAX Function

Choose A Format
Story
Formatted Text with Embeds and Visuals
Video
Youtube, Vimeo or Vine Embeds
Image
Photo or GIF