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
jdballard30
Helper II
Helper II

Create a measure with a filter

I have the following data; it's a table that is denormalized and is the result of the join of App and Transaction.

 

AppID     TransactionID     DaysBetweenEvents

DEF       123               3

DEF       880               3

LMN       228               6

LMN       318               6

XYZ       414               9

 

The column "DaysBetweenEvents" will always be the same for any row that has the same AppID. What I'm trying to do is get the average days between events, but based on the DaysBetweenEvents for each application, without regard for the number of transactions. So, for the data above, the average would be (3  + 6 +  9) / 3, which is 6 (there are three unique applications, app DEF has 3 days between, LMN has 6 days between, and XYZ has 9.) The problem is that Power BI is calculating it as 5.4, because it's adding all the rows and dividing by 5.

 

How can I create a measure to calculate this? Do I need to change my model or is there DAX syntax I can use?

 

I've include a link to a .pbix file (Average.pbix) that has the above data (and a little more) so you can see what I'm trying to do. Perhaps that'll help. https://1drv.ms/f/s!AlWcOa_mDYfDq94uNPUcUD3JxLJ0VQ

 

 

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @jdballard30,

 

You also can use a measure instead. There could be two approaches.

Measure =
AVERAGEX (
    DISTINCT (
        SELECTCOLUMNS (
            ProgramTransactions,
            "Col1", [AppId],
            "Col2", [DaysBetweenEvents]
        )
    ),
    [Col2]
)
Measure 2 =
AVERAGEX (
    SUMMARIZE (
        'ProgramTransactions',
        'ProgramTransactions'[AppId],
        'ProgramTransactions'[DaysBetweenEvents]
    ),
    [DaysBetweenEvents]
)

Create-a-measure-with-a-filter

 

Best Regards,
Dale

Community Support Team _ Dale
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

5 REPLIES 5
v-jiascu-msft
Employee
Employee

Hi @jdballard30,

 

You also can use a measure instead. There could be two approaches.

Measure =
AVERAGEX (
    DISTINCT (
        SELECTCOLUMNS (
            ProgramTransactions,
            "Col1", [AppId],
            "Col2", [DaysBetweenEvents]
        )
    ),
    [Col2]
)
Measure 2 =
AVERAGEX (
    SUMMARIZE (
        'ProgramTransactions',
        'ProgramTransactions'[AppId],
        'ProgramTransactions'[DaysBetweenEvents]
    ),
    [DaysBetweenEvents]
)

Create-a-measure-with-a-filter

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
HotChilli
Super User
Super User

I think you need to get the distinct appid, daysbetweenevents rows of your table . Something like 

NewTable = DISTINCT(SELECTCOLUMNS(YourTable, "ID", YourTable[AppId], "Days",YourTable[AverageDays])) 

and then create a measure that takes the average of the Days column

NewMeasure = AVERAGE(NewTable[Days])

and stick that measure on a card

 

So I figured it out.

 

I used the "New Table" option on the Modeling menu to add the table. So that obviously creates a table, and I see how the distinct columns works. In my linked .pbix, I got the result I wanted.

 

I guess my question is: I could do this in my queries when everything is loaded. Is there a reason to do it in the front-end as opposed to the back-end or vice versa?

It's entirely up to you.   You can do the same algorithm in power query editor or advanced query editor using M.

If you have better skills in DAX, then use that.

I'm a bit confused, and it's me, not you. Smiley Happy

 

Would the new table be created using the query editor or DAX?

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.