Forum Discussion

PaulHallam's avatar
PaulHallam
Icon for Helper III rankHelper III
3 years ago
Solved

Adding a column to return if data is a maximum per category

Hi,

Looking for help.

 

I have a data table sample below. 

CityBuildingCategoryDateDayIDReturn 1 if it’s the Highest Category 2 Day
LondonACategory 105/09/2022MondayA 
LondonACategory 105/09/2022MondayB 
LondonACategory 205/09/2022MondayC 
LondonACategory 305/09/2022MondayD 
LondonACategory 106/09/2022TuesdayA1
LondonACategory 206/09/2022TuesdayB1
LondonACategory 306/09/2022TuesdayC1
LondonACategory 206/09/2022TuesdayD1
LondonACategory 207/09/2022WednesdayA 
LondonACategory 307/09/2022WednesdayB 
LondonACategory 107/09/2022WednesdayC 
LondonACategory 207/09/2022WednesdayD 
LondonACategory 108/09/2022ThursdayA1
LondonACategory 308/09/2022ThursdayB1
LondonACategory 208/09/2022ThursdayC1
LondonACategory 208/09/2022ThursdayD1
LondonACategory 309/09/2022FridayA1
LondonACategory 209/09/2022FridayB1
LondonACategory 309/09/2022FridayC1
LondonACategory 309/09/2022FridayD1
LondonACategory 212/09/2022MondayA1
LondonACategory 212/09/2022MondayB1
LondonACategory 112/09/2022MondayC1
LondonACategory 112/09/2022MondayD1
LondonACategory 113/09/2022TuesdayA 
LondonACategory 213/09/2022TuesdayB 
LondonACategory 113/09/2022TuesdayC 
LondonACategory 113/09/2022TuesdayD 
LondonACategory 214/09/2022WednesdayA1
LondonACategory 214/09/2022WednesdayB1
LondonACategory 214/09/2022WednesdayC1
LondonACategory 314/09/2022WednesdayD1
LondonACategory 115/09/2022ThursdayA 
LondonACategory 115/09/2022ThursdayB 
LondonACategory 315/09/2022ThursdayC 
LondonACategory 315/09/2022ThursdayD 
LondonACategory 316/09/2022FridayA 
LondonACategory 116/09/2022FridayB 
LondonACategory 116/09/2022FridayC 
LondonACategory 116/09/2022FridayD 

 

I am trying to add the last column 'Return 1 if it’s the Highest Category 2 Day', filled in as an example.
So

Look at all Mondays and see which Monday has the highest number of Category 2's. Then to return a 1 in the column in all of the columns for that date. etc etc for all days. So if i had a years worth of data only one Monday would have 1's one Tuesday etc and these would be the days with the maximum Category 2's

Hope that makes sense
P

  • PaulHallam,

     

    Try these calculated columns:

     

    Category 2 Row Count = 
    VAR vDay = Table1[Day]
    VAR vDate = Table1[Date]
    VAR vTable =
        FILTER (
            Table1,
            Table1[Day] = vDay
                && Table1[Date] = vDate
                && Table1[Category] = "Category 2"
        )
    VAR vResult =
        COUNTROWS ( vTable )
    RETURN
        vResult
    Is Highest Category 2 Day = 
    VAR vDay = Table1[Day]
    VAR vMaxRowCount =
        MAXX ( FILTER ( Table1, Table1[Day] = vDay ), Table1[Category 2 Row Count] )
    VAR vResult =
        IF ( Table1[Day] = vDay && Table1[Category 2 Row Count] = vMaxRowCount, 1 )
    RETURN
        vResult

     

     

2 Replies

  • PaulHallam,

     

    Try these calculated columns:

     

    Category 2 Row Count = 
    VAR vDay = Table1[Day]
    VAR vDate = Table1[Date]
    VAR vTable =
        FILTER (
            Table1,
            Table1[Day] = vDay
                && Table1[Date] = vDate
                && Table1[Category] = "Category 2"
        )
    VAR vResult =
        COUNTROWS ( vTable )
    RETURN
        vResult
    Is Highest Category 2 Day = 
    VAR vDay = Table1[Day]
    VAR vMaxRowCount =
        MAXX ( FILTER ( Table1, Table1[Day] = vDay ), Table1[Category 2 Row Count] )
    VAR vResult =
        IF ( Table1[Day] = vDay && Table1[Category 2 Row Count] = vMaxRowCount, 1 )
    RETURN
        vResult

     

     

    • PaulHallam's avatar
      PaulHallam
      Icon for Helper III rankHelper III

      Thanks for such a quick reply. I think i follow the logic......fantastic.!