Forum Discussion
Creating a Table in an IF statement
I want to create a table
I am trying to display a table of the tags selected in another table, but if none are selected I want to show an empty table, whereas the default behaviour is to display all of them.
Why doesn't this Table formula work?
6 Replies
- Greg_DecklerCommunity Champion
KervBruce Couple things. First, I believe you need this:
VAR N = COUNTROWS('Tags')
Unless [Tags Selected] is a measure that returns the number of tags selected.
Also, mixing measures with calculated tables and columns doesn't generally work as calculated tables and measures are not dynamic.
Finally, yes, DAX doesn't like it when you try to return different tables such as your IF statement. You could just return BLANK() instead of BlankTable and that will likely fix that issue.
But, overall, you will likely need to rethink your approach to this. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.- KervBruceAdvocate I
Thanks Greg_Deckler
Here is my model:Yes I do have a measure called [Tags Selected] as follows:
Tags Selected = VAR TagsSelected = COUNTROWS(Tags)RETURN IF(TagsSelected = [AllTags], 0, TagsSelected)What I am trying to achieve is to filter a table of WorkItems based to tags slected, but I want to do this with AND rather than OR, so I have created the following measure to filter the table:Selected Tags with AND-Only Condition =var TheselectedTags=VALUES('Tag Assignments'[TagName])var countRowsAss=COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('Tag Assignments',RELATED(Tags[TagName]) in TheselectedTags),"Tag",RELATED(Tags[TagName]))))var countRowsTags=COUNTROWS(Tags)returnIF([Tags Selected] = 0,0,IF(countRowsAss>=countRowsTags,countRowsAss))What I now want to display is the list of tags that are selected, but display none if none are slelected.I did also try returning Blank() but that wasn't recognised as a table, hence constructing an empty table.- Greg_DecklerCommunity Champion
KervBruce Well, I created an AND slicer once. You might be able to use it along with a Complex Selector. Really difficult without sample data to test with.