0
votes

New to DAX. I need a bit of help when moving excel formulas to DAX. I have this table and call it table1:

Date        ID  Time
10/06/2020  1   1
10/06/2020  1   2
11/06/2020  1   3
12/06/2020  2   5
13/06/2020  1   6

And I need to calculate count and average per day per ID. The results with two simple formulas (=COUNTIFS(B:B,B2,A:A,A2)) and (=AVERAGEIFS(C:C,B:B,B2,A:A,A2)) in excel is:

Date        ID  Time    Count ifs   Avergae ifs
10/06/2020  1   1       2           1.5
10/06/2020  1   2       2           1.5
11/06/2020  1   3       1           3
12/06/2020  2   5       1           5
13/06/2020  1   6       1           6

How can I replicate in DAX?

Update

Count in DAX

DAX Count = 
COUNTROWS (
    FILTER (
        'Table1',
        'Table1'[ID] = EARLIER ( 'Table1'[ID] )
            &&  'Table1'[Date] = EARLIER ( 'Table1'[Date] )
    )
)

Sum per day per ID

Sum = 
CALCULATE(
    SUM(Table1[Time]),
    FILTER(
        All(Table1),
        Table1[ID] = EARLIER(Table1[ID]) &&
        Table1[Date] = EARLIER(Table1[Date])
    )
)

Item closed :)

1
Are you trying to write a measure or a calculated column?Alexis Olson
Actually, both and I would need the dynamic changes when displaying the results.Kalenji
I have count done. DAX Count = COUNTROWS ( FILTER ( 'Table1', 'Table1'[ID] = EARLIER ( 'Table1'[ID] ) && 'Table1'[Date] = EARLIER ( 'Table1'[Date] ) ) ) but need a bit more help with the average.Kalenji

1 Answers

0
votes

I have answered the question. @Alexis Olson thank you for the inspiration.

Count in DAX

DAX Count = 
COUNTROWS (
    FILTER (
        'Table1',
        'Table1'[ID] = EARLIER ( 'Table1'[ID] )
            &&  'Table1'[Date] = EARLIER ( 'Table1'[Date] )
    )
)

Sum per day per ID

Sum = 
CALCULATE(
    SUM(Table1[Time]),
    FILTER(
        All(Table1),
        Table1[ID] = EARLIER(Table1[ID]) &&
        Table1[Date] = EARLIER(Table1[Date])
    )
)