Forum Discussion
Largest value in a category
Hi
I am strugling with a problem and hope you can help.
I need a DAX measure/filter to find the latest quarter for a given category and subcategory. However, my quarter data is text, not a date field.
As an example, for Project 1, Main it it would would report PQ7 and for Project 1 Support it would report PQ5. For Project 2 Main it would report PQ12 and for Project 2 Support it would report PQ7
| Category | Subcategory | Quarter | LatestQ |
| Project 1 | Main | PQ1 | No |
| Project 1 | Support | PQ2 | No |
| Project 1 | Support | PQ5 | No |
| Project 1 | Main | PQ4 | No |
| Project 1 | Main | PQ7 | Yes |
| Project 2 | Support | PQ4 | No |
| Project 2 | Support | PQ6 | No |
| Project 2 | Support | PQ7 | No |
| Project 2 | Main | PQ12 | Yes |
| Project 2 | Main | PQ9 | No |
I've tried some of the other solutions, including https://community.powerbi.com/t5/DAX-Commands-and-Tips/DAX-Largest-value-from-column/m-p/1641867 , but I'm stuck with needing to filter on category and subcategory
Would appreciate any advice!
Hi Anonymous
First add a calculated column into the table.
Quarter No. = VALUE(RIGHT([Quarter], LEN([Quarter])-2))Then create a measure to get the latest quarter value.
Latest Quarter = "PQ" & CALCULATE(MAX('Table'[Quarter No.]),ALLEXCEPT('Table','Table'[Category],'Table'[Subcategory]))or
Latest Quarter 2 = VAR latestQtr = CALCULATE(MAX('Table'[Quarter No.]),ALLEXCEPT('Table','Table'[Category],'Table'[Subcategory])) RETURN CALCULATE(MAX('Table'[Quarter]),ALLEXCEPT('Table','Table'[Category],'Table'[Subcategory]),'Table'[Quarter No.]=latestQtr)Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.
2 Replies
- v-jingzhang
Community Support
Hi Anonymous
First add a calculated column into the table.
Quarter No. = VALUE(RIGHT([Quarter], LEN([Quarter])-2))Then create a measure to get the latest quarter value.
Latest Quarter = "PQ" & CALCULATE(MAX('Table'[Quarter No.]),ALLEXCEPT('Table','Table'[Category],'Table'[Subcategory]))or
Latest Quarter 2 = VAR latestQtr = CALCULATE(MAX('Table'[Quarter No.]),ALLEXCEPT('Table','Table'[Category],'Table'[Subcategory])) RETURN CALCULATE(MAX('Table'[Quarter]),ALLEXCEPT('Table','Table'[Category],'Table'[Subcategory]),'Table'[Quarter No.]=latestQtr)Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it. - amitchandak
Super User
Anonymous , You need to create a number from that
a new column
Quarter no = right([Quarter], len([Quarter]) -2)
Then have column like
if([Quarter no] = maxx(filter(Table, [category] = earlier([category])),[Quarter no]), "Yes", "No")