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
MaximilianR
Helper I
Helper I

Average or Sum over already aggregated measure

Hi all,

 

I am quite new to Power BI and I know that similar questions have been posted before and I read many answers but I am still not unterstanding how to achieve what I want.

 

Situation: I have successfully created measures for sales and sold quantity on a daily basis. I have also aggregated these values for for all items sold by one customer. The table is showing the article number (in fact unique numbers, just shortened for data protection) as well as values for the days the article was in stock (DayInSt) and for the full time period (all). In this case, a data slicer has been set between 01.07.2020 and 31.08.2020
Snip Item Performance table.JPG

(Article numbers on the left are unique, I just cut them to hide the full number)

 

This analysis works well for just one customer at a time but now I want to average and/or sum values for many customers. I know this might be slow for so many data points (220 customers * 250 Articles total * 365 days).

Here is the code I have used so far:

 

Sales Per Day (with blanks) = 
VAR CurrentDate = SELECTEDVALUE('DateTable'[Date])         

VAR NextSalesDate =
    CALCULATE(
        MIN('Sales Invoice Line'[Shipment Date]),           
        DATESBETWEEN(
            DateTable[Date],
            CurrentDate+1,
            CurrentDate+2000
        )
    )   

VAR PrevSalesDate =
    CALCULATE(
        MAX('Sales Invoice Line'[Shipment Date]),           
        DATESBETWEEN(
            DateTable[Date],
            CurrentDate-2000,
            CurrentDate
        )
    )               

VAR PrevAmount =
CALCULATE(    
    SUMX(
        FILTER('Sales Invoice Line',
            'Sales Invoice Line'[Shipment Date] = PrevSalesDate
        ),
        'Sales Invoice Line'[Amount]
    ),
    DATESBETWEEN(
        DateTable[Date],
        PrevSalesDate,
        CurrentDate
    )
)

VAR DaysSinceLastOrderTmp = DATEDIFF(PrevSalesDate, CurrentDate, DAY)
VAR DaysSinceLastOrder =
    IF(
        ISBLANK(DaysSinceLastOrderTmp),
        9999,
        DaysSinceLastOrderTmp
    )

VAR DaysBetweenOrders = DATEDIFF(PrevSalesDate, NextSalesDate, DAY)
VAR SalesDays =
    IF(
        DaysSinceLastOrder > 30, 
        BLANK(),
        IF(
            ISBLANK(DaysBetweenOrders),
            31,
            MIN(DaysBetweenOrders, 31)
        )
    )

VAR SalesPerDay =
    DIVIDE(
        PrevAmount,
        SalesDays,
        BLANK()
    )

RETURN SalesPerDay

 


The final measure is created with:

 

Av. Sales per Day (all) = 
    AVERAGEX('DateTable',
        [Sales Per Day (zeros)]
    )

 

 

Question: How do I summarize/average this over all customers? Mind that it needs to calculate the "Av. Sales per Day (all)" for an article for every customer separately and then sum or average it, enter it into the row and then go to the next article number doing the same.

 

Thanks in advance for the help!

Maximilian

1 ACCEPTED SOLUTION
MaximilianR
Helper I
Helper I

Found a solution by myself:

 

Summed Av. Sales per Day per Item (all) = 
    SUMX(
        DISTINCT('Sales Invoice Line'[Cust. No]),
        [Av. Sales per Day (all)]
    )

 

It works, it is just very slow...

View solution in original post

2 REPLIES 2
MaximilianR
Helper I
Helper I

Found a solution by myself:

 

Summed Av. Sales per Day per Item (all) = 
    SUMX(
        DISTINCT('Sales Invoice Line'[Cust. No]),
        [Av. Sales per Day (all)]
    )

 

It works, it is just very slow...

MaximilianR
Helper I
Helper I

Maybe, as an additional thing to show what I want, see below image: These are the sales and sold quantity values for ONE article and many customers in the rows. The measure I need would do the following steps:

  1. Summarize or average these colums (The automatic summation at the bottom is obviously incorrect, when using excel to calculate I get a different result).
  2. Do this for each article (see original post)

 

Snip Cust Performance table.JPG

 

 

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.