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
TwiggyHaz
Frequent Visitor

Measure for Average of Sum of Collections per month

Hello,

 

Looking to recreate the below SQL into a DAX equivalent, currently using DirectQuery for the Dashboard being created.

 

SELECT		AccountID,
		AVG(Q1.Total) AS Average

FROM 
		(
			SELECT		AccountID,
					FORMAT(EntryDate,'yyyyMM') AS Period,
					SUM(Amount) AS Total

			FROM		Collections

			GROUP BY	AccountID,
					FORMAT(EntryDate,'yyyyMM')
		) Q1

GROUP BY	AccountID

 

 

 

I currently have the following in DAX, but the output is incorrect. Any ideas where I am going wrong?

 

Test = 
CALCULATE (
    AVERAGEX (
        SUMMARIZE (
            Collections,
            'Base Data'[AccountID],
            Dates[Period],
            "Collections", Sum ( Collections[Amount] )
        ),
        [Collections]
    ),
    USERELATIONSHIP ( Collections[EntryDate], Dates[DateID] ),
    Collections[PreStrat] = "Yes"
)

 

 

1 REPLY 1
v-jayw-msft
Community Support
Community Support

Hi @ TwiggyHaz,

 

Please check following steps as below and see if the result achieve your expectation.

1. Create calculated table:

    Date = DISTINCT(Collections[EntryDate])

2. Create calculated column:

    YearMonth = FORMAT('Date'[EntryDate],"YYYYMM")

3. Create measure:

    Measure =

    VAR countYM =

        CALCULATE (

            DISTINCTCOUNT ( 'Date'[YearMonth] ),

           FILTER ( Collections, Collections[AccountID] = MAX ( Collections[AccountID] ) )

        )

    RETURN

        SUM ( Collections[Amount] ) / countYM

Result would be shown as below, hopefully works for you:

1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

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.