Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Problem with TREATAS

Hey there. Here's the file link.

 

I've been trying to run what should be an easy calculation, however I can not understand what I'm doing wrong. Basically, I'm trying to use TREATAS to propagate the virtual d_resellers[id_reseller] → d_clients[id_reseller] relationship. Of course, by simply using a physical one would be the best option, however I'm learning the TREATAS function, and thus why I have not chose to use the physical relationship.

 

The formula is as follows:

EVALUATE
VAR _resellers = 
	DISTINCT ( d_resellers[id_reseller] )
VAR _propagation =
	TREATAS ( _resellers, d_clients[id_reseller] )
VAR _result =
	ADDCOLUMNS (
		_affiliates,
		"@", 
			CALCULATE (
				COUNTROWS ( d_clients ),
				KEEPFILTERS ( _propagation )
			)
	)
RETURN
	_result

 

Note that 7, in the [@] column, is the correct result, but it should be properly assigned to the numbers 8 and 10 for the [id_reseller] column.

 

The correct result should be:

 

This is the data model:

 

What am I doing wrong?

 

Thanks in advance.

 

  • sorry. My bad. attention to detail 😛

    try this:

    EVALUATE
    VAR _resellers =
        DISTINCT ( d_resellers[id_reseller] )
    VAR _result =
        ADDCOLUMNS (
            _resellers,
            "@",
            VAR _currentReseller = [id_reseller]
            VAR _propagation =
                TREATAS ( {_currentReseller}, d_clients[id_reseller] )
            RETURN
                CALCULATE (
                    COUNTROWS ( d_clients ),
                    _propagation
                )
        )
    RETURN
        _result

4 Replies

  • connect your tables in the data model- 

     

    use the id_reseller column to connect.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for your reply, but I'm trying to use the TREATAS function because I've never used it before and because of that I have not set this relationship active.

      • Shravan133's avatar
        Shravan133
        Icon for Super User rankSuper User

        sorry. My bad. attention to detail 😛

        try this:

        EVALUATE
        VAR _resellers =
            DISTINCT ( d_resellers[id_reseller] )
        VAR _result =
            ADDCOLUMNS (
                _resellers,
                "@",
                VAR _currentReseller = [id_reseller]
                VAR _propagation =
                    TREATAS ( {_currentReseller}, d_clients[id_reseller] )
                RETURN
                    CALCULATE (
                        COUNTROWS ( d_clients ),
                        _propagation
                    )
            )
        RETURN
            _result