Forum Discussion
Filter by column in underlying data
I have a table called Apps with 3 columns:
ID (Prmary Key)
Year
Type
I would like to create a column chart that groups by year, displays a count, and has filters for Type and Year. The SQL query would look something like this:
SELECT Year, COUNT(*)
FROM Apps
WHERE Year IN ([Year filter selected values])
AND Type IN (Type filter selected values])
GROUP BY Year
The Year filter is a simple drag and drop, but how would the Type filter be implemented? Type can't be in the final data set because it would throw off the count. But if Type is not in the final data set, then how can a page filter be created for it?
Thanks,
Tim
td48260 not sure what you mean using type on the slicer will throw the count off
just use type and year as a slicer and a simple measure
Count = COUNTROWS ( Table )or maybe I didn't understand your question, explain it with sample data if that is the case.
✨ Follow us on LinkedIn and to our YouTube channel
Check my latest video on Filters and Sparklines https://youtu.be/wmwcX8HvNxc
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.
5 Replies
- parry2kSuper User
td48260 not sure what you mean using type on the slicer will throw the count off
just use type and year as a slicer and a simple measure
Count = COUNTROWS ( Table )or maybe I didn't understand your question, explain it with sample data if that is the case.
✨ Follow us on LinkedIn and to our YouTube channel
Check my latest video on Filters and Sparklines https://youtu.be/wmwcX8HvNxc
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.
- mh2587Super User
= calculate(count([value]),table[year]== selectedvalue(table[year]) && table[Type] == selectedvalue(table[type]))
- td48260Regular Visitor
Sorry, I didn't explain it well.
ID Year Type 1 2014 A 2 2015 B 3 2015 C 4 2016 A 5 2016 B 6 2016 C I want a column chart where the Axis column is Year and the Values column is a count of the rows. There should be filters or slicers for Year and Type. In the example above, if all Years and all Types were selected the chart should reflect this data:
Year Value (count)
2014 1
2015 2
2016 3
If only A is checked in the filter/slicer, then this should be the data:
Year Value (count)
2014 1
2016 1
The order of operations should be
1. Filter table rows by Year and Type filter/slicer values
2. Group the results by Year
3. Calculate Count for each Year
I tried creating measures for
COUNTROWS(Table)
and
calculate(count([value]),table[year]== selectedvalue(table[year]) && table[Type] == selectedvalue(table[type])
In both cases I got syntax errors which I've been unable to resolve.
Thanks for your help.
- td48260Regular Visitor
Yes, I was overcomplicating it! Once I removed the GROUP BY operation and added a Measure COUNTROWS(Table), it works.
Thanks for your patience and help!
Tim