Umut K
Umut K

Reputation: 1388

list of the max and min of the sums

I want to list only the max and the min of the sums grouped by date where count of the Name is above 2. Below formula works fine to find the max

Maks = 
maxx(
SUMMARIZE('Table',
     'Table'[DateStamp],
     "Total",
     CALCULATE(sum('Table'[Value]),
        filter('Table', count('Table'[Name])>2))
        ),[Total]

)

sample data

DateStamp   Name    Value
7.7.2022    A       55
7.7.2022    B       88
7.7.2022    C       77
8.7.2022    A      125
8.7.2022    B       25
8.7.2022    C       54
9.7.2022    A       61
9.7.2022    C       88
10.7.2022   A       92
10.7.2022   B      113
10.7.2022   C      145
11.7.2022   A      155
11.7.2022   C      255
12.7.2022   A      107
12.7.2022   B      121
12.7.2022   C      167

Desired Output is

12.07.2022  395
8.07.2022   204

Upvotes: 0

Views: 89

Answers (2)

Ozan Sen
Ozan Sen

Reputation: 2615

This is another solution. I am using DAX.do software to write my dax codes which I think is more efficient. so If you decide to copy and use codes, please do not forget to remove evaluate and give a name to your table, column or whatever....

let's go step by step: 1st Step - Create our table

DEFINE
    TABLE Records =
        SELECTCOLUMNS (
            {
                ( dt"2022-07-07", "A", 55 ),
                ( dt"2022-07-07", "A", 55 ),
                ( dt"2022-07-07", "B", 88 ),
                ( dt"2022-07-07", "C", 77 ),
                ( dt"2022-07-08", "A", 125 ),
                ( dt"2022-07-08", "B", 25 ),
                ( dt"2022-07-08", "C", 54 ),
                ( dt"2022-07-09", "A", 61 ),
                ( dt"2022-07-09", "C", 88 ),
                ( dt"2022-07-10", "A", 92 ),
                ( dt"2022-07-10", "B", 113 ),
                ( dt"2022-07-10", "C", 145 ),
                ( dt"2022-07-11", "A", 155 ),
                ( dt"2022-07-11", "C", 255 ),
                ( dt"2022-07-12", "A", 107 ),
                ( dt"2022-07-12", "B", 121 ),
                ( dt"2022-07-12", "C", 167 )
            },
            "DateStamp", [Value1],
            "Name", [Value2],
            "Value", [Value3]
        )
EVALUATE
Records

enter image description here

DEFINE 
   MEASURE Records[TotalCount] = COUNT ( Records[Name] )
EVALUATE
ROW("TotalCount",[TotalCount])

SSS

EVALUATE

    VAR Maks = MAXX(ADDCOLUMNS (
        SUMMARIZE ( Records, Records[DateStamp]),
             "Total", CALCULATE ( SUM ( Records[Value] ) )
             ),IF([TotalCount]>2,[Total]))
    VAR MinK = MINX (ADDCOLUMNS (
        SUMMARIZE ( Records, Records[DateStamp]),
             "Total", CALCULATE ( SUM ( Records[Value] ) )
             ),IF([TotalCount]>2,[Total]))
    VAR Maks_Date = MAXX(FILTER (ADDCOLUMNS (
        SUMMARIZE ( Records, Records[DateStamp]),
             "Total", CALCULATE ( SUM ( Records[Value] ) )
             ),[Total] = Maks),[DateStamp])
    VAR Min_Date = MINX(FILTER (ADDCOLUMNS (
        SUMMARIZE ( Records, Records[DateStamp]),
             "Total", CALCULATE ( SUM ( Records[Value] ) )
             ),[Total] = MinK),[DateStamp])
    RETURN
    SELECTCOLUMNS (
    {(Maks_Date,Maks),
    (Min_Date,MinK)},
    "MaxDate-MinDate",[Value1],
    "MaxValue-MinValue",[Value2]
    )

KXXXXX

Upvotes: 1

Mik
Mik

Reputation: 2103

tablo = 

VAR tbl = 
    FILTER(
        SUMMARIZE(ALL('Table'),'Table'[DateStamp])
        ,CALCULATE(
            DISTINCTCOUNT('Table'[Name])
            ,ALLEXCEPT('Table','Table'[DateStamp])
        )>2
    )

VAR tblFiltered =
    FILTER(
        ADDCOLUMNS(
            tbl
            ,"SUM",CALCULATE(SUM('Table'[Value]))
        )
        ,OR(
            [SUM]=MAXX(tbl,CALCULATE(SUM('Table'[Value])))
            ,[SUM]=MINX(tbl,CALCULATE(SUM('Table'[Value])))
        )
    )
RETURN
    SUMX(FILTER(tblFiltered,[DateStamp]=SELECTEDVALUE('Table'[DateStamp])),[SUM])

enter image description here

Upvotes: 2

Related Questions