Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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.model.png

 

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...):

 

 
 

run info.pngruntime info.png

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

 

.result.png

 

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
v-yuta-msft
Community Support
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.

View solution in original post

1 REPLY 1
v-yuta-msft
Community Support
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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.