cancel
Showing results for
Did you mean:
Highlighted
Helper IV

## 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!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support

## Re: Help with DAX formula (Edited)

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.

Highlighted
Community Support

## Re: Help with DAX formula (Edited)

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.

Announcements

#### Microsoft Ignite

This will be a conference that you do not want to miss!

#### Get Ready for Power BI Dev Camp

Don't miss the Power BI Dev Camp this week!

#### August Community Highlights

Check out a full recap of the month!

#### August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

#### Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors