Forum Discussion
Best Practice: Binary True/False vs Integer 1/0 ?
I want to use a flag field for if records have a given status, or are marked for deletion, etc...
I was using an Integer with a 0 for FALSE and 1 for TRUE.
Then I did a nice SUM on the field to get what I was after.
However, if I add a slicer, showing 0 and 1 is NOT user friendly.
Is there any downside to changing it to a True/False field?
I'd use COUNT instead of SUM to count the TRUE values, but other than that. Is there any downside?
sasdfasdfsad Readability: True/False fields are more intuitive and user-friendly, especially when used in slicers or filters. Users can easily understand the meaning of True/False compared to 0/1.
Data Modeling: True/False fields are explicitly designed for boolean logic, which can make your data model more semantically correct and easier to understand.
DAX Functions: Power BI's DAX language has built-in support for boolean fields, which can simplify your calculations and improve readability.CountOfTrueValues = COUNTROWS(FILTER(Table, Table[FlagField] = TRUE()))
sasdfasdfsad I don't see any different storing 0/1 or True/False, only thing come in mind is that you cannot use True/False value in the filter page (like visual/page/report level filters) other than that I don't see any difference.
Other difference you already point out that you will use count with condition, if you want count of true or false values, although sum is always returning sum of true values.
4 Replies
- bhanu_gautamSuper User
sasdfasdfsad Readability: True/False fields are more intuitive and user-friendly, especially when used in slicers or filters. Users can easily understand the meaning of True/False compared to 0/1.
Data Modeling: True/False fields are explicitly designed for boolean logic, which can make your data model more semantically correct and easier to understand.
DAX Functions: Power BI's DAX language has built-in support for boolean fields, which can simplify your calculations and improve readability.CountOfTrueValues = COUNTROWS(FILTER(Table, Table[FlagField] = TRUE()))
- parry2kSuper User
sasdfasdfsad I don't see any different storing 0/1 or True/False, only thing come in mind is that you cannot use True/False value in the filter page (like visual/page/report level filters) other than that I don't see any difference.
Other difference you already point out that you will use count with condition, if you want count of true or false values, although sum is always returning sum of true values.
- sasdfasdfsadAdvocate IV
Good point about SUM still working even, I didn't process that at all. Thank you!!
- parry2kSuper User
sasdfasdfsad also the DAX can be written like this;
CountOfTrueValues = COUNTROWS(FILTER(Table, Table[FlagField]))