Power BI - TREATAS Function

Today’s post is about TREATAS() function. I will show you a short example how to deal with a data lineage.
In tabular models every column has its own lineage — it is a special mark added to a column. Data lineage is operated by DAX engine in entire process of data calculations. So, in most cases you haven’t bother how it works. But there is a few cases when you can take advantage of it.
Our model is composed of two tables. Users and Badges from StackOverflow database.

First example. When you don’t have relationship between tables and for some reason you don’t want to create it. You can make a virtual relationship between tables wich changes data lineage. Example bellow.
As you can see, standard measure won’t give you correct result because of lack of relationship between tables. But using measure with TREATAS() function solves the problem.

Second case can occur, when you use ADDCOLUMN() function. Additionall columns don’t contain information about lineage.
Script bellow, shows how it works and how you can deal with it.
Firstly, I’ve written two simple measures, filtered table and summarized data: #1, #2, #3
I added new column, which doesn’t contain information about lineage: #4
I saved column with lineage and with no lineage into two separate variables: #5, #6
Now, we have two columns.

When we put WithLineage variable in point #8 then we have appropriate result.

But when we replace it with WithNoLineage variable in point #8 then result doesn’t look good.

What we can do? TREATAS() function comes to the rescue. We can add a lineage. Like at point #7. Now our result looks better.
