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

Custom Column, weird behaviour

Hi,

while adding some custom columns to a table (DAX) I encountered something weird, and I don't understand why it's happening:

I have a table:

IDValue
1False
1True
1False
1False
2False
2True
3False
3False
3False

 

What I want to achieve is: A custom column with a value of TRUE or FALSE, True when the value for an id is at least one time TRUE and FALSE when the value for an id is never TRUE. So in this case the custom column is True for both ID's 1 and 2 and False for ID 3.

 

I can achieve this by the the following statement:

 

isTrueID = 
var arr = CALCULATETABLE(VALUES('Test'[ID]); 'Test'[Value] = TRUE())
RETURN 
if('Test'[ID] in arr; TRUE(); FALSE())

 

Which results to this table (which is correct) : 

IDValueisTrueID
1FalseTrue
1TrueTrue
1FalseTrue
1FalseTrue
2FalseTrue
2TrueTrue
3FalseFalse
3FalseFalse
3FalseFalse

 

Now when I add an extra custom column, for example: (doesn't matter wich DAX statement I use here):

 

ConcatColumn = CONCATENATE(Test[ID]; Test[Value])

 

My previous 'isTrueID' gets messed up and results in this table:

 

IDValueisTrueIDConcatColumn
1FalseFalse1FALSE
1TrueTrue1TRUE
1FalseFalse1FALSE
1FalseFalse1FALSE
2FalseFalse2FALSE
2TrueTrue2TRUE
3FalseFalse3FALSE
3FalseFalse3FALSE
3FalseFalse3FALSE

 

Anyone an idea why this is happening? And how I can fix this?

 

Thank you!

1 ACCEPTED SOLUTION
MartynRamsden
Solution Sage
Solution Sage

Hi @Anonymous 

 

Not entirely sure why it's happening but try this expression for your first calculated column:

isTrueID =
VAR SelID = Test[ID]
VAR TrueRows =
COUNTROWS(
    FILTER(
        ALL( Test ),
        Test[ID] = SelID
            && Test[Value] = TRUE()
    )
)
VAR Result =
    IF(
        TrueRows = 0,
        FALSE(),
        TRUE()
    )
RETURN
    Result

 

Best regards,
Martyn


If I answered your question, please help others by accepting it as a solution.

View solution in original post

4 REPLIES 4
MartynRamsden
Solution Sage
Solution Sage

Hi @Anonymous 

 

Not entirely sure why it's happening but try this expression for your first calculated column:

isTrueID =
VAR SelID = Test[ID]
VAR TrueRows =
COUNTROWS(
    FILTER(
        ALL( Test ),
        Test[ID] = SelID
            && Test[Value] = TRUE()
    )
)
VAR Result =
    IF(
        TrueRows = 0,
        FALSE(),
        TRUE()
    )
RETURN
    Result

 

Best regards,
Martyn


If I answered your question, please help others by accepting it as a solution.

Hi @Anonymous 

 

Had a bit of time to think about it...

The confusion comes from the fact that you have a row context and a filter context active at the same time.

 

Since you weren't explicitly overriding the filter context on the new 'ConcatColumn', the filter from the row context was still being applied.

 

For example, on row 1 of your table, the value in the ConcatColumn is "1FALSE".

Essentially, your CALCULATETABLE was asking for a list of unique IDs where Table[Value] = TRUE and Table[ConcatColumn] = "1FALSE".

Obviously, this would return an empty table and your IF statement would return FALSE.

 

Taking your original query, you could modify it to remove all filters as follows:

isTrueID = 
VAR arr = 
CALCULATETABLE(
    VALUES( 'Test'[ID] ), 
    FILTER( 
        ALL( Test ), 
        'Test'[Value] = TRUE() 
    )
)
RETURN 
IF( 'Test'[ID] in arr, TRUE(), FALSE() )

 

Hope this explains things.

 

Best regards,
Martyn


If I answered your question, please help others by accepting it as a solution.

Anonymous
Not applicable

Thank you, your solutions works! Still weird why my solutions breaks on other custom columns ...

Anonymous
Not applicable

& when adding the column 'ConcatColumn' to the filter in CALCULATETABLE, i get the back to the result I want to achieve.
Why is this working? And should I add every calculated column I add to the table in the filter for my calculated table? 

 

isTrueID = 
var arr = CALCULATETABLE(VALUES('Test'[ID]); 'Test'[Value] = TRUE(); Test[ConcatColumn] <> "")
RETURN 
if('Test'[ID] in arr; TRUE(); FALSE())

 

 

IDValueIsTrueIDConcatColumn
1FalseTrue1FALSE
1TrueTrue1TRUE
1FalseTrue1FALSE
1FalseTrue1FALSE
2FalseTrue2FALSE
2TrueTrue2TRUE
3FalseFalse3FALSE
3FalseFalse3FALSE
3FalseFalse3FALSE

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.