Forum Discussion

littlepatos's avatar
littlepatos
Icon for Helper II rankHelper II
3 years ago
Solved

Calculate Highest Count Based on Category

I have data detailing complaints per department and per category and I would like to add a Card showing Year Month with highest number of complaints.  Eg: If Transport Services had highest number of all time with 30 complaints in July 2021.

Step 1) I added a column to show Year Month

Step 2) I have created a Measure to Count all the Complaints

D = COUNT(Complaints[Directorate]
Step 3) I created a Measure to show highest number of Complaints but not sure how to tell it that I want it to add up the complaints per department.
Highest Complaints Month Year = FIRSTNONBLANK(TOPN(1,VALUES('Complaints'[Year Month]),[d]),1)
 

 

Record Type    Record Number     Department                                      Directorate                                                    Date

ComplaintCOM/22/17CompliancePlanning & Environment18/12/2022
ComplaintCOM/22/16Transport ServicesInfrastructure15/11/2022
ComplaintCOM/22/15Water ServicesInfrastructure26/10/2022
ComplaintCOM/22/14Transport ServicesInfrastructure19/10/2022
ComplaintCOM/22/13CompliancePlanning & Environment11/10/2022
ComplaintCOM/22/12Transport ServicesInfrastructure10/10/2022
ComplaintCOM/22/11Governance & RiskCorporate Services26/09/2022
ComplaintCOM/22/10Parks & Open SpacesPlanning & Environment7/09/2022
ComplaintCOM/22/9CompliancePlanning & Environment1/08/2022
ComplaintCOM/22/8Transport ServicesInfrastructure11/07/2022
ComplaintCOM/22/6CompliancePlanning & Environment29/06/2022
ComplaintCOM/22/5Building ServicesPlanning & Environment16/06/2022
ComplaintCOM/22/4Transport ServicesInfrastructure9/06/2022
ComplaintCOM/22/2Water ServicesInfrastructure18/05/2022
ComplaintCOM/22/1Parks & Open SpacesPlanning & Environment16/02/2022
ComplaintCOM/21/16CompliancePlanning & Environment20/12/2021
ComplaintCOM/21/15Customer ServiceCommunity & Economic Development15/12/2021
ComplaintCOM/21/14Customer ServiceCommunity & Economic Development14/12/2021
ComplaintCOM/21/13Waste & EnvironmentPlanning & Environment25/11/2021
ComplaintCOM/21/12Planning & Environment DirectoratePlanning & Environment23/11/2021
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi littlepatos ,

     

    Please try this:

    Measure = 
    VAR __counts = MAXX(SUMMARIZE('Calendar','Calendar'[Year-Month],'Complaints'[Department]),CALCULATE(COUNTROWS('Complaints')))
    VAR __month = MAXX(FILTER(SUMMARIZE('Calendar','Calendar'[Year-Month],'Complaints'[Department],"count",[D]),[count]=__counts),'Calendar'[Year-Month])
    VAR __department = MAXX(FILTER(SUMMARIZE('Calendar','Calendar'[Year-Month],'Complaints'[Department],"count",[D]),[count]=__counts),'Complaints'[Department])
    RETURN
    __department & " had highest number of all time with " & __counts & " complaints in " & __month

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi littlepatos ,

     

    Please try this:

    Measure = 
    VAR __counts = MAXX(SUMMARIZE('Calendar','Calendar'[Year-Month],'Complaints'[Department]),CALCULATE(COUNTROWS('Complaints')))
    VAR __month = MAXX(FILTER(SUMMARIZE('Calendar','Calendar'[Year-Month],'Complaints'[Department],"count",[D]),[count]=__counts),'Calendar'[Year-Month])
    VAR __department = MAXX(FILTER(SUMMARIZE('Calendar','Calendar'[Year-Month],'Complaints'[Department],"count",[D]),[count]=__counts),'Complaints'[Department])
    RETURN
    __department & " had highest number of all time with " & __counts & " complaints in " & __month

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum