Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Help with DAX formula (Edited)

Hi everyone!

I reuploaded this post because the previous one was marked as a spam for some reason (for which I hope I'm not doing something wrong).

 

I am new to DAX and I am struggling to create a formula for a report of mine. I have the model shown below.

 

Some more details. Each Query has 10 (or so) Event IDs where every Event ID has one Event Count and Event Time. Also each Query runs multiple times and have a unigue SessionUID. So Each many Sessions -> many occurences of each Query -> many occurences of each Event ID for each Query.

 

What I want to do is:
1) For each Event ID of each Query get the average Event time of one day.

2) Do the same thing but for the previous day (which I can get from 'Run Info'[Previous Date])

3) Calculate the difference Previous Date Average - Current Date Average

4) Somehow store those differences and count all the negative results 

5) Show that count on a visual that filters by the Current Date

 

Here are samples of inputs (sorry for the redacted information but you know...):

 

 
 

And this is some form of the result that I want. For each date on the left, get a count of all the negative (or positive) values that were calculated as described above

 

.

 

I hope I made sense in what I want to do. If you have any questions do not hesitate to ask. 

 

Thank you!

 

  • Anonymous ,

     

    Create a calculate column:

    Average Time =
    CALCULATE (
        AVERAGE ( Table[Event Time] ),
        ALLEXCEPT ( Table, Table[Query], Table[Event ID], Table[Date] )
    )
    

     

    To achieve the previous date, you need to create an index column in query editor:

    Previous Date =
    VAR Current_Index = Table[Index]
    VAR Previous_Index = Current_Index - 1
    RETURN
        CALCULATE (
            MAX ( Table[Date] ),
            FILTER ( Table, Table[Date] = Previous_Index )
        )
    

     

    Achieve the difference:

    Difference =
    VAR Previous_Date = Table[Previous Date]
    RETURN
        [Average Time]
            - CALCULATE (
                AVERAGE ( Table[Event Time] ),
                FILTER (
                    ALLEXCEPT ( Table, Table[Query], Table[Event ID] ),
                    Table[Date] = Previous_Date
                )
            )
    

     

    Finally count the negetive difference:

    Count Num =
    CALCULATE ( COUNTROWS ( Table ), FILTER ( Table, Table[Differnce] < 0 ) )
    

     

    Community Support Team _ Jimmy Tao

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • v-yuta-msft's avatar
    v-yuta-msft
    Community Support

    Anonymous ,

     

    Create a calculate column:

    Average Time =
    CALCULATE (
        AVERAGE ( Table[Event Time] ),
        ALLEXCEPT ( Table, Table[Query], Table[Event ID], Table[Date] )
    )
    

     

    To achieve the previous date, you need to create an index column in query editor:

    Previous Date =
    VAR Current_Index = Table[Index]
    VAR Previous_Index = Current_Index - 1
    RETURN
        CALCULATE (
            MAX ( Table[Date] ),
            FILTER ( Table, Table[Date] = Previous_Index )
        )
    

     

    Achieve the difference:

    Difference =
    VAR Previous_Date = Table[Previous Date]
    RETURN
        [Average Time]
            - CALCULATE (
                AVERAGE ( Table[Event Time] ),
                FILTER (
                    ALLEXCEPT ( Table, Table[Query], Table[Event ID] ),
                    Table[Date] = Previous_Date
                )
            )
    

     

    Finally count the negetive difference:

    Count Num =
    CALCULATE ( COUNTROWS ( Table ), FILTER ( Table, Table[Differnce] < 0 ) )
    

     

    Community Support Team _ Jimmy Tao

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.