Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi,
I am trying to create a count of the rows returned in a set of table visualizations that all from the same base fact table using different measures that contain filters as well.
I have two table visualizations on a single page that return counts of survey responses for specific questions. I am trying to count the number of rows in the each table viz where the Diff measure is above, equal to, and below zero. I also have a slicer that filters the two comparable measures. I have been researching countrows with filters, but I am not able to figure how to have the countrows apply to each individual table visualization. Any help would be greatly apprieciated.
I am trying to create the two count tables highlighted in the red boxes below.
Solved! Go to Solution.
Yes. You're on the right track. Make sure your 0's are actual 0's and not "null".
Also, I think you may have the formula flipped. See example 2 in the link: https://docs.microsoft.com/en-us/dax/countx-function-dax
The following formula illustrates how to pass a filtered table to COUNTX for the first argument. The formula uses a filter expression to get only the rows in the Product table that meet the condition, ProductSubCategory = "Caps", and then counts the rows in the resulting table that have a list price. The FILTER expression applies to the table Products but uses a value that you look up in the related table, ProductSubCategory.
=COUNTX(FILTER(Product,RELATED(ProductSubcategory[EnglishProductSubcategoryName])="Caps", Product[ListPrice])
Hey @mcomsto
I see the problem now. Because of the way your data is set up you cannot use any of the COUNT functions. you will need to unpivot your data to have a row for the row in your table and then turn your measures into calculated columns.
Essentially your measures are calculating the different between two rows out of a column. Not two columns in a row. Because of this the FILTER function is keeping the rows that contain a component for the measure that is a possible answer to the COUNT function.
So you are essentially trying to combine the two red highlighted tables in the shared image?
Thank you for the reply.
I'm trying to create the two highlighted tables, sorry that wasn't clear.
Ah. That's easy enough. You can use the Countx as a countif function and/or use the FILTER functions.
COUNTX: https://docs.microsoft.com/en-us/dax/countx-function-dax
FILTER: https://docs.microsoft.com/en-us/dax/filter-function-dax
Also might want to check out the COUNTAX function: https://docs.microsoft.com/en-us/dax/countax-function-dax
So I would do something like this for counting the above zero rows?
Yes. You're on the right track. Make sure your 0's are actual 0's and not "null".
Also, I think you may have the formula flipped. See example 2 in the link: https://docs.microsoft.com/en-us/dax/countx-function-dax
The following formula illustrates how to pass a filtered table to COUNTX for the first argument. The formula uses a filter expression to get only the rows in the Product table that meet the condition, ProductSubCategory = "Caps", and then counts the rows in the resulting table that have a list price. The FILTER expression applies to the table Products but uses a value that you look up in the related table, ProductSubCategory.
=COUNTX(FILTER(Product,RELATED(ProductSubcategory[EnglishProductSubcategoryName])="Caps", Product[ListPrice])
@Tad17 , I thought the solution you proposed would work, but it did not. I think I needed to provide more details of my situation. I have create a new screenshot with the full scenario. If you don't mind, would you take a look and let me if you have any ideas on how to solve my problem. Thank you.
Can you sharea screen shot of your data in Power BI and the result you are currently getting?
I had a mistake in the Above Zero formula, corrected below:
Above Zero = COUNTX(FILTER('Form Response Fact',('Form Response Fact'[Comp 1 Q1 Form Score] - 'Form Response Fact'[Comp 2 Q1 Form Score]) > 0 ),'Form Response Fact'[AllData.Q1 Score]).
I can't really show a screenshot due to the sensitivity of the data, but I have created a measure called "Above Zero" the formula is:
Hey @mcomsto
Without being able to see the data or knowing the format I'm not sure how much I can help, but I believe your logic statement may be the problem. I believe it should be >= "0"
The quotation marks may be all that is necessary, but given that the measure is called "above zero" I figured the inequality needs to be "greater than" (>) or "greater than or equal to" (>=). Depending on the formatting of your data the quotations marks may be necessary to count text values.
I have attached a mocked up pbix, and I am getting the wrong count values in the Above and Equal Zero measures. See attached pbix file. Thank you.
https://www.dropbox.com/s/gbfb8nmwyp2bkrp/mockupforcountxissue.pbix?dl=0
Hey @mcomsto
I see the problem now. Because of the way your data is set up you cannot use any of the COUNT functions. you will need to unpivot your data to have a row for the row in your table and then turn your measures into calculated columns.
Essentially your measures are calculating the different between two rows out of a column. Not two columns in a row. Because of this the FILTER function is keeping the rows that contain a component for the measure that is a possible answer to the COUNT function.
@Tad17 , thank you. You are correct and that makes a lot of sense. Luckily have the data in two tables, one is pivoted to summarize the scores (column-wise) and the other is unpovited (row-wise). I will use the row-wise table for these calculations.
Awesome. Sorry it took me so long to figure that out. I should have picked up on the fact that the data wasn't pivoted correctly for my calculations. I'm sorry my presumptions and oversight cost you time.
Ok. Thank you for the reply. I will create a mocked up data set and pbix file.
User | Count |
---|---|
85 | |
80 | |
77 | |
49 | |
41 |
User | Count |
---|---|
114 | |
56 | |
51 | |
42 | |
42 |