Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

TREATAS doesn't show all data

Hello!

 

I'd like to create virtual relationship between tables: 'Sales' and 'Plan', but TREATAS function doesn't work.
When any of the position from 'Plan' does not exist in 'Sales' it works incorrectly . Example:

 

Measure:

Plan =

CALCULATE (

SUM ( Plan[Value] ),

TREATAS (

SUMMARIZE ( 'Sales', 'Sales'[Year], 'Sales'[Month],'Sales'[Type],'Sale'[Region]),

plan[Year],plan[Month],plan[Type],plan[Region]))

 

 

Source:

PowerBI1971_0-1606321647458.png

 

https://i.ibb.co/M8Lfqpx/1.png

 

Power BI shows:

 
 

3

https://i.ibb.co/YXSGVZK/3.png

 

I expect:

PowerBI1971_2-1606321647465.png

https://i.ibb.co/NL4QqbT/3.png
 

Any Ideas?

2 ACCEPTED SOLUTIONS
edhans
Super User
Super User

Can you post some actual data per links below? I am not typing that in.

 

You cannot use TREATAS here. The function works by saying "TREAT this AS a filter for that." That is where TREATAS came from. If the data doesn't exist in this then it has nothing to filter for that. I'd be inclinced to merge or combine data in Power Query - would have to play with it. But need data.

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

daxer-almighty
Solution Sage
Solution Sage

To get what you want, you can't use columns from your fact tables. You ALWAYS have to use proper dimensions to slice data by. The hard rule is that data should never be sliced and diced by columns in fact tables. Only via dimensions. Stick to this and you'll be safe.

View solution in original post

6 REPLIES 6
daxer-almighty
Solution Sage
Solution Sage

To get what you want, you can't use columns from your fact tables. You ALWAYS have to use proper dimensions to slice data by. The hard rule is that data should never be sliced and diced by columns in fact tables. Only via dimensions. Stick to this and you'll be safe.

edhans
Super User
Super User

Can you post some actual data per links below? I am not typing that in.

 

You cannot use TREATAS here. The function works by saying "TREAT this AS a filter for that." That is where TREATAS came from. If the data doesn't exist in this then it has nothing to filter for that. I'd be inclinced to merge or combine data in Power Query - would have to play with it. But need data.

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

@Anonymous @edhans @wdx223_Daniel 
I want to be able to display the plan for a all combinations, even if combination is not available in 'Sale'. How can I do it?


4.png

Sometimes we have a plan for a product but it hasn't been sold yet. Still, I would like the see plan: 800, not 700.

Dimension tables are created, but still the same problem. 

 

wdx223_Daniel
Super User
Super User

@Anonymous the better way is to create dimension tables for date, region,type. then put them in the row

Anonymous
Not applicable

Combinations under TREATAS (the first argument) that do not exist in the target table to which you apply them (the other arguments) will, of course, not appear in the output. So, if there's a combination in Sales that does not exist in 'plan', it'll not show up. It just can't show up since TREATAS creates a set of rows that DO EXIST in the target table.

edhans
Super User
Super User

Here is your measure a bit more readable so I can understand what is going on:

Plan =
CALCULATE(
    SUM( Plan[Value] ),
    TREATAS(
        SUMMARIZE(
            'Sales',
            'Sales'[Year],
            'Sales'[Month],
            'Sales'[Type],
            'Sale'[Region]
        ),
        plan[Year],
        plan[Month],
        plan[Type],
        plan[Region]
    )
)

The issue it seems is your Sales table doesn't have the 2020/2/2/B value to filter the plan table by, so it will not show up. There is nothing in sales to filter that.

if you need more help, please provide some data.

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors