Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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:

 

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

 

Power BI shows:

 
 

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

 

I expect:

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

Any Ideas?

  • 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.

  • 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.

6 Replies

  • edhans's avatar
    edhans
    Icon for Community Champion rankCommunity Champion

    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.

  • Anonymous's avatar
    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.

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

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

  • edhans's avatar
    edhans
    Icon for Community Champion rankCommunity Champion

    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.

  • 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.

  • Anonymous's avatar
    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?


    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.