Calculate Average Number of Days Between Multiple Dates with dax in power bi

佐手、 提交于 2021-01-28 05:10:33

问题


Let's say I have the following data frame. I want to calculate the average number of days between all the activities for a particular account using Dax in power bi

Let say I have this:

I want a desired result like this

How do I achieve this using DAX in power BI


回答1:


Assuming you have the data in a table as in your picture, create a calculated column like this:

AvgerageDaysInbetween = 
var thisCustomer = [Customer]
var temp = 
SUMX(
    FILTER(
        SUMMARIZE(
            'Table';
            [Customer];
            "avg";  
                DIVIDE(
                    DATEDIFF(MIN('Table'[DateOfOrder]); MAX('Table'[DateOfOrder]); DAY);
                    DISTINCTCOUNT('Table'[DateOfOrder])-1;
                    0
            )
        );
        [Customer] = thisCustomer
    );
    [avg]
)
return
temp

Resulting table:

enter image description here



来源:https://stackoverflow.com/questions/55410412/calculate-average-number-of-days-between-multiple-dates-with-dax-in-power-bi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!